Home » RDBMS Server » Server Administration » How to Create a Stored Procedure
How to Create a Stored Procedure [message #371596] Fri, 10 November 2000 13:33 Go to next message
Sussette Blasa
Messages: 2
Registered: November 2000
Junior Member
Hi, I've been trying to find the correct way to create a stored procedure in Oracle. I just want it to output from this Select statement:

SELECT state_id, state_name
FROM state;

How would you call the procedure to get its output?
Also, if anyone can point me to a good Oracle book that has this info, I'd appreciate that, too.

thanks,

--Sussette
Re: How to Create a Stored Procedure [message #371598 is a reply to message #371596] Sat, 11 November 2000 13:42 Go to previous messageGo to next message
Babu Paul
Messages: 38
Registered: November 2000
Member
Hi!
The best book will be ORACLE PL/SQL.
Okay, to create a stored procedure. You should have your code look something like this.

CREATE OR REPLACE PROCEDURE procedure_name(parameters)
AS
--- Declarations (local variables)
BEGIN
--- PL/SQL statements
EXCEPTION
END ;
/

Example;

CREATE OR REPLACE PROCEDURE proc_get_state_info
AS

CURSOR c1
IS
SELECT state_id
,state_name
FROM state ;

v_state_id state.state_id%TYPE ;
v_state_name state.state_name%TYPE ;

BEGIN

DBMS_OUTPUT.PUT_LINE ('State ID' || ' ' || 'State Name') ;
DBMS_OUTPUT.PUT_LINE('-------------------------');
OPEN c1 ;
LOOP

FETCH c1 INTO v_state_id
,v_state_name ;
EXIT WHEN c1%NOTFOUND ;

DBMS_OUTPUT.PUT_LINE(v_state_id || ' ' || v_state_name) ;

END LOOP ;
CLOSE c1 ;
EXCEPTION

WHEN others THEN

DBMS_OUTPUT.PUT_LINE(SQLCODE||'-'||SQLERRM) ;

END proc_get_state_info ;
/

After Compiling...without errors

You have to either call this procedure from the SQL prompt or write a PL/SQL script...

SQL> set serveroutput on
SQL> exec proc_get_state_info

Hope this helps!

Good Luck!
Babu
Re: How to Create a Stored Procedure [message #371614 is a reply to message #371596] Tue, 14 November 2000 17:26 Go to previous messageGo to next message
Sussette Blasa
Messages: 2
Registered: November 2000
Junior Member
Thanks, Babu, that worked great! I will check out the Oracle PL/SQL book for more info.

--Sussette
Re: How to Create a Stored Procedure [message #371658 is a reply to message #371596] Mon, 20 November 2000 21:54 Go to previous messageGo to next message
brendan
Messages: 9
Registered: November 2000
Junior Member
Once you have saved the stored procedure, how do you go back later and view it? (in sqlplus)
Re: How to Create a Stored Procedure [message #371659 is a reply to message #371596] Mon, 20 November 2000 21:55 Go to previous messageGo to next message
brendan
Messages: 9
Registered: November 2000
Junior Member
Once you have saved the stored procedure, how do you go back later and view it? (in sqlplus)
Re: How to Create a Stored Procedure [message #371660 is a reply to message #371596] Mon, 20 November 2000 21:56 Go to previous messageGo to next message
brendan
Messages: 9
Registered: November 2000
Junior Member
Once you have saved the stored procedure, how do you go back later and view it? (in sqlplus)
Re: How to Create a Stored Procedure [message #371664 is a reply to message #371596] Tue, 21 November 2000 03:37 Go to previous message
Babu Paul
Messages: 38
Registered: November 2000
Member
Hi,

Whenever we create a stored procedure or function or package, it resides in all_source table and user_source table. You can give a query to see your procedure that is compiled.

SELECT text FROM all_source where
name = upper('your procedure name') ;

Try this one!

Good Luck!
Babu
Previous Topic: Expertise needed on triggers
Next Topic: Cursor when not found.
Goto Forum:
  


Current Time: Sat May 04 03:13:31 CDT 2024