我对密码中的特殊字符“@”有疑问。 问题是我不知道如何将带有此特殊字符的密码传递到脚本文件并使用 sqlplus 连接。
例如,我有用户“test_user”,密码为“temp123@”。对于通过 sqlplus 登录,我使用以下带有转义的字符串:
sqlplus test_user/\"temp123@\"@some-db:1521/SID
效果很好。对于我的情况,我需要传递密码作为 sql 脚本的参数。例如,我有以下脚本进行连接(实际上是使用多对登录名/密码的脚本来一次更新许多用户):
-- @deploy.sql
connect &&2./&&3.@&&1.
失败,因为 sqlplus 无法正确解释带有“@”的密码。我尝试了谷歌的许多转义建议,但其中大部分适用于 sqlplus 调用时的连接字符串。对于我的情况,它需要传递给脚本的参数。
使用:cmd.exe 而不是 powershell 窗口
if not :
在 powershell windows 中:sqlplus 'login/\"P@$$w0rd\"@TNS_NAME'
在cmde.exe中:sqlplus登录/\"P@$$w0rd\"@TNS_NAME
连接字符串中只需要引号:
connect &&2./"&&3."@&&1.
alter user scott identified by "T@!ger";
powershell脚本
.\test-connect.ps1
$username = "scott"
$password = '\"T@!ger\"'
$connect_string ="DEV19"
$list_scripts = "select 1 ,sysdate from dual ;"
$list_scripts | ./sqlplus $username/$password@$connect_string;
C:\instantclient_19_15>powershell .\test-connect.ps1