Visit Our UNIX and Linux User Community


Help is Script inserting in db2 tables


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Help is Script inserting in db2 tables
# 1  
Old 06-09-2011
Help is Script inserting in db2 tables

Hi,
I am creating a shell script to insert few records in db2 tables.
I am facing 2 challenges and would appreciate your help on this.

1) In my insert statement like follows:

Code:
 
db2 "connect to dbname user user_name";
 
db2 "insert into table_name (name, phone, ssn) values (${user_name},123456789,123456789)";

I am getting user_name from another file i am sourcing in this script.
The file has entry like this

Quote:
user_name=XYZ
I also tried
user_name='XYZ'
The insert is failing because the "name" field in table is varchar and is expect
'XYZ' in insert statement and its getting XYZ without single quotes.

Appreciate help on this

2) I would like to break the insert statement into multiple lines for formatting.
I tried this

Code:
 
 db2 "insert into table_name (name, phone, ssn) \n
 values (${user_name},123456789,123456789)";

The insert fails on this as well.

Help is appreciated on above 2 issues.
# 2  
Old 06-09-2011
Quote:
Originally Posted by pinnacle
The insert is failing because the "name" field in table is varchar and is expect 'XYZ' in insert statement and its getting XYZ without single quotes.
So put it in single quotes.
Code:
db2 "insert into table_name (name, phone, ssn) values ('${user_name}',123456789,123456789)";

Quote:
2) I would like to break the insert statement into multiple lines for formatting.
I tried this

Code:
 
 db2 "insert into table_name (name, phone, ssn) \n
 values (${user_name},123456789,123456789)";

The insert fails on this as well.
Remove the n.
Code:
db2 "insert into table_name (name, phone, ssn)        \
        values (${user_name},123456789,123456789)";

You might not even need the backslash if db2 is smart enough to eat newlines as whitespace.

Previous Thread | Next Thread
Test Your Knowledge in Computers #151
Difficulty: Easy
In 1975, adopting Unix required a license from Bell Laboratories that cost $20,000 USD.
True or False?

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How to use V$tables in UNIX shell script?

Hi All, In my script I have used the below code to retrieve the instance name V_INSTANCE_NAME=`sqlplus -s ${APPS_USR_PSWD} <<+ set pagesize 0 linesize 256 feedback off verify off head off echo off set serveroutput off select... (2 Replies)
Discussion started by: kalidoss
2 Replies

2. Shell Programming and Scripting

DB2 runstats script

I want to write a script to run statistics for a DB2 V9 database on AIX. Can anyone please help. Thanks! (0 Replies)
Discussion started by: goforit1010
0 Replies

3. Shell Programming and Scripting

Db2 query with script

Hi All, I want to connect two tables in DB2 using shell script and then compare the contents of two tables field by field.and i should return on the screen the un matched records .. Could any one please help me in connecting database tables using Unix and retriving data from the same. (1 Reply)
Discussion started by: kanakaraju
1 Replies

4. AIX

Extract data from DB2 tables and FTP it to outside company's firewall

Please help me in creating the script in AIX. requirement is; The new component's main function is to extract the data from DB2 tables and company's firewall directly. The component function needs to check the timestamp in the DB2 tables ((CREDAT and CRETIM) with the requested timestamp and... (1 Reply)
Discussion started by: priyanka3006
1 Replies

5. Shell Programming and Scripting

compare two tables using shell script

Hi, I want to compare two tables fieldwise using shell script. Can anyone help me regarding the same. The approach which i tried is to first move the two tables in simple txt file where each field is now seperated by space. But i can't retrive each field with "space" as a seperator b'coz there... (1 Reply)
Discussion started by: dtidke
1 Replies

6. Shell Programming and Scripting

Finding tables from each script

Hi, I just want to take each sql script from specified directory and print all tables in those sqls. Below is the script but getting an error lik ksh: 0403-057 Syntax error: `(' is not expected. Script is---- ls /ukdw/prd/working/TDMatrix/srualcb02/ukdw/prd/bin | awk '{printf("%s... (2 Replies)
Discussion started by: subrat
2 Replies

7. UNIX for Dummies Questions & Answers

Exception while loading DB2 driver Class.forName("com.ibm.db2.jcc.DB2Driver")

Hi... I m working on UNIX z/OS. Actually i have to pass the parameters from the JCL to java-db2 program thru PARM. I am able to pass the arguments but the problem occured is, it is throwing an exception while loading the db2 driver as 'Javaclassnotfound:com.ibm.db2.jcc.DB2Driver'... (0 Replies)
Discussion started by: Sujatha Gowda
0 Replies

8. Shell Programming and Scripting

Converting tables of row data into columns of tables

I am trying to transpose tables listed in the format into format. Any help would be greatly appreciated. Input: test_data_1 1 2 90% 4 3 91% 5 4 90% 6 5 90% 9 6 90% test_data_2 3 5 92% 5 4 92% 7 3 93% 9 2 92% 1 1 92% ... Output:... (7 Replies)
Discussion started by: justthisguy
7 Replies

9. UNIX for Dummies Questions & Answers

DB2 Backup Script

Not sure if this should be in AIX forum or not, but I thought I would try here since I am a "Dummy" when it comes to DB2. Does any one have a sample script that I could use to backup a database in DB2? The database is set up with Circular Logging so online backups are not possible. I am hoping... (0 Replies)
Discussion started by: jyoung
0 Replies

Featured Tech Videos