-
Passing parameters to sql inside a shell script.
Hi,
can anyone help me in this script.
nawk '{{print $1,$2,$3}}' ./$DirectoryName/AuditGroupTableTableData_$TimeStamp.txt | while read a b c
do
echo $a
echo $b
echo $c
touch ./$DirectoryName/Query.sql
ret=`sqlplus -s $db_user/$db_pwd@$db_sid "'$a'" "'$b'" "'$c'" < ./${DirectoryName}/Query.sql
SET HEADING OFF
SET SERVEROUTPUT ON SIZE 10000
SET FEEDBACK OFF
DECLARE
CNT NUMBER(5);
DROPCNT NUMBER(5);
ERRORCNT NUMBER(5);
BEGIN
SELECT COUNT(*) INTO CNT FROM USAGE_INTRNL_ERROR WHERE AUDIT_GROUP_ID='&1';
IF ( CNT != &3) THEN
Dbms_Output.put_line('SELECT INTRL_DROP_QTY,INTRL_ERROR_QTY INTO DROPCNT,ERRORCNT FROM USAGE_AUDIT_GROUP WHERE AUDIT_GROUP_NBR=''&1'';';
SELECT INTRL_ERROR_QTY INTO DROPCNT FROM USAGE_AUDIT_GROUP WHERE AUDIT_GROUP_NBR = '&1';
SET DROPCNT=DROPCNT-CNT;
Dbms_Output.put_line('UPDATE USAGE_AUDIT_GROUP SET INTRL_DROP_QTY='||DROPCNT||' ,INTRL_ERROR_QTY='||CNT||' WHERE AUDIT_GROUP_NBR=''&1'';'
END IF;
END;
/
EXIT;
EOF`
touch ./$DirectoryName/SELECTQuery_$TimeStamp.sql
touch ./$DirectoryName/UPDATEQuery_$TimeStamp.sql
for stmt in `cat ./${DirectoryName}/Query.sql`
do
is_select=`echo ${stmt} | grep "^SELECT" | wc -l`
if [ ${is_select} -ne 0 ]
then
echo ${stmt} >> ./$DirectoryName/SELECTQuery_$TimeStamp.sql
else
echo ${stmt} >> ./$DirectoryName/UPDATEQuery_$TimeStamp.sql
fi
done
done
Am unable to connect to db with this .
is this statement correct:
ret=`sqlplus -s $db_user/$db_pwd@$db_sid "'$a'" "'$b'" "'$c'" < ./${DirectoryName}/Query.sql
and the input file contents for nawk is as follows:
1LK81JVDE2HRNDG 3 0
1LMXTJJD0W28TX2 3 0
1LS1XJGDEVWAC5T 7 1
-
What errors do you get?
For one, your sqlplus query has syntax errors.
Related to the parameters, you should not use double and single quotes.
Also if you wish to execute a query, use '@' instead of '<' in the command line, try this:
PHP Code:
ret=`sqlplus -s $db_user/$db_pwd@$db_sid "$a" "$b" "$c" @./${DirectoryName}/Query.sql <<EOF
-- here go your additional sql commands --
exit
EOF`
Last edited by LKBrwn_DBA; 03-27-2012 at 03:57 PM.
"The person who says it cannot be done should not interrupt the person doing it." --Chinese Proverb
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|