2014-06-08 Created By BaoXinjian
一、总结
1. 上传资料
(1).通过调用function<FND_FNDFLUPL>,打开上传文件页面;
(2).从表fnd_lob_access和fnd_lobs中取出文件名放在form画面上;
2. 对dbms_lob中的二进制文件进行处理
(1).通过dbms_lob.converttoclob将二进制文件转换成字符文件;
(2).通过dbms_lob.instr和dbms_lob.substr在字符文件获取字符串记录;
3. 对获取资料放入到临时表,并显示在画面上
(1).通过instr和substr获字符串记录中的字段;
(2).并将字段赋值到集合或表中;
二、步骤
1. 上传资料
1 DECLARE
3 access_id NUMBER;
5 l_server_url VARCHAR2(100);
7 l_parameters VARCHAR2(100);
9 button_choice INTEGER;
11 l_file_id VARCHAR2(100);
13 l_gfm_id INTEGER;
15 BEGIN
17 access_id := fnd_gfm.authorize(NULL);
19 fnd_profile.get('APPS_WEB_AGENT', l_server_url);
21 l_parameters := 'access_id=' || access_id || ' l_server_url=' || l_server_url;
23 fnd_function.EXECUTE(function_name => 'FND_FNDFLUPL',
25 open_flag => 'Y',
27 session_flag => 'Y',
29 other_params => l_parameters);
31 -- Display a modal message for user to indicate file upload
33 -- is completed.
35 fnd_message.set_name('FND', 'ATCHMT-FILE-UPLOAD-COMPLETE');
37 button_choice := fnd_message.question(button1 => 'YES',
39 button2 => NULL,
41 button3 => 'NO',
43 default_btn => 1,
45 cancel_btn => 3,
46 icon => 'question');
48
49 IF (button_choice = 3) THEN
51 NULL;
53 ELSIF (button_choice = 1) THEN
55 l_file_id := '';
57 l_gfm_id := fnd_gfm.get_file_id(access_id);
59 :main.gfm_id := fnd_gfm.get_file_id(access_id);
61 IF l_gfm_id IS NOT NULL THEN
63 SELECT DECODE(INSTR(file_name, '/'),0,file_name,SUBSTR(file_name, INSTR(file_name, '/') + 1))
65 INTO l_file_id
67 FROM fnd_lobs
69 WHERE file_id = l_gfm_id;
71 IF l_file_id IS NOT NULL THEN
73 :main.filename := l_file_id;
75 SELECT cux_ce_stmt_s.NEXTVAL INTO :main.working_id FROM DUAL;
77 END IF;
79 END IF;
81 END IF;
83 END IF;
2. 对dbms_lob中的二进制文件进行处理
1 DECLARE
3 c_data CLOB;
5 l_data BLOB;
7 l_dest_offset INTEGER := 1;
9 l_scr_offset INTEGER := 1;
11 l_lang_context INTEGER := DBMS_LOB.default_lang_ctx;
13 l_warn INTEGER;
15 n_offset INTEGER;
17 n_clob_size INTEGER;
19 n_pos INTEGER;
21 v_buf VARCHAR2(4000);
23 BEGIN
25 DBMS_LOB.createtemporary(c_data, FALSE, DBMS_LOB.SESSION);
27 SELECT file_data INTO l_data FROM fnd_lobs WHERE file_id = 1501905;
29 DBMS_LOB.converttoclob(dest_lob => c_data,
31 src_blob => l_data,
33 amount => DBMS_LOB.lobmaxsize,
35 dest_offset => l_dest_offset,
37 src_offset => l_scr_offset,
39 blob_csid => NLS_CHARSET_ID('UTF8'),
41 lang_context => l_lang_context,
43 warning => l_warn);
45 n_offset := 1;
47 LOOP
49 n_pos := DBMS_LOB.INSTR(lob_loc => c_data,
51 pattern => CHR(10),
53 offset => n_offset,
55 nth => 1);
57 IF NVL(n_pos, 0) = 0 THEN
59 n_pos := n_clob_size + 1;
61 END IF;
63 v_buf := DBMS_LOB.SUBSTR(lob_loc => c_data,
65 amount => n_pos - n_offset,
67 offset => n_offset);
69 n_offset := n_pos + 1;
71 EXIT WHEN n_pos > n_clob_size;
73 END LOOP;
75 IF dbms_lob.istemporary(l_data) > 0 THEN
77 dbms_lob.freetemporary(l_data);
79 END IF;
81 IF dbms_lob.istemporary(c_data) > 0 THEN
83 dbms_lob.freetemporary(c_data);
85 END IF;
87 END IF;
3. 对获取资料放入到临时表,并显示在画面上
1 DECLARE
3 v_buf VARCHAR2(1000);
5 v_field VARCHAR2(1000);
7 n_delimiter_pos INTEGER;
9 BEGIN
11 v_buf := 'Return Authorization Reference,Adjustment Type,Vendor Number,Site Code- Pay To,Site Code- Ship To,Part Number,Quantity,Subinventory';
13 LOOP
15 v_field := NULL;
17 n_delimiter_pos := INSTR(v_buf, ',');
19 IF n_delimiter_pos > 0 THEN
21 v_field := LTRIM(RTRIM(SUBSTR(v_buf, 1, n_delimiter_pos - 1)));
23 v_buf := SUBSTR(v_buf, n_delimiter_pos + 1);
25 ELSIF LTRIM(RTRIM(v_buf)) IS NOT NULL THEN
27 v_field := LTRIM(RTRIM(v_buf));
29 v_buf := NULL;
31 END IF;
33 IF (v_buf IS NULL) THEN
35 EXIT;
37 END IF;
39 END LOOP;
41 END;
Thanks and Regards