Thursday, April 17, 2014

Insert into table row data with '&' sign

Inserting into table is pretty straight forward, however a scenario to note would be if you need to enter '&' as a character in your table row.

"&" has a special meaning (substitution variable) in oracle database. While using sqlplus if you use that to enter  into a field, it will prompt you to enter a value in that field, to avoid this we user "set define off;"

SQL> insert into testd values (4, 'Maths & Science', 444);
Enter value for science:                                 <<<<< we notice it is prompting us to substitute a value

-- so we define substitution off as follows >>> 
SQL> set define off;
SQL> insert into testd values (4, 'Maths & Science', 444);
1 row created.
SQL> commit;
Commit complete.

SQL> select  * from testd;

    DEPTID DEPTNAME                                            FACULTYID
---------- -------------------------------------------------- ----------
         4 Maths & Science                                           444

No comments:

Post a Comment