简体   繁体   English

在 Linux 中尝试通过 shell 脚本向 oracle 数据库表插入记录时出错

[英]Error while trying to insert a record to oracle database table via shell script in Linux

Could anyone help me on resolving this error which I am getting when I try to run a shell script test.sh with parameter as 20211007 The code is as below:任何人都可以帮助我解决这个错误,当我尝试运行参数为 20211007 的 shell 脚本 test.sh 代码如下:

#!/bin/sh

ODATE=${1}
file_source_sys="abc"
File_name="xyz"
file_deliver_time="20210218:12:56:76"

HOME_DIR="/var/tmp/Sneha"

source ~/env/INFORMATICA.env
source ${HOME_DIR}/db.properties

cd ${HOME_DIR}

cat <<EOD > temp.sql
INSERT INTO test VALUES 
('${file_source_sys}','${File_name}','${file_deliver_time}','$ODATE');

commit;

quit
EOD

sql ${USER}/\"${PASS}\"@${DB_INSTANCE} @temp.sql

The error is as below:错误如下:

SQLcl: Release 18.3 Production on Sat Nov 06 18:53:24 2021 Copyright (c) 1982, 2021, Oracle. SQLcl:2021 年 11 月 6 日星期六 18:53:24 发布 18.3 版 版权所有 (c) 1982, 2021,Oracle。 All rights reserved.版权所有。

Last Successful login time: Sat Nov 06 2021 18:53:25 +01:00上次成功登录时间:2021 年 11 月 6 日星期六 18:53:25 +01:00

Connected to: Oracle Database 19c Enterprise Edition Release 19.0.0.0.0 - Production Version 19.11.0.0.0连接到:Oracle Database 19c 企业版 19.0.0.0.0 版 - 生产版 19.11.0.0.0

Error starting at line : 1 File @ /var/tmp/Sneha/temp.sql In command - INSERT INTO test VALUES ('abc','xyz','20210218:12:56:76','20211005') Error at Command Line : 1 Column : 13 File @ /var/tmp/Sneha/temp.sql Error report - SQL Error: ORA-00942: table or view does not exist错误从行开始:1 文件@/var/tmp/Sneha/temp.sql 在命令中 - INSERT INTO test VALUES ('abc','xyz','20210218:12:56:76','20211005') 错误在命令行:1 列:13 文件@/var/tmp/Sneha/temp.sql 错误报告 - SQL 错误:ORA-00942:表或视图不存在

Commit complete.提交完成。

Disconnected from Oracle Database 19c Enterprise Edition Release 19.0.0.0.0 - Production Version 19.11.0.0.0与 Oracle Database 19c 企业版 19.0.0.0.0 版 - 生产版 19.11.0.0.0 断开连接

Note I double checked and confirmed that table test is created in DB.注意我仔细检查并确认表测试是在数据库中创建的。 Also I manually checked my inserting this insert statement generated into DB it is working fine.此外,我手动检查了我将生成的插入语句插入到数据库中的情况,它工作正常。 But via Shell script it is not happening.但是通过 Shell 脚本它不会发生。

Also I see the temp.sql file is generated with below content:我还看到 temp.sql 文件是用以下内容生成的:

INSERT INTO test VALUES ('abc','xyz','20210218:12:56:76','20211005');插入测试值 ('abc','xyz','20210218:12:56:76','20211005');

commit;犯罪;

quit退出

I am not sure where in the code I am going wrong, as I can see the script is connecting to database successfully and also doing commit and disconnecting itself as well properly.我不确定代码中哪里出错了,因为我可以看到脚本成功连接到数据库,并且也正确地进行了提交和断开连接。

Your help is much appreciated.非常感谢您的帮助。 Many thanks非常感谢

你确定你连接到了正确的数据库,它说表“test”不存在,尝试做:

INSERT INTO DB_NAME.test VALUES (...);

I am connecting to a simulation database hence this error was coming, the actual schema and simulation schema are so much alike that I missed one one character in the hostname while connecting to actual schema.我正在连接到一个模拟数据库,因此出现了这个错误,实际模式和模拟模式非常相似,以至于我在连接到实际模式时错过了主机名中的一个字符。 Many thanks for your suggestions.非常感谢您的建议。 :) :)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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