Solved

SqlPlus script fails to create objects

Posted on 2011-09-18
6
541 Views
Last Modified: 2012-05-12
New to Oracle and SqlPlus, I need to create a release script for an exising set of files for tables/views/functions/etc.  I'm finding that unlike Toad, when SqlPlus processes these files, the objects are not created if the file does not end with "/".  I can ask that all the files be corrected, but I thought there might be some SqlPlus option that handles this.  Is there any way around this in SqlPlus?
0
Comment
Question by:jkavx
6 Comments
 
LVL 23

Expert Comment

by:OP_Zaharin
ID: 36557883
- apart from using '/' you can put semicolon ';'at the end of each statement in your script to execute each of the sql statements.

- eg:
select * from o_table1;
create table table2 as select * from table1;
0
 

Author Comment

by:jkavx
ID: 36557948
These are ddl scripts.  One script per object - table, view, function, procedure.  The problem files end with ";" but without a final line with "/", the SqlPlus commands, although successful, don't actually create the object.
0
 
LVL 23

Expert Comment

by:OP_Zaharin
ID: 36558088
- i've done my test on the following script without having to use slash '/':
- my script contain:
CREATE TABLE "TEST"."TEST2"
   (      "LEGACYKEY" VARCHAR2(100),
      "CODE" VARCHAR2(10),
      "CODE2" VARCHAR2(10),
      "CODE3" VARCHAR2(10)
   );

- and i execute it this way:
SQL> @c:\temp\test2.sql;

Table created.

0
PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

 
LVL 23

Accepted Solution

by:
OP_Zaharin earned 500 total points
ID: 36558089
- kindly note also that if you are executing pl/sq block, you need to use slash '/' as mention in the Oracle doc:

"You must include a semicolon at the end of each SQL command and a slash (/) on a line by itself after each PL/SQL block in the file. You can include multiple SQL commands and PL/SQL blocks in a script"
http://download.oracle.com/docs/cd/B14117_01/server.101/b12170/ch6.htm
0
 
LVL 6

Expert Comment

by:tangchunfeng
ID: 36558289
$ cat a.sql
select count(*) from dual
/
exit

$ sqlplus scott/tiger @a.sql


  COUNT(*)
----------
         1

This works.
0
 
LVL 76

Expert Comment

by:slightwv (䄆 Netminder)
ID: 36559675
Check for blank lines.

The semi-colon (';') MUST be at the end of the command immediately on the next line.

The slash ('/') tells sqlplus to run whatever comment is current in the buffer.  With only one command per script a blank line after the command will store the script in the command buffer and a '/' will execute it later.

I don't like this idea since each script should be able to execute by itself but since you asked it there was a way around it:  If you have some master script that calls them individually you can always add the '/' in the master script after the individual ones.

master.sql
-------
@file1
/

@file2
/

etc...
0

Featured Post

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Cursors in Oracle: A cursor is used to process individual rows returned by database system for a query. In oracle every SQL statement executed by the oracle server has a private area. This area contains information about the SQL statement and the…
FreeBSD on EC2 FreeBSD (https://www.freebsd.org) is a robust Unix-like operating system that has been around for many years. FreeBSD is available on Amazon EC2 through Amazon Machine Images (AMIs) provided by FreeBSD developer and security office…
Via a live example, show how to restore a database from backup after a simulated disk failure using RMAN.
This video shows how to configure and send email from and Oracle database using both UTL_SMTP and UTL_MAIL, as well as comparing UTL_SMTP to a manual SMTP conversation with a mail server.

777 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question