procedure process_856_batch(errbuf out varchar2, retcode out varchar2, p_delivery_id in varchar2) is l_sub_retcode number; l_request_id number := fnd_global.conc_request_id;
cursor cur_asn(p_request_id in number) is --Step two select seh.delivery_id from som_edi_856_header seh where seh.send_asn_parent_request_id = p_request_id and seh.asn_status ='R';
l_req_id_fee number; l_req_option boolean;
begin
--Step one update som_edi_856_header seh set seh.asn_status ='R', seh.send_asn_parent_request_id = l_request_id where nvl(seh.asn_status, 'N') ='R' and get_order_type(seh.delivery_id) ='A01' and seh.send_asn_parent_request_id isnull and seh.delivery_id = nvl(p_delivery_id, seh.delivery_id);
begin --for update 当前 session 可以执行更新,其它 session 更新必须等到当前 session for update 的 commit 或者 rollback --在 PL/SQL 不能使用 select 1 from som_edi_asn_header for update; select 必须有 insert 语句; 否则会出现 Error: PLS-00428: an INTO clause is expected in this SELECT statement; --for update 查询也不能有聚合函数, select distinct 1 into l_fake_column from som_edi_asn_header for update; 会出现 Error: PL/SQL: ORA-01786: FOR UPDATE of this query expression is not allowed; --所以使用 execute 执行 SQL 语句。 execute immediate 'select 1 from som_edi_asn_header for update'; -- Lock
update som_edi_asn_header seh set seh.file_counter = (select nvl(max(sh.file_counter), 0) +1 from som_edi_asn_header sh where sh.transfer_flag ='Y' and sh.creation_date >= trunc(sysdate) and sh.creation_date < trunc(sysdate) +interval'1'day) where seh.header_id = p_header_id;
commit; --Release Lock end;
begin select 'ASN' ||'_'||count(*) ||'_'|| to_char(sh.creation_date, 'yyyymmdd') ||'_'|| sh.file_counter ||'.txt' into l_asn_filename from som_edi_asn_header sh, som_edi_asn_line sl where sh.header_id = sl.header_id and sh.header_id = p_header_id groupby sh.creation_date, sh.file_counter; exception when others then debug('get ans_filename error, header_id: '|| p_header_id); retcode :='2'; end;
execute immediate 'select 1 from som_edi_asn_header for update'; --Lock
--已经有相同时间产生的文件,将当前资料增加 1s,这样依据时间(yyyymmddhhmiss)命名文件不会重复。 update som_edi_asn_header sh set sh.creation_date = sh.creation_date +interval'1'second where sh.header_id = p_header_id and sh.creation_date in (select creation_date from som_edi_asn_header);
commit; --Release Lock
begin select 'ASN' ||'_'|| to_char(sh.creation_date, 'yyyymmddhhmiss') ||'.csv' into l_asn_filename from som_edi_asn_header sh where sh.header_id = p_header_id; exception when others then debug('get asn_filename error, header_id: '|| p_header_id); retcode :='2'; end;
for sectionFTP in sectionTarget.iter('FTP'): objFTP = FTP(sectionFTP.get("SITE")) objFTP.login(sectionFTP.get("ID"), sectionFTP.get("PASSWORD")) for sectionUpload in sectionFTP.iter('FILE'): objFTP.cwd(sectionUpload.get("UploadFolder"))
1 2 3 4 5 6
<TARGETID="ASN"Description="SN and RFID files"> <FTPSITE="site"ID="username"PASSWORD="password"> <FILETYPE="SN"TEMPLATE="VZ*.txt"SourceFolder="D:\HUB_EDI\TEST\FilePool\SN\"UploadFolder="TEST/Outbound/SN"BackupFolder="D:\HUB_EDI\TEST\FilePoolSN\bak\"MailAppender="MailASN" /> <FILETYPE="RFID"TEMPLATE="SERC*.csv"SourceFolder="D:\HUB_EDI\TEST\FilePool\RFID\"UploadFolder="TEST/Outbound/RFID"BackupFolder="D:\HUB_EDI\TEST\FilePoolRFID\bak\"MailAppender="MailASN" /> </FTP> </TARGET>