shell:shell执行oracle的sql文件

shell执行oracle的sql文件:oracle的sql文件可以嵌套执行sql文件。

【create.sql】注意sql文件编码为UTF8与数据库字符集相同

create table tab01(

c1 varchar2(6),

c2 number(38)

) ;

comment on table tab01 is '测试';

comment on column tab01.c1 is '字段1';

comment on column tab01.c2 is '字段2';

【defineVariable.properties】

define tnsname = 10.137.150.234:1521/ssa

define ssmgr_user = ssmgr_c10

define ssmgr_user_pwd = ssmgr_c10

【main_DB.sql】

@'defineVaiable.properties';

prompt Connect to database…

conn &&ssmgr_user/&&ssmgr_user_pwd@&&tnsname

@'create.sql';

exit; --一定要退出否则shell重定向执行日志后不能返回shell环境

【setupDB_oracle.sh】

#!/bin/bash

export NLS_LANG=AMERICAN_AMERICA.AL32UTF8

$ORACLE_HOME/bin/sqlplus /nolog @main_DB.sql;