[英]How attach the SQL script by SQLPlus to the bash loop?
我想通过sqlplus并基于路径中的文件名( path/to/files )从所有数据( Table_with_DB (它在程序 sqldeveloper 中))中清除表,使用 SQLPlus 完成表(Table_with_DB)路径中的文件名.
我创建了 2 个单独的 SQL 文件( clear.sql ; register.sql )
和 1 个 bash ( bashloop.sh )
清除.sql
BEGIN
package.clear('Table_with_DB');
END;
寄存器.sql
BEGIN
package.register('folderName' , '&1);
END;
bashloop.sh
for i in path/to/files;
do
sqlplus -s userid/password@ @clear.sql
sqlplus -s userid/password@ @register.sql
done
我希望查询清除Table_with_DB并使用SQLPlus将文件名从path/to/files 传输到Table_with_DB
但实际上它不起作用:(
如果我了解您想要做什么,那么在您的 bashloop.sh 中,您希望将db_name替换为$i - 或 ${i} 如果您有带空格的文件名。
循环中的示例 sqlplus。
#!/bin/bash
username=system
password=passwordsystem
tns_alias=esmd
for i in /opt/oracle/example1/test*/file*.txt;
do
$ORACLE_HOME/bin/sqlplus $username/$password@$tns_alias <<EOF
SET SERVEROUTPUT ON SIZE 2000
BEGIN
dbms_output.put_line('$i');
END;
/
EOF
done;
示例 output
Connected to:
Oracle Database 11g Release 11.2.0.3.0 - 64bit Production
SQL> SQL> 2 3 4 /opt/oracle/example1/test2/file2.txt
PL/SQL procedure successfully completed.
SQL> Disconnected from Oracle Database 11g Release 11.2.0.3.0 - 64bit Production
SQL*Plus: Release 11.2.0.3.0 Production on Tue Oct 22 13:59:24 2019
Copyright (c) 1982, 2011, Oracle. All rights reserved.
Connected to:
Oracle Database 11g Release 11.2.0.3.0 - 64bit Production
SQL> SQL> 2 3 4 /opt/oracle/example1/test3/file3.txt
PL/SQL procedure successfully completed.
SQL> Disconnected from Oracle Database 11g Release 11.2.0.3.0 - 64bit Production
SQL*Plus: Release 11.2.0.3.0 Production on Tue Oct 22 13:59:24 2019
Copyright (c) 1982, 2011, Oracle. All rights reserved.
Connected to:
Oracle Database 11g Release 11.2.0.3.0 - 64bit Production
SQL> SQL> 2 3 4 /opt/oracle/example1/test4/file4.txt
PL/SQL procedure successfully completed.
SQL> Disconnected from Oracle Database 11g Release 11.2.0.3.0 - 64bit Production
oracle@esmd:~/example1>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.