Oracle - 如何在不询问值的情况下使用 &?
Oracle - How to use & without being asked about the value?
基本上,我不想被问到这样的值::
SQL> select &test from dual;
Enter value for test:
我只想在脚本中声明 &test
,类似于:
&test varchar2(100):= 'some value'; --of course, this don't work.
执行
SQL> set define off
在 运行 您的代码之前。
SQL> select '&test' from dual;
'&TES
-----
&test
SQL>
如果你想“声明”它,那么使用var
:
SQL> var test varchar2(200);
SQL> exec :test := 'some value';
PL/SQL procedure successfully completed.
SQL> print test
TEST
----------------------------------------------------------------------------------------------------
some value
SQL>
动态 SQL:我不会锁定任何人,但是 - 我会更改我的密码。
SQL> connect scott/tiger
Connected.
SQL> var test varchar2(200);
SQL> exec :test := 'lion';
PL/SQL procedure successfully completed.
SQL> print test
TEST
----------------------------------------------------------------------------------------------------
lion
SQL> begin
2 execute immediate 'alter user scott identified by ' || :test;
3 end;
4 /
PL/SQL procedure successfully completed.
SQL> connect scott/tiger
ERROR:
ORA-01017: invalid username/password; logon denied
Warning: You are no longer connected to ORACLE.
SQL> connect scott/lion
Connected.
SQL>
基本上,我不想被问到这样的值::
SQL> select &test from dual;
Enter value for test:
我只想在脚本中声明 &test
,类似于:
&test varchar2(100):= 'some value'; --of course, this don't work.
执行
SQL> set define off
在 运行 您的代码之前。
SQL> select '&test' from dual;
'&TES
-----
&test
SQL>
如果你想“声明”它,那么使用var
:
SQL> var test varchar2(200);
SQL> exec :test := 'some value';
PL/SQL procedure successfully completed.
SQL> print test
TEST
----------------------------------------------------------------------------------------------------
some value
SQL>
动态 SQL:我不会锁定任何人,但是 - 我会更改我的密码。
SQL> connect scott/tiger
Connected.
SQL> var test varchar2(200);
SQL> exec :test := 'lion';
PL/SQL procedure successfully completed.
SQL> print test
TEST
----------------------------------------------------------------------------------------------------
lion
SQL> begin
2 execute immediate 'alter user scott identified by ' || :test;
3 end;
4 /
PL/SQL procedure successfully completed.
SQL> connect scott/tiger
ERROR:
ORA-01017: invalid username/password; logon denied
Warning: You are no longer connected to ORACLE.
SQL> connect scott/lion
Connected.
SQL>