Skip to main content

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

Comments

Popular posts from this blog

Using App Icons In Oracle Apex (Part1)

 Recently with the introduction of Apex 4.2 and later Apex 4.2.1 the default published  packaged applications comes with a sleek logo just at the left-hand corner of the the login screen. Fig 1 Fig 2 Fig 3 If u want to use these cool  sprites that come with the later releases as said in the the former. From the above diagram, looking into the css  inside the  i / or anywhere that your images are stored navigate to the cloud/app_theme/css/4_1.css You would find the img.appIcon.  class  which houses all the sprite launchpad logos in the Fig 1 Inside the css, locate ------App Icons Image-- img.appIcon.project_tracking{background-position:-256px 0}img.appIcon.solar{background-position:-320px 0}img.appIcon.website{background-position:-384px 0}img.appIcon.apex_service{background-position:-448px 0}img.appIcon.solar_red{background-position:-512px 0}img.appIcon.sales{background-position:-576px 0}img.appIcon.data_modeler{background-position:0 -64px}img.appIcon.group_calen

Disabling of Password Expiration in Oracle Apex(Internal Workspace Admin)

This post was inspired by a  question  on the OTN APEX forum, which contains how to  reset set the password of the  Oracle Internal Workspace Admin    and  Set the account never to expire  The first bullet has so many blogs  talk about how to reset the password of the Internal Workspace. However, i am more intrigued with the second . To start of with It is not advisable to never expire accounts since its rudimental for user to always renew their accounts  prior to expiration. The default expiration of an account is mostly 180 days so hey whats the point going to do this again after 180 days?? . There are two methods that can be used to achieve this  Generic Never expiration of all User accounts (This should never be practiced in a production Environment All database users are assigned to something called a PROFILE . The profile controls two aspects of the users database access – the system resources available to the user and th

How does one add a day/hour/minute/second to a date value?

DATE is the datatype that we are all familiar  with when we think about representing date and time values. It has the ability to store the month, day, year, century, hours, minutes, and seconds. It is typically good for representing data for when something has happened or should happen in the future.  The problem with the DATE datatype is its' granularity  when trying to determine a time interval between two events when the events happen within a second of each other. This issue is solved with the TIMESTAMP datatype. In order to represent the date stored in a more readable format, the TO_CHAR function has traditionally been wrapped around the date: SQL> SELECT  TO_CHAR(hiredate,'DD.MM.YYYY:HH24:MI:SS')  "hiredate"   FROM employees; hiredate ------------------- 17.12.1980:00:00:00 20.02.1981:00:00:00 The SYSDATE pseudo-column shows the current system date and time. Adding 1 to SYSDATE will advance the date by 1 day. Use fractions to add hours, minut