Oracle in batch processing to increase the value and uniqueness of the field

Copyright: Copyright Rights Reserved https://blog.csdn.net/weixin_39921821/article/details/90440936

1. Today data in the test environment platform suddenly gone, it turned out to be here last night I test program carried out at the time of the Qing library file storage, caused.

Therefore, taken from another table a few required data, other data fields can be written fixed, and then the data again made 100

So the question is, the primary key of the table especially what you should pay attention to, ah, or very pit, there are two data stored before, then in addition to too few mandatory, the other in accordance with the original

Like the file data replication;

Script Analysis:

insert into dfgz_pkgmx(in_time,recv_pkgno,code,contractorcorpcode,contractorcorpname,paybankname,paybanksubcode,paybanksubname,paybankcardnumber,payflag,workername,idcardtype,idcardnumber,payrollbankcardnumber,payrollbankname,payrolltopbankname,banklinknumber,payrolltopbankcode,totalpayamount,
balancedate,platflowno,sysno,payrollcode) 
select sysdate,'2','20190329-01','91640000227680637T','某某某','某某某','100164003','某某某','64222396985745921','2',spname,'3621',custid,btbankno,'某某某','某某某','5234523452345','105',1000.00,sysdate,
'P20190423145620190420190328-'||substr('0000000'||rownum, length('0000000'||rownum)-6,7),'0',
'P201904231456201904001' from gjjlmk_customersign t
where rownum<=100

2. The actual initial spell the unique values ​​for the field, I thought about using 'P20190423145620190420190328-' sysdate in a fight 'mmsss' (points milliseconds),

Or a fight that the TO_CHAR (systimestamp, 'ssff'), but later found that this relatively stupid, computer query execution speed of one second and tens of thousands is not a problem, so when his second query 100 is constant, it is not used sysdate and systimestamp of this,

There are thought of using guid () This, finally found does not work, or too fast query

Such as: test

select to_char(systimestamp,'ssff') from dual
select substr(sys_guid(),1,3) from dual

3. After testing found that can use rownum

Because only seven, so the interception

substr('0000000'||rownum, length('0000000'||rownum)-6,7)

7 and then the last character string preceding a fight this field can guarantee a unique way, O (∩_∩) O ~ ha

'P20190423145620190420190328-'||substr('0000000'||rownum, length('0000000'||rownum)-6,7)

 

Guess you like

Origin blog.csdn.net/weixin_39921821/article/details/90440936