How can i load or insert a table in oracle from c language thru unix environment


 
Thread Tools Search this Thread
Top Forums Programming How can i load or insert a table in oracle from c language thru unix environment
# 1  
Old 07-04-2002
Question How can i load or insert a table in oracle from c language thru unix environment

I'm having a oracle server and i'm having a table in that.
I'm having a linux server which is in network with the oracle server. I need to write a c program in linux env when on execution loads the table with the text file given as input.

Please explain me the flow of process in that and also tell me the logic of that c pgm and what can be used in c under unix so that we can connect and load oracle
# 2  
Old 07-04-2002
I dont think u need the pgm flow....coz, its quite simple....but I can throw some light on how to connect to oracle from c program...and other statements.


1.Connect to Oracle
EXEC SQL CONNECT :<OracleUID>;

2. Insert into table.
EXEL SQL INSERT INTO <Tablename> ( field1, field2 , ...)
VALUES ( :var_field1, :var_field2 , ...);

3. Commit the work.
EXEC SQL COMMIT WORK;

4. To roll back the work.
EXEC SQL ROLLBACK;

5. Release Oracle connection.
EXEC SQL ROLLBACK WORK RELEASE;


And.....all exception conditions should also be handled after each EXEC SQL statement. (SQLERROR, NOTFOUND, NOORACLE etc)


Will that do?

Deepa
# 3  
Old 07-05-2002
will it compile

Thanks deepa whats my question here is will it compile in a ordinary c compiler for unix. Else what has to be done

W
# 4  
Old 07-05-2002
You got to use the Pro-C compiler...
# 5  
Old 07-05-2002
Is there Oracle Client loaded in your Linux machine? Is yes, then you can use the sqlplus or the sqlldr utility provided with Oracle. You can create .sql files on the fly in your C code, which basically have commands created like:
INSERT INTO TABLE_NAME VALUES(va11, val2);
...
INSERT INTO TABLE_NAME VALUES(va11, val2);
where val1 and val2 are values read from your input text file.
These .sql files can then be run from sqlplus, which can again be called from your C code.
# 6  
Old 07-08-2002
Depending what flavor of UNIX you are using you need to declare this:

/* Include the SQL Communications area */

typedef char asciz[20];
exec sql include sqlca;

exec sql begin declare section;
exec sql type asciz is string(20) reference;
asciz usr_name;
asciz pwd;
asciz dbname;
exec sql end declare section;

/* End SQL Communications area */

Also here is a really good link:

http://www-rohan.sdsu.edu/doc/oracle...661_01/toc.htm
# 7  
Old 07-09-2002
The sql loader(sqlldr) loads your data from a file(.dat or .sql) into the oracle table.

The ctl file is the control file that helps in loading the data from the flat file into the oracle table.

The contents of sample demo.ctl file is

load data
infile 'path name of unix server' //Here is where the flat file
//would be located
insert
into table test
(
name position(01:10) char(10),
)


The execution of this ctl file goes like this:

sqlldr username/password control=demo.ctl


-Nisha
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Script to load XML file to Oracle table

Experts. I have created a oracle table as below. create table xml_tab ( File_No number , File_content Varchar2(2000), file_type xmltype ); Daily we are receiving many XML files as below. here is our sample xml file. File1 : (7 Replies)
Discussion started by: vasuvv
7 Replies

2. Shell Programming and Scripting

Insert script result into Oracle Table

Hi All, I want to insert STAT and ENDTIME values for each job in joblist into TBL_DAILY_STATUS table. Eg: insert into tbl_daily_status values(STAT,ENDTIME); Please help me on this. #!/bin/ksh joblist="com_abc_job com_abc_dot_job com_abc_seq com_abc_det" for i in $joblist do... (8 Replies)
Discussion started by: vichuelaa
8 Replies

3. Shell Programming and Scripting

Insert into Oracle table thru UNIX - linux 2.6.9-89

Hi, I am trying to insert a record into a table (say dips_tbl) which resides in Oracle DB through a ksh script. I want to insert records into few of the table columns-not all. I'll give an e.g. for the date column "CREATE_DATE". For that I first execute SQL1="SELECT SYSDATE FROM DUAL" ... (1 Reply)
Discussion started by: dips_ag
1 Replies

4. Shell Programming and Scripting

Insert value to ORACLE table from sqlldr log

This is the sample sqlldr log: ------------------------------------------------------------------------------------------------------------ SQL*Loader: Release 9.2.0.7.0 - Production on Sun Feb 8 23:37:02 2009 Copyright (c) 1982, 2002, Oracle Corporation. All rights reserved. Control... (13 Replies)
Discussion started by: aimy
13 Replies

5. Shell Programming and Scripting

load a data from text file into a oracle table

Hi all, I have a data like, 0,R001,2,D this wants to be loaded into a oracle database table. Pl let me know how this has to be done. Thanks in advance (2 Replies)
Discussion started by: raji35
2 Replies

6. Shell Programming and Scripting

To load data from variable to oracle table ....???

Hi all, How to load variable value into Oracle table? I have created a file validation shell script. After the validation completes, i need to update a Oracle table with the variable value... Can someone help me how to do it? I have searched, but not able to get answer. i have 4 variables... (2 Replies)
Discussion started by: Amit.Sagpariya
2 Replies

7. Shell Programming and Scripting

To load data from variable to oracle table

Hi all, How to load variable value into Oracle table? I have created a file validation shell script. After the validation completes, i need to update a Oracle table with the variable value... Can someone help me how to do it? I have searched, but not able to get answer. i have 4... (1 Reply)
Discussion started by: Amit.Sagpariya
1 Replies

8. UNIX for Advanced & Expert Users

unix script for update or insert records from a file to a oracle table

Hi, I have delimited file(|). Sample data: 1|name|50009|DS24|0|12 2|name|30009|DS24|0|13 3|name|20409|DS24|0|14 4|name|20009|DS24|0|15 5|name|10009|DS24|0|16 I want to load this data into a oracle table (update and insert) Please help me the commands and also... (1 Reply)
Discussion started by: unihp1
1 Replies

9. UNIX for Advanced & Expert Users

How to load comma seperated values file (*.csv) into Oracle table

Hi all I need to input values in a .csv file into my Oracle table running in Unix, I wonder what would be the command to do so... The values are recorded in an excel file and I tried using a formatted text file to do so but failed because one of the field is simply too large to fit in the... (4 Replies)
Discussion started by: handynas
4 Replies

10. UNIX for Dummies Questions & Answers

How to load comma seperated values file (*.csv) into Oracle table

Hi all I need to input values in a .csv file into my Oracle table running in Unix, I wonder what would be the command to do so... The values are recorded in an excel file and I tried using a formatted text file to do so but failed because one of the field is simply too large to fit in the... (5 Replies)
Discussion started by: handynas
5 Replies
Login or Register to Ask a Question