Skip to Main Content

SQL & PL/SQL

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Procedure

580519Oct 22 2007 — edited Oct 22 2007
Hi all

Please look into the following procedure :

CREATE OR REPLACE PROCEDURE ifpr_esales
IS
in_file UTL_FILE.file_type;
linebuf VARCHAR2(80);
v_actid NUMBER(12);
v_act_name VARCHAR2(20);
temptab samptab%ROWTYPE;
str VARCHAR2(200) := '(';
BEGIN
in_file := UTL_FILE.fopen('/tmp', 'sample.txt', 'r');
LOOP
UTL_FILE.GET_LINE(in_file, linebuf);
v_actid := substr(linebuf, 1, instr(linebuf, '~', 1) - 1);
v_act_name := substr(linebuf, instr(linebuf, '~', 1) + 1);
MERGE
INTO samptab
USING(
SELECT v_actid id, v_act_name NAME
FROM dual) t ON(t.id = samptab.act_id) WHEN matched THEN UPDATE SET act_name = NAME WHEN NOT matched THEN INSERT VALUES(id, NAME);
str := str || v_actid || ',';
END LOOP;
EXCEPTION
WHEN NO_DATA_FOUND THEN
dbms_output.put_line('NO data found...EOF');
UTL_FILE.FCLOSE(in_file);
str := rtrim(str, ',') || ')';
--inserting into temp table
EXECUTE IMMEDIATE 'insert into temptab select * from samptab
where act_id not in ' || str;
--deleting unwanted values in s(If required, we can delete)
EXECUTE IMMEDIATE 'delete from samptab
where act_id not in ' || str;
COMMIT;
END;

Here i am fetching only account id and account name from my file and i am inserting into my table based on condition. Now my file consists of 48 fields. I want to upload 48 fields from file into table. can anyone modify my procedure and let me know the result. i was struck up here.. Please save my time.

Thanks in advance..

Regards
Joshi
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Nov 19 2007
Added on Oct 22 2007
1 comment
151 views