[英]How attach the SQL script by SQLPlus to the bash loop?
I want to clear the table from all data ( Table_with_DB (it is in program sqldeveloper)) through sqlplus and based on filenames in the path ( path/to/files ) using SQLPlus completes the table (Table_with_DB) the filenames that are in the path.我想通过sqlplus并基于路径中的文件名( path/to/files )从所有数据( Table_with_DB (它在程序 sqldeveloper 中))中清除表,使用 SQLPlus 完成表(Table_with_DB)路径中的文件名.
I create 2 separate SQL files ( clear.sql ; register.sql )我创建了 2 个单独的 SQL 文件( clear.sql ; register.sql )
and 1 with bash ( bashloop.sh )和 1 个 bash ( bashloop.sh )
clear.sql清除.sql
BEGIN
package.clear('Table_with_DB');
END;
register.sql寄存器.sql
BEGIN
package.register('folderName' , '&1);
END;
bashloop.sh bashloop.sh
for i in path/to/files;
do
sqlplus -s userid/password@ @clear.sql
sqlplus -s userid/password@ @register.sql
done
I expect the query clear Table_with_DB and transfer the filenames from path/to/files to Table_with_DB using SQLPlus我希望查询清除Table_with_DB并使用SQLPlus将文件名从path/to/files 传输到Table_with_DB
but the actual it not work:(但实际上它不起作用:(
If I understand what you want to do then in your bashloop.sh you want to replace db_name with $i - or ${i} if you have filenames with spaces.如果我了解您想要做什么,那么在您的 bashloop.sh 中,您希望将db_name替换为$i - 或 ${i} 如果您有带空格的文件名。
Example sqlplus in loop.循环中的示例 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;
Example output示例 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.