简体   繁体   中英

Not able to do update oracle table

I have written a shell script where I'm trying to update oracle table, while updating table I'm experiencing below error on other hand when I'm executing with given hard coded values it is working fine.

Code

    DAT_SUPPL_ID='21'
    PA_OLT_CD='32'
    DT_PY_FD_TY='43'
    DT_FL_MTH='M201565'

    sqlplus -silent XXX/YYY@UDF <<!

    UPDATE HX_DT_PUC_DOL SET PROC_STA_TS=SYSTIMESTAMP,PROC_ID=1 WHERE DT_SPPL_INT_ID='${DAT_SUPPL_ID}' AND PH_CD='${PA_OLT_CD}' AND DAT_PY_FD_TY='${DT_PY_FD_TY}' AND DT_FLE_MONTH='${DT_FL_MTH}'
exit;
!

Error:

UPDATE HX_DT_PUC_DOL SET PROC_STA_TS=SYSTIMESTAMP,PROC_ID=1 WHERE DT_SPPL_INT_ID='21' AND PH_CD='1981808' AND DAT_PY_FD_TY='1' AND DT_FLE_MONTH='M200911'
                                                                                                                                          *                                             
ERROR at line 1:
ORA-00942: table or view does not exist

Working Code

       sqlplus -silent XXX/YYY@UDF <<!

UPDATE HX_DT_PUC_DOL SET PROC_STA_TS=SYSTIMESTAMP,PROC_ID=1 WHERE DT_SPPL_INT_ID='21' AND PH_CD='1981808' AND DAT_PY_FD_TY='1' AND DT_FLE_MONTH='M200911'
!

Add a semicolon after the end of sql.

-bash-4.2$ sqlplus hr/hr

SQL*Plus: Release 11.2.0.2.0 Production on Tue Apr 10 15:40:04 2018

Copyright (c) 1982, 2011, Oracle.  All rights reserved.


Connected to:
Oracle Database 11g Express Edition Release 11.2.0.2.0 - 64bit Production

SQL> create table test_table (col1 date, col2 number, col3 number, col4 varchar2(30));

Table created.

SQL> insert into test_table (col1,col2,col3,col4) values (sysdate, 1,1234,'@T!ger');

1 row created.

SQL> commit;

Commit complete.

SQL> select * from test_table;

COL1                     COL2       COL3 COL4
------------------ ---------- ---------- ------------------------------
10-APR-18                   1       1234 @T!ger

SQL> exit


#!/bin/sh
test_num1='1234'
test_char2='@T!ger'

sqlplus  hr/hr <<!

    UPDATE TEST_TABLE SET col1=SYSDATE , col2=4  WHERE col3='${test_num1}' AND col4='${test_char2}' ;
    commit;
    exit;
!

bash-4.2$ ./test_sql.sh

SQL*Plus: Release 11.2.0.2.0 Production on Tue Apr 10 16:11:08 2018

Copyright (c) 1982, 2011, Oracle.  All rights reserved.


Connected to:
Oracle Database 11g Express Edition Release 11.2.0.2.0 - 64bit Production

SQL> SQL>
1 row updated.

SQL>
Commit complete.

SQL> Disconnected from Oracle Database 11g Express Edition Release 11.2.0.2.0 - 64bit Production

sql without ;

bash-4.2$ ./test_sql.sh

SQL*Plus: Release 11.2.0.2.0 Production on Tue Apr 10 16:16:30 2018

Copyright (c) 1982, 2011, Oracle.  All rights reserved.


Connected to:
Oracle Database 11g Express Edition Release 11.2.0.2.0 - 64bit Production

SQL> SQL>   2      exit
    *
ERROR at line 2:
ORA-00933: SQL command not properly ended


SQL> Disconnected from Oracle Database 11g Express Edition Release 11.2.0.2.0 - 64bit Production

bash-4.2$ more test_sql.sh
#!/bin/sh
test_num1='1234'
test_char2='@T!ger'

sqlplus  hr/hr <<!

    UPDATE TEST_TABLE SET col1=SYSDATE , col2=4  WHERE col3='${test_num1}' AND col4='${test_char2}'
    exit;
!

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