Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

oracle

sqlplus

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" ("id","right") values ('1','R'); 

I'm looking for documentation about "set define off" and it's literally writing "disable the parsing of commands to replace substitution variable with their values"

I don't really understand what they want to say.

Can anyone help me?

like image 1000
Enrique Benito Casado Avatar asked Dec 17 '15 10:12

Enrique Benito Casado


People also ask

What is the use of set define off?

Synopsis. The SET DEFINE command changes the prefix character used to mark substitution variables. You can use SET DEFINE to turn variable substitution off.

What is set define off in Oracle procedure?

"set define off" is a sql*plus command. You should call it before calling the stored procedure, not within the procedure. Show the details, How the procedure looks like, How you are calling the procedure and from where (which client), and what is the exact problem you are facing.

What is set define off in SQL Developer?

Either use SET DEFINE OFF or escape the ampersand when you use it and don't want it interpreted. You can use connection script - that is, an SQL script that will be executed on logon for each connection.

What is set feedback off in Oracle?

Setting feedback to zero is equivalent to turning it OFF. SET FEEDBACK OFF also turns off the statement confirmation messages such as 'Table created' and 'PL/SQL procedure successfully completed' that are displayed after successful SQL or PL/SQL statements.>


2 Answers

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.

like image 91
Tony Andrews Avatar answered Sep 30 '22 20:09

Tony Andrews


Here is the example:

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 

With set define off, it took a row with &var value, prompted a user to enter a value for it and replaced &var with the entered value (in this case, X).

like image 39
Durga Viswanath Gadiraju Avatar answered Sep 30 '22 20:09

Durga Viswanath Gadiraju