Oracle FAQ | Your Portal to the Oracle Knowledge Grid |
Home -> Community -> Usenet -> c.d.o.server -> Re: Simple Create Procedure Problem..
"Howard J. Rogers" <hjr_at_dizwell.com> wrote in message
news:41ac53a3$0$17542$afc38c87_at_news.optusnet.com.au...
| Mark C. Stock wrote:
| > "Howard J. Rogers" <hjr_at_dizwell.com> wrote in message
| > news:41ac00bc$0$17542$afc38c87_at_news.optusnet.com.au...
| > | Arijit Chatterjee wrote:
| > | > RESPECTED FACULTIES,
| > | > I AM TRYING TO WRITE A PROCEDURE CODE IS GIVEN BELOW
| > | > ===========================================
| > | > CREATE PROCEDURE PROC(ACCNO IN NUMBER)
| > | > AS
| > | > BEGIN
| > | > SELECT * FROM ACCOUNTMASTER WHERE ACCOUNTCODE=ACCNO;
| > | > END;
| > | > ============================================
| > | > aND I AM GETTING THE ERROR
| > | >
| > | > --------------------------------------------
| > | > Warning: Procedure created with compilation errors.
| > | > --------------------------------------------
| > | > I HAVE CONNECTED WITH SCOTT/TIGER AND SCOTT HAS GIVEN THE
| > | > PRIVILEGES TO CREATE PROCEDURE.
| > | >
| > | > NOW WHAT SHOULD BE THE REASON FOR THIS ERROR?
| > | >
| > | > REGARDS
| > | > ARIJIT CHATTERJEE
| > |
| > |
| > | How about learning how to type "show errors" when you receive that
| > message?
| > |
| > | If you did, maybe you'd see something like this:
| > |
| > | SQL> create procedure proc (accno in number)
| > | 2 as
| > | 3 begin
| > | 4 select * from emp where empno=accno;
| > | 5 end;
| > | 6 /
| > |
| > | Warning: Procedure created with compilation errors.
| > |
| > | SQL> show errors
| > | Errors for PROCEDURE PROC:
| > |
| > | LINE/COL ERROR
| >
| -------- -----------------------------------------------------------------
| > | 4/1 PLS-00428: an INTO clause is expected in this SELECT
statement
| > |
| > | Which kind of gives you the clue as to where the error lies. And one
| > | possible solution would be:
| > |
| > | SQL> create or replace procedure proc (accno in number)
| > | 2 as
| > | 3 begin
| > | 4 execute immediate 'select * from emp where empno=' || accno;
| > | 5 end;
| > | 6 /
| > |
| > | Procedure created.
| > |
| > |
| > | But this is extremely basic stuff, so you'd best start reading up on
how
| > | to write PL/SQL.
| > |
| > | Regards
| > | HJR
| >
| > slow down, howard....
|
|
|
|
|
|
|
|| > end;
| > create or replace procedure proc (accno in number)
| > as
| > r_emp emp%rowtype;
| > begin
| > select *
| > into r_emp
| > from emp where empno = accno;
| >
| > -- then do something with r_emp
| |
|
|
|
|
|
| |
wow! that was unexpected!
'slow down' was meant as nothing more than a friendly, 'hey, don't forget', or whatever you would normally interpret as a non-confrontational additional comment
i am truly sorry that it was taken as an affront -- that was certainly not my intent. based on the content of all your other posts and publications, i simply assumed you had overlooked something that you were well aware of.
however, since you apparently are of a different opinion on the technical issues, let me elaborate a little
i stand by the statement that execute immediate is unnecessary, as there is no dynamic sql involved here. if i'm not mistaken, execute immediate also causes additional parses (so i recall from my recent readings, i've not done tests to empirically prove this). i would not want any of my students, readers, or developers to get in the habit of using execute immediate for non-dynamic sql.
providing the OP with an example that lacks a basic and typical element, like the into clause, can be, i believe, misleading -- especially to a newbie. yes, the code does compile, but it does not accomplish anything -- and it is not a stretch to assume that if a select statement is being issued, then the point is to have access to the results.
borrowing from the 'teach a man to fish' illustration -- if someone asks me how to put the worm on the hook and he's standing there with just a pole and a hook, i would think it appropriate to remind him not to forget to connect the hook to the pole with a bit of fishing line.
sorry again for my poor choice of words -- your posts are always valued, and i certainly welcome any corrections or challenges you care to provide for my posts.
++ mcs Received on Tue Nov 30 2004 - 05:57:54 CST