tousinn
tousinn

Reputation: 73

how to transfer variables that have spaces from shell to oracle sqlplus

I am using shell script to run sql written in sql script files. In the script files there are some bind variables can be transfered from the shell run time parameters.

here is my code.

result=`sqlplus -s ${DB_USER_NAME}/${DB_USER_PWD}@${DB_SID}<<!
        SET HEADING ON
        SET UNDERLINE OFF
        SET COLSEP ','
        WHENEVER SQLERROR EXIT 255
        SET TRIM SPOOL ON
        SPOOL $outputPath

        @{sqlFilePath} $@


        #@${sqlFilePath} "$@"    
`

when I run the shell like this:

run_sql.sh param1 param2 "param 3" 

the $@ will be explained to param1,param2,param,3 as four vaiables

@{sqlFilePath} param1 param2 param 3

the "$@" will be explained to "param1 param2 param 3" as one variable

@{sqlFilePath} "param1 param2 param 3"

but I want the parameters will be explained like this

@{sqlFilePath} param1 param2 "param 3"

is there any way to solve my problem?

Upvotes: 3

Views: 3801

Answers (1)

DCookie
DCookie

Reputation: 43533

How about:

run_sql.sh param1 param2 '"param 3"'

which should expand in your script to:

@{sqlFilePath} param1 param2 "param 3"

Upvotes: 3

Related Questions