我们如何在shell脚本中进行数据库连接? [英] How we can do DB connection in shell script?

查看:190
本文介绍了我们如何在shell脚本中进行数据库连接?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,



我正在写一个shell脚本,它处理DB(Oracle)表操作(创建,更新,更改,插入等...)

对于每个操作我都写了单独的shell脚本函数。

请告诉我,有必要在下面的每一个函数中连接到oracle吗?



sqlplus -s scott / tiger<< EOF



请告诉我这个数据库连接的范围是函数还是整个脚本?



我用这个语句编写了一个DB_Connection函数,其他函数从脚本中的main函数调用。

主函数包括DB_connection,Create_Table,inser_rows等...函数。



因此,在编写任何DDL语句之前,必须在每个函数中写入此行。

Eg

sqlplus -s scott / tiger<< EOF

选择*从< table_name>

退出

EOF





提前致谢。 :-O

解决方案

Hello Poonam,



<<<< EOF和EOF标签之间的行表示通过管道输入SQLPlus可执行文件的SQL命令。请查看[ ^ ]文章。它不像大多数编程语言中提供的数据库连接,只需打开一次并在任何地方重复使用,这是管道命令。



问候,

Hello,

I am writting a shell script, which handles DB(Oracle) table operations (create, update, alter, insert etc...)
For each operation I had written seperate shell script function.
Could you please tell me that, it is necessary to connect to oracle in every function with below line?

sqlplus -s scott/tiger << EOF

Please tell me the scope of this DB connection is functionwise or its overall to the script?

I had written a DB_Connection function with this statement and other functions are getting called from main function in script.
Main function includes DB_connection, Create_Table, inser_rows etc...functions.

So is it necessary to write this line in every function before writting any DDL statement.
E.g.
sqlplus -s scott/tiger << EOF
Select * from <table_name>
exit
EOF


Thanks in advance. :-O

解决方案

Hello Poonam,

The lines between <<EOF and EOF tags denotes the SQL commands being piped into the SQLPlus executable. Have a look at this[^] article. It''s not like a Database Connection available in most of the programming languages which you open once and reuse everywhere, It''s a pipe command.

Regards,


这篇关于我们如何在shell脚本中进行数据库连接?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆