Oracle - 如何使用&没有被问及价值?

发布于 2025-01-15 00:31:19 字数 248 浏览 3 评论 0原文

基本上,我不想被问到这样的值::

SQL> select &test from dual;
Enter value for test:

我只想沿着脚本声明 &test ,如下所示:

&test varchar2(100):= 'some value'; --of course, this don't work.

Basically, I don't want to be asked about the value like this::

SQL> select &test from dual;
Enter value for test:

I want only declare the &test along the script, something like it:

&test varchar2(100):= 'some value'; --of course, this don't work.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

戏剧牡丹亭 2025-01-22 00:31:19

执行

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>

Execute

SQL> set define off

before running your code.


SQL> select '&test' from dual;

'&TES
-----
&test

SQL>

If you want to "declare" it, then use var:

SQL> var test varchar2(200);
SQL> exec :test := 'some value';

PL/SQL procedure successfully completed.

SQL> print test

TEST
----------------------------------------------------------------------------------------------------
some value

SQL>

In dynamic SQL: I won't lock anyone, but - I'll change my password.

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>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文