views:

411

answers:

1

I am looking for good resources on Oracle Stored Procedure geared towards beginners. I tried the Dev Shed Article and one from Oracle Documentation site but they did not meet my needs. The one form Oracle Documentation site had the overhead of Java example. I tried the Dev Shed one but I keep getting invalid SQL error when I try their example. Here is the basic one that I tried to run:

CREATE OR REPLACE PROCEDURE skeleton
IS
BEGIN
 NULL;
END;

EXECUTE skeleton;

Am I making a rookie mistake or is the syntax in the article out of date? I am working with Oracle 10g & PL/SQL Developer.

Thanks!

SOLUTION:

As per @curtisk's suggestion, I tried a slightly more involved example:

CREATE OR REPLACE PROCEDURE p_getdate
IS
BEGIN
 dbms_output.put_line(TO_CHAR
    (SYSDATE, 'MM-DD-YYYY HH24:MI:SS'));
END;

When I tried to execute it like so:

EXECUTE p_getdate

I got ORA-00900: Invalid SQL statement error. I looked for why this would be the case & stumbled across this thread. I decided to give call a try so I tried the following:

CALL p_getdate;

but that did not work as well. I read the thread some more & skeptically tried:

CALL p_getdate();

and voila, I had the procedure being called properly. I do not have an answer as to why this works but the fact that it works allows me to move forward with my project. If there is anyone who can explain to me why this is, I would love to learn more on this.

Thanks once again to @curtisk for the help!

A: 

I wouldn't use that example as a starting point...I'd make it do something here's one to try

CREATE OR REPLACE PROCEDURE p_getdate
IS
BEGIN
 dbms_output.put_line(TO_CHAR
    (SYSDATE, 'MM-DD-YYYY HH24:MI:SS'));
END;

Run that, it should compile successfully, then at the prompt....

SQL> SET SERVEROUT ON;
SQL> execute p_getdate;
 06-11-2009 12:29:54

You should see the current date/time in the output. The example you used was too simple IMHO. Next step is to create a procedure that deals with declarations and parameters.

As far as beginner resources, there's a ton out there can't really recommend any one in particular, and if nothing there's always "Ask Tom"..should be some Q/A there that may help

curtisk
Thanks for the response. I tried running the getdate. There is no problem creating the procedure but when I try to execute, I get invalid sql statement in PL/SQL Developer. Here is what I am running:EXECUTE p_getdate;
tundal45
tundal45