Link to home
Start Free TrialLog in
Avatar of jsaravana
jsaravana

asked on

insert data from a file

Hi,

I need to insert data from csv file and need to do some validations.
import is not working inside stored procedure.
load might create integrity issue.
Is there a way to use insert command in this?. Any method to read csv data n insert to table using insert command?.

I need to catch the exceptions if any error occurs n throw back the error. So if there is any way to use insert command it would be gr8!

Thanks!
SOLUTION
Avatar of tangchunfeng
tangchunfeng

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of tangchunfeng
tangchunfeng

and if all data are legal, you will not get warning
SQL3107W  There is at least one warning message in the message file.


$ cat a.csv
a,1
a,3

$ db2 import from a.csv of del modified by coldel, messages a.log replace into a

Number of rows read         = 2
Number of rows skipped      = 0
Number of rows inserted     = 2
Number of rows updated      = 0
Number of rows rejected     = 0
Number of rows committed    = 2
Avatar of jsaravana

ASKER

Hi experts,

I am creating this on windows so AIX commands wont work.
Also, I wont be able to use import inside stored procedure. I would like to catch the errors and post back to the front end. Exception handling can be done inside stored procedure only. So please suggest the best way to do this.

ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Hi Experts,
I found out a way to use import in stored procedure.
CALL SYSPROC.ADMIN_CMD('import from C:\testfield.csv of del insert into administrator.test_title');

Thanks!