Inserting values into a table with '&'

I often say "I learn something new about Oracle every day".  It really is true - there is so much to know about it, it is hard to keep up sometimes.
It is a  little sqlplus quirk that I probably knew at one point but totally forgot.  People run into problems with &'s in sqlplus all of the time as sqlplus tries to substitute in for an &variable.  So, if they try to select '&hello world' from dual - they'll get:
SQL> select '&hello world' from dual;
Enter value for hello: 
old   1: select '&hello world' from dual
new   1: select ' world' from dual


'WORLD
------
 world


As the result.
One solution is to "set define off" to disable the substitution (or set define to some other character).  Another oft quoted solution is to use chr(38) - 
SQL> select chr(38)||'hello world' from dual;
  I never liked that one personally. lol :)  
What i suggest is this 
SQL> select '&' || 'hello world' from dual;



'&'||'HELLOW
------------
&hello world
SQL>

Well just concatenate '&' to the string, sqlplus doesn't touch that one!  I like that better than chr(38) (but a little less than set define off....) ... there u have it. Smile
Benjamin Intsiful

I live on Ice Tea, an Apex gourmet and web development fanatic

Post a Comment

Previous Post Next Post