ZKX's LAB

sqlplus 脚本执行 输入变量值 如何把SQL的运行结果赋值给SHELL脚本中的变量。

2020-07-22知识7

在SQL*PLUS中可以用哪个命令显示系统变量或环境变量的值? 用show all可以查看所有68个系统变量值。如何把SQL的运行结果赋值给SHELL脚本中的变量。比如说,我想查一下库中数据表TAB的纪录数,并将此纪录数值赋值给SHELL脚本中的一个变量CNT,然后用CNT来进行其它应用。。sqlplus 执行脚本文件时如何传参数 d:\\test.sql脚本如下:[sql]view plaincopyselect&1 from&2;exit;执行时这样传参数:sqlplus\"scott/tiger@test\"@d:\\test.sql sysdate dual注意:参数必须用&[1-9]表示,不然传不进去,会提示让手动输入参数[sql]view plaincopyC:\\>;sqlplus\"scott/tiger@test\"@d:\\test.sql sysdate dualD:\\>;sqlplus\"scott/tiger@test\"@d:\\test.sql sysdate dualSQL*Plus:Release 11.2.0.1.0 Production on 星期二 11月 1 21:59:00 2011Copyright(c)1982,2010,Oracle.All rights reserved.连接到:Oracle Database 11g Enterprise Edition Release 11.2.0.1.0-ProductionWith the Partitioning,OLAP,Data Mining and Real Application Testing options原值 1:select&1 from&2新值 1:select sysdate from dualSYSDATE01-11月-11从 Oracle Database 11g Enterprise Edition Release 11.2.0.1.0-ProductionWith the Partitioning,OLAP,Data Mining and Real Application Testing options 断开D:\\>;如果脚本中有重复用到相同的值,如果&1=2:d:\\tes2.sql[sql]view plaincopydelete scott.emp where no=1 or deptno=2;commit;执行时,就必须传2个参数:[sql]view plaincopysqlplus。执行SQL脚本使用SQLyog,SQL脚本可以在实际应用中,减少开发时间,提高效率,使用SQLyog图形化界面来执行SQL脚本,执行MySQL的SQL脚本

#shell#变量#赋值语句#赋值#shell脚本

qrcode
访问手机版