When or Why to use a “SET DEFINE OFF” in Oracle Database

前端 未结 2 582
后悔当初
后悔当初 2020-12-02 17:52

I\'m watching a Script in Oracle and I see something I don\'t recognize

REM INSERTING into database1.\"Users\"
 SET DEFINE OFF;
Insert into database1.\"Users         


        
2条回答
  •  误落风尘
    2020-12-02 18:31

    By default, SQL Plus treats '&' as a special character that begins a substitution string. This can cause problems when running scripts that happen to include '&' for other reasons:

    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
    

    If you know your script includes (or may include) data containing '&' characters, and you do not want the substitution behaviour as above, then use set define off to switch off the behaviour while running the script:

    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
    

    You might want to add set define on at the end of the script to restore the default behaviour.

提交回复
热议问题