tags:

views:

147

answers:

5

I have a sql file that contains a simple procedure to print "Hi" like,

CREATE OR REPLACE PROCEDURE skeleton 
IS
BEGIN
  DBMS_OUTPUT.PUT_LINE('Hi');
END;

When I try to execute this from sql file itself, it just gets compiled and it is not running.

I added the as,

CREATE OR REPLACE PROCEDURE skeleton 
IS
BEGIN
  DBMS_OUTPUT.PUT_LINE('Hi');
END;
/ /* this is required else it throws me compilation error*/
set serveroutput on
EXECUTE skeleton;

I tried calling the same skeleton from other sql file also and even from the sqldeveloper GUI, that also didnt execute this. Only the sqlplus commandline helps me. Let me know what I am missing and the solution for this.

A: 
Colin Pickard
You are right about the "little green arrow in front of the document", but that is called "execute script".
Juergen Hartelt
Thank you! I've not got a copy of SQL developer on this machine, I was trying to remember exactly what is was called. I've updated my answer.
Colin Pickard
A: 

Try setting set serveroutput on before the dbms_output.

Xaisoft
I don't think that will work. `set serveroutput on` is not valid there. Also I don't think `set serveroutput on` is actually required anyway, at least for SQL Developer; it will be on anyway.
Colin Pickard
A: 

Hi, Thanks for your replies. But even though I have the EXECUTE command within it, but it is not running it when i call as @filename.sql. It just says Procedure compiled. How do I run it ?

Priya
What is your environment here? sqlplus? Does your script look like carpenteri suggested?`CREATE OR REPLACE PROCEDURE skeletonISBEGIN DBMS_OUTPUT.PUT_LINE('Hi');END;/set serveroutput onEXECUTE skeleton;`
Juergen Hartelt
+1  A: 

Here are the steps I took using SQL Plus

SQL> CREATE OR REPLACE PROCEDURE skeleton
  2  IS
  3  BEGIN
  4    DBMS_OUTPUT.PUT_LINE('Hi');
  5  END;
  6  /

Procedure created.

SQL> set serveroutput on
SQL> EXECUTE skeleton;
Hi

PL/SQL procedure successfully completed.

SQL>

Can you start a new sqlplus session replicate these steps and post the content?

carpenteri
He said he can already run it in an interactive sqlplus session, he was just stuck running it in SQL developer and from a file.
Colin Pickard
@Colin - My bad! Amazing what happens when you read the question more than once. Thanks
carpenteri
+1  A: 

Hi Priya,

The only change I had to make to your sql to allow running it as an @file was to remove the comment. This is the whole content of the the .sql file:

CREATE OR REPLACE PROCEDURE skeleton
IS
BEGIN
  DBMS_OUTPUT.PUT_LINE('Hi');
END;
/
set serveroutput on
EXECUTE skeleton;

You should get an output something like this:

C:\Temp>sqlplus username/password @skeleton.sql

SQL*Plus: Release 11.1.0.6.0 - Production on Mon Oct 5 17:10:46 2009

Copyright (c) 1982, 2007, Oracle.  All rights reserved.

Connected to:
Oracle Database 11g Enterprise Edition Release 11.1.0.6.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options

Procedure created.

Hi

PL/SQL procedure successfully completed.

SQL>
Colin Pickard