【oracle】处理oracle用户密码中的特殊字符$和@
1.创建测试用户
create user testdb identified by "testdb@";
grant connect,resource to testdb;
grant unlimited tablespace,create session to testdb;
alter user testdb identified by "test$db@";
查看用户权限
select * from dba_sys_privs;
select * from dba_role_privs;
select * from dba_tab_privs;
select * from role_sys_privs;
select * from role_role_privs;
select * from role_tab_privs;
select * from user_sys_privs;
select * from user_role_privs;
select * from user_tab_privs;
2.shell连接oracle数据库
su - oracle
mkdir $ORACLE_HOME/test
vi test.sh
输入以下内容:
#!/bin/bash
script_path=`cd (dirname $0);pwd` #$0 表示文件名
temp_sql=${script_path}/temp_$$.sql #$$表示进程号
user_name=testdb
user_password='test$db@'
user_password_n='"'${user_password}'"' #处理密码中的特殊字符$和@
jdbc_conn=10.10.10.1:1521/orcl
echo "select sysdate from dual;" > ${temp_sql}
echo "exit;" >> ${temp_sql}
export NLS_LANG=.AL32UTF8
sqlplus ${user_name}/${user_password_n}@${jdbc_conn} "@${temp_sql}"n #正确
sqlplus ${user_name}/${user_password}@${jdbc_conn} "@${temp_sql}" #错误
执行test.sh:
sh -x test.sh
或者
su - oracle -c "sqlplus testdb/'test$db@'@10.10.10.1:1521/orcl @/tmp/test.sql"
su - oracle -c "sqlplus testdb/'test$db@'@10.10.10.1:1521/orcl '@/tmp/test.sql'"
su - oracle -c "sqlplus testdb/'test$db@'@10.10.10.1:1521/orcl \"@/tmp/test.sql\""