sql insert command


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting sql insert command
# 1  
Old 05-19-2006
sql insert command

Hi,

sqlplus -s / <<EOF > /dev/null
insert into table1 (a1, a2, a3) values ('a',1,'b');
commit;
EOF

in the above code can i pass the values to the insert command from shell script like this:

insert into table1 (a1, a2, a3) values ('$a',$b,'$c');

If yes, how is it passed??

Any help greatly appreciated. (I found some similar threads but culdn't find any particular soln to this)

thanks,

abey
# 2  
Old 05-19-2006
The problem is that you require ' characters to delimit strings. Here is a workaround not using a here doc:
Code:
userid=me
pswd=mypassword
 command=$(
 echo "$userid/$pswd"
 printf "insert into table1 (a1, a2, a3) values ('%s','%s','%s');\n" $a $b $c
 echo "commit;"
 echo "exit")
 echo "$command" | sqlplus -s

# 3  
Old 05-19-2006
Code:
a='abc'
b='def'
sqlplus -s / <<EOF
    select '${a}', '${b}' from dual;
EOF


Last edited by tmarikle; 05-19-2006 at 01:07 PM..
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Storing multiple sql queries output into variable by running sql command only once

Hi All, I want to run multiple sql queries and store the data in variable but i want to use sql command only once. Is there a way without running sql command twice and storing.Please advise. Eg : Select 'Query 1 output' from dual; Select 'Query 2 output' from dual; I want to... (3 Replies)
Discussion started by: Rokkesh
3 Replies

2. Shell Programming and Scripting

From sql Insert Query to XML format

Hi How do I translate Let say Cat inserts.sql gives Insert into PM9_TAXATION_ROUNDING (STATE_GECODE, TAX_TYPE, TAX_AUTHORITY, SYS_CREATION_DATE, SYS_UPDATE_DATE, APPLICATION_ID, DL_SERVICE_CODE, ROUNDING_METHOD) Values ('xx', 'xx', 'x', TO_DATE('10/26/2012 13:01:20',... (3 Replies)
Discussion started by: anuj87in
3 Replies

3. Shell Programming and Scripting

How to insert variable date (monthly) from SQL script

Hi Guys, Can someone please help me on adding/inserting a variable to an sql scipt? Basically I want to generate data on monthly (i.e. July 01, 2011 to July 31, 2011) basis. As shown below.. set head off; set linesize 300; set pagesize 200; spool /opt/oracle/temp/output.txt select... (1 Reply)
Discussion started by: pinpe
1 Replies

4. Programming

[SQL] Insert content file to mysql

dear all, i want to insert string in file to mysql i just want how to do that cause i am poor in sql languages ... so this file like this DATA.txt doni|student|westjava|123412|lombok| iwan|student|westjava|1234412|utankayu| rio|student|westjava|12342|cempedak| so i want insert DATA.txt to... (2 Replies)
Discussion started by: zvtral
2 Replies

5. Shell Programming and Scripting

convert file into sql insert stmt

My file is now cleaned, sanitized & prepped: 07/07/2008 21:18:51 Installation 52016 complete *BUT NOTHING CHANGED* 07/21/2008 15:28:15 Removal 52016 complete 07/21/2008 15:34:15 Removal 55856 complete 12/08/2009 19:30:40 Installation 62323 complete 12/08/2009 19:39:06 Installation ... (6 Replies)
Discussion started by: dba_frog
6 Replies

6. Emergency UNIX and Linux Support

Insert data into sql queries from a file

Hello friends, I need to insert data from a file to another. I need this to form an sql query file which will consist of 50.000 INSERT INTO sentences. my sql query file will consist of 50.000 times the below line consecutively: insert into subscriber... (6 Replies)
Discussion started by: EAGL€
6 Replies

7. SuSE

Syslog-ng 3.0.7 fails to insert into microsoft sql server

Dear All, Im currently configuring syslog-ng on SUSE Linux 10 SP2 to communicate with microsoft sql server 2005. I have installed freeTds 8.0. Tested TSQL ..works fine ISQL works fine. when testing with syslog-ng destination d_mssql { sql(type(mssql) host("ip address")... (0 Replies)
Discussion started by: SystemEng
0 Replies

8. Programming

SQL : Fine tune Insert by query

i would like to know how can i fine tune the following query since the cost of the query is too high .. insert into temp temp_1 select a,b,c,d from xxxx .. database used is IDS.. (1 Reply)
Discussion started by: expert
1 Replies

9. Web Development

SQL Select inside Insert

I have following. . . . $userid = 2 . $query = "select username from users where userid = ".$userid.";"; . $username = $line; $data="Some Data Here"; . $query = "insert into logger (username, data) valuse ($username, $data);"; . I would like to not have 2 database calls. (3 Replies)
Discussion started by: Ikon
3 Replies

10. Shell Programming and Scripting

Cron to Auto Insert SQL to DB

Hi People.. This is driving me mad. I have approx 100 files received daily, normally in 5 min intervals in the format of.. ******-logfile.sql These are auto uploaded to a folder on server called filelist The format of each file is as follows. DELETE FROM `webuserdata` WHERE... (0 Replies)
Discussion started by: OkiesPlace
0 Replies
Login or Register to Ask a Question