Click here to Skip to main content
Click here to Skip to main content

Oracle SQL*Plus – Forward Slash contd…

, 27 Dec 2013
Rate this:
Please Sign up or sign in to vote.
Forward Slash contd…

Recently while working with a coworker I saw trouble with using Forward slash, first hand. He was running some old scripts. The original developer probably ran these in some other tool (typically other tools are more pardoning than SQL*Plus.

One of the scripts had DDLs and had some code commented out. Incidentally, the original developer used C-Style comments (those in between /* … */). And inadvertently, he created a Forward slash problem!!!!

I am including a very simple script below to illustrate this:

create table t (c VARCHAR2(30));
/* drop table t;
*/
In the above SQL, there is a DDL on the first line that creates a new table. Second line has, the C-Style comment. Developer essentially commented the Drop statement, with /*. Here is the output in SQL*Plus:
SQL> create table t (c VARCHAR2(30));
/* drop table t;
*/
create table t (c VARCHAR2(30))
*
ERROR at line 1:
ORA-00955: name is already used by an existing object

No way!!!! How come?? Well, you guessed it! It’s because of a Forward slash (/), the developer left in the second line of the script. He only wanted to comment out the Drop Table Statement, but SQL*Plus took the Forward Slash ("/") as the RUN command. It tried to execute the previously executed statement (create table) again, when it saw /* on the second line, and thus the Error! Now, you wouldn't have seen this error if the Create Table statement was not terminated with semi-colon(;)!

Funnily, this doesn’t happen in a DML nor in a PL/SQL block. So, if your scripts have DDLs beware of Forward slashes in any shape or form!!! Above error could be avoided, by always commenting with SQL style comments, starting with "--".

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

About the Author

Sam Varadarajan
Software Developer (Senior) City of Los Angeles
United States United States
Originally a Physics major, fell in love with Microprocessors and switched to Computer Science 20+ years ago. Since then, dabbled in various languages including, PowerBuilder, Oracle, Java, C, C++, Perl, Python etc. Constantly striving for quality and performance too.
 
I try to help fellow developers with technology as a way of "giving back to the community". Blogging became a natural extension of that effort. Still learning to perfect that art. If one new programmer out there benefits from this blog, my time and effort are fully worth it.
 
The underlying theme in my blogs is power and beauty of programming (and technology in general). A well written program gives me the sense of awe you get when you look at a man made wonder like Angkor Wat. You experience poetry, art, mystique, power all at once. A program and the troubleshooting that ensues also gives you a feeling you get while reading a mystery novel!
Follow on   Twitter   Google+   LinkedIn

Comments and Discussions

 
-- There are no messages in this forum --
| Advertise | Privacy | Mobile
Web01 | 2.8.140709.1 | Last Updated 27 Dec 2013
Article Copyright 2013 by Sam Varadarajan
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid