Execute sql statment in korn shell


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Execute sql statment in korn shell
# 1  
Old 06-04-2015
Execute sql statment in korn shell

I am fairly new to writing scripts, and have gotten a lot of help from this site in the past with many of the posts.
I have a question/issue with a script I am attempting to write and have a question regarding executing an sql statement inside of a loop (do while). I have in the past written scripts where script syntax and logic and then has one or more SQL statements, but not intermixed.
I am on HP-UX, running INFORMIX and we use dbaccess to call the DB.
The issue that I am having is in regards to using a counter in a loop and executing an sql that contains the value of the counter.
I have played around already with the redirect (>>$op<<!!!) but still getting errors on a “unmatched <<”
And when I seem to resolve that; the sql wont execute..
I am trying this in a loop because I need to update 2+ million records { and wanted to get a simple select working first} and don’t want to sit and update and execute individually many many times - I can’t run the range to high as I will take up all of the locks, so I am starting with 100K records at a time.

Any direction, guidance, help would be greatly appreciated
Code:
 x=1
 xa=1
 while ((x<xa)) ; do
    print -n \\rx = $x
    sleep 1
     dbaccess ${DB}@${DBSERV} >>${op} <<!!! 
       set isolation dirty read;
        SELECT
          <field_1>
          ,<field_2>
        FROM
          <table>
        Where
           <field> between '$x' and '$xa'
                   ;
                 !!!
                 
     ((x=x+100000))
 done

Moderator's Comments:
Mod Comment Please avoid unusual fonts/formatting

Last edited by jim mcnamara; 06-04-2015 at 10:15 PM..
# 2  
Old 06-04-2015
The here document is part of your problem
The last !!! has to be in column #1 - the leftmost column. Or the leading <<!!! needs a dash : <<-!!!

Next: I think your redirection needs to be outside the top !!! - that is to the right of it not inside.

I do not know Informix, but generally speaking, massive selects do not use locking, massive updates do. So a periodic commit releases the locks.

This answer was predicated on your using a modern shell.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Korn shell script - SQL statement challenges

Hi scripting experts. I have some coding challenges that I'm hoping you can help me out. I have one file#1 that contains the following sql statement that spans over multiple lines: sql Select /*+ use_has(a,b) */ * from customer a, customer_address b where a.id = b.id... (1 Reply)
Discussion started by: pchang
1 Replies

2. Programming

pass value from Oracle sql to Korn shell

Hi All , I am trying to pass a value from sqlplus to korn shell . There is a table tab1 in Oracle that has a column userdate. I need to pass the userdate to the korn shell . This is what I am doing . VALUE=`sqlplus -silent username/password << END set pagesize 0 feedback off verify off... (14 Replies)
Discussion started by: megha2525
14 Replies

3. Shell Programming and Scripting

How to execute korn shell script from different directory

Guy's , I need to run korn shell script from different directory, usually I run the script using ./details.ksh in the same directory but now I need to run the file and process details using awk code. Now I am running the script this way but with no luck Directory = home/users/work ... (3 Replies)
Discussion started by: James_Owen
3 Replies

4. Shell Programming and Scripting

MKS KORN SHELL WONT EXECUTE from windows command prompt

Can anybody help me with this small script , the script works fine and launches the IE from c:\documents and settings \test\my documents>ksh prompt $RunURL1.sh this scitpt works and launches the ie from ksh , but when i schedule it to run the script then i get the error box saying command:1... (2 Replies)
Discussion started by: venu
2 Replies

5. Programming

how to execute the sql quires from shell script?

hi all, I'm new to shell scripting, i want to know how to use the sql statements from the shell script? is there any documents or pdf to learn from the begining? plese provide me some useful links on the same. Thanks all in advance..,:b: (3 Replies)
Discussion started by: vij_krr
3 Replies

6. Shell Programming and Scripting

how to execute shell script in another server that contain sql.

hi all, how to execute shell script in another server that contain sql script. i tried using "ssh -l" option.. but i am unable to load the environment variable of the remote host. please suggest how execute the shell script contain sql part inside it. (2 Replies)
Discussion started by: sandeep909
2 Replies

7. UNIX for Advanced & Expert Users

Accessing PL/SQL OUT variables in Korn Shell Script

Hello All, I was just wondering if there is any direct way to access PL/SQL OUT variables from Korn Shell Script. I could already figure out how to return a single value back from PL/SQL to Shell Script (using bind variable). But, what if we want to return multiple values? One option I... (4 Replies)
Discussion started by: bright_future
4 Replies

8. Shell Programming and Scripting

How to redirect value from sql select statment to unix variable

Hi, I need to get the value from the table using the sql command and store this value into the unix variable so that i can use this value for furthure use.. Please can any body help me in this regards Thanks & Regards Abdul Hafeez Shaik (17 Replies)
Discussion started by: abdulhafeez
17 Replies

9. Shell Programming and Scripting

Shell Script to execute SQL's

Hi people, i need youre help on this. I need to create an Shell SCript to list in a directory some sql files and then execute them one by one . Also i need to have Logs from the executed Sql's to send to our costummers. Can anyone help me on this Regards, osramos (2 Replies)
Discussion started by: osramos
2 Replies

10. Shell Programming and Scripting

How to execute a .sql file with shell script

hi everybody... can anyone help me in executing the .sql file with shell scripting.... thanx in advance (2 Replies)
Discussion started by: abuanas
2 Replies
Login or Register to Ask a Question