Procedure
580519Oct 22 2007 — edited Oct 22 2007Hi 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