Skip to Main Content
  • Questions
  • Quick Question for Oracle Set define off query

Breadcrumb

Question and Answer

Chris Saxon

Thanks for the question, Muhammad.

Asked: December 12, 2018 - 9:35 am UTC

Last updated: December 12, 2018 - 2:33 pm UTC

Version: 11g

Viewed 10K+ times! This question is

You Asked

Hi All,

I just want to know that if i turned off the feature i.e. "SET DEFINE OFF" from my oracle database, will there by any consequences / disadvantages with my data or database, as i really need to turn it off for some queries.

Please advise if it will not break anything.

and Chris said...

Define is a SQL*Plus client variable. It is NOT a database level setting.

Setting this to ON instructs SQL*Plus to look for substitution variables in your code. These are variables prefixed by an ampersand (&).

If there are any, the client will stop and ask you to supply a value for the variable. At which point it'll change your code to include this text.

The problem comes if you have & buried in some text somewhere. e.g. say you're inserting:

Tom & Jerry

When SQL*Plus comes to process this, it'll ask you what to replace the variable Jerry with. And insert that instead:

SQL> create table t (
  2    c1 varchar2(20)
  3  );

Table created.

SQL>
SQL> set define off
SQL> insert into t values ( 'Tom & Jerry' );

1 row created.

SQL>
SQL> set define on
SQL> insert into t values ( 'Tom & Jerry' );
Enter value for jerry: mouse
old   1: insert into t values ( 'Tom & Jerry' )
new   1: insert into t values ( 'Tom mouse' )

1 row created.

SQL> select * from t;

C1
--------------------
Tom & Jerry
Tom mouse


So unless you know your script includes these variables, it's best to set define off. This avoids unexpected changes to your data & code!

Is this answer out of date? If it is, please let us know via a Comment