我正在看Oracle中的脚本,我看到了一些我不认识的东西
REM INSERTING into database1."Users" SET DEFINE OFF; Insert into database1."Users" ("id","right") values ('1','R');
我正在寻找关于"set define off"的文档,它实际上是在写"禁用解释命令以用它们的值替换替换变量"
我真的不明白他们想说什么.
谁能帮我?
默认情况下,SQL Plus将'&'视为开始替换字符串的特殊字符.运行由于其他原因而包含"&"的脚本时,这可能会导致问题:
SQL> insert into customers (customer_name) values ('Marks & Spencers Ltd'); Enter value for spencers: old 1: insert into customers (customer_name) values ('Marks & Spencers Ltd') new 1: insert into customers (customer_name) values ('Marks Ltd') 1 row created. SQL> select customer_name from customers; CUSTOMER_NAME ------------------------------ Marks Ltd
如果您知道您的脚本包含(或可能包含)包含'&'字符的数据,并且您不希望上述替换行为,那么请set define off
在运行脚本时关闭该行为:
SQL> set define off SQL> insert into customers (customer_name) values ('Marks & Spencers Ltd'); 1 row created. SQL> select customer_name from customers; CUSTOMER_NAME ------------------------------ Marks & Spencers Ltd
您可能希望set define on
在脚本末尾添加以恢复默认行为.
这是一个例子:
SQL> set define off; SQL> select * from dual where dummy='&var'; no rows selected SQL> set define on SQL> / Enter value for var: X old 1: select * from dual where dummy='&var' new 1: select * from dual where dummy='X' D - X
使用时set define off
,它会占用一行&var
值,提示用户为其输入值并替换&var
为输入的值(在本例中为X
).