简体   繁体   中英

How to create and pass an array from KSH to Oracle sqlplus

I'm trying to create a KSH script in which I'm trying to create an array which will hold the contents of a text file, which contains a list of string values, and send the array to an SQL function in the KSH script. Here's what I've done so far:

export text_file=$HOME/values.log
while read **line**; 

       do
       CmResTypUpd 
   done < $text_file

The ResTypUpd does the following:

CmResTypUpd () {
            sqlplus -s $db_user/$db_pass@$db_inst <<EOF

            SET VERIFY OFF
            SET HEADING OFF
            SET PAGESIZE 200
            SET LINESIZE 200
            SET FEEDBACK OFF

            update My_Table set Column_Field_To_Change='NEW_VALUE' where IND1_COLUMN_VALUE='SomethingSomething' and IND2_COLUMN_VALUE='**$line**';
            commit;
   exit;

    EOF

            }

What I get is that the script hangs and does nothing.

Also, the script should be able to run cross-platform, meaning on any Unix or Linux .

You need to pass your line as parameter to the function

export text_file=$HOME/values.log 
while read line; do CmResTypUpd "$line"; done < $text_file

And your function:

CmResTypUpd () {
    [...]
    update My_Table set Column_Field_To_Change='NEW_VALUE' 
    where IND1_COLUMN_VALUE='SomethingSomething' and IND2_COLUMN_VALUE='$1';
    [...]
}

And also the variable **line** should be line

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM