If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > Oracle > Stored Procedure Error

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 07-21-03, 17:44
JCScoobyRS JCScoobyRS is offline
Registered User
 
Join Date: Feb 2003
Location: In your thoughts
Posts: 195
Stored Procedure Error

Here is my code to create an SP:

Code:
CREATE OR REPLACE PROCEDURE attendance
  (sdate IN DATE,
   edate IN DATE)
AS
BEGIN
  SELECT ALL EM.EM_KEY, EM.EM_DPKEY, EM.EM_TMKEY, EM.EM_LAST_NAME,
  EM.EM_FIRST_NAME, ATX.ATX_CLOCK_IN, ATX.ATX_CLOCK_OUT, ATX.ATX_DATE
  FROM ATX, EM
  WHERE (ATX.ATX_EMKEY = EM.EM_KEY) AND ATX.ATX_DATE BETWEEN TO_CHAR(sdate) AND TO_CHAR(edate) ORDER BY ATX.ATX_DATE, EM.EM_LAST_NAME;
END attendance;
/
SHOW ERRORS
Now, I get these errors when ran:

Code:
Warning: Procedure created with compilation errors.

Errors for PROCEDURE ATTENDANCE:

LINE/COL ERROR
-------- -----------------------------------------------------------------
6/3      PLS-00428: an INTO clause is expected in this SELECT statement
6/3      PL/SQL: SQL Statement ignored
Can someone see where I'm going wrong? Thanks, Jeremy
__________________
Nothing better than a good ride.
Reply With Quote
  #2 (permalink)  
Old 07-21-03, 17:51
LKBrwn_DBA LKBrwn_DBA is offline
Registered User
 
Join Date: Jun 2003
Location: West Palm Beach, FL
Posts: 2,456
Cool

<QUOTE>
-----------------------------------------------------------------
6/3 PLS-00428: an INTO clause is expected in this SELECT statement
</QUOTE>

Oracle is trying to tell you that you have not defined any variables to receive the results of the query.

A 'select' statement inside a procedure requires variables defined in order to receive and be able to manipulate the results of the query.

You have to write the query as:

SELECT COLS,... INTO VARS... FROM ....
Reply With Quote
  #3 (permalink)  
Old 07-21-03, 17:54
JCScoobyRS JCScoobyRS is offline
Registered User
 
Join Date: Feb 2003
Location: In your thoughts
Posts: 195
Can you help me out? I thought I did that in my declare block but must had been mistaken. If I were to run the query by itself, and replaced "sdate" and "edate" with dates, it works properly. Thanks, Jermey
__________________
Nothing better than a good ride.
Reply With Quote
  #4 (permalink)  
Old 07-21-03, 17:57
The_Duck The_Duck is offline
Registered User
 
Join Date: Jul 2003
Posts: 2,292
aren't you passing in the dates from outside??

PHP Code:
CREATE OR REPLACE PROCEDURE attendance
     
(sdate IN DATE,
      
edate IN DATE)

      
cursor data_cursor is
SELECT 
        EM
.EM_KEY
        
EM.EM_DPKEY
        
EM.EM_TMKEY
        
EM.EM_LAST_NAME,
        
EM.EM_FIRST_NAME
        
ATX.ATX_CLOCK_IN
        
ATX.ATX_CLOCK_OUT
        
ATX.ATX_DATE
  FROM 
        ATX

        
EM
  WHERE 
       
(ATX.ATX_EMKEY EM.EM_KEY) AND 
        
ATX.ATX_DATE BETWEEN 
          sdate 
AND edate 
  ORDER BY 
        ATX
.ATX_DATE
        
EM.EM_LAST_NAME;

AS
BEGIN
  
for v_data IN data_cursor 
      loop
        
(updateinsert or whatever stuff you want to do)
      
end loop;

END;

Personally, I normally convert dates to character strings when they come in and manipulate then.

if the between gives you errors use the to_date function.
Also, you never say what you want to do with the data.
__________________
- The_Duck
you can lead someone to something but they will never learn anything ...

Last edited by The_Duck; 07-21-03 at 18:06.
Reply With Quote
  #5 (permalink)  
Old 07-21-03, 18:01
JCScoobyRS JCScoobyRS is offline
Registered User
 
Join Date: Feb 2003
Location: In your thoughts
Posts: 195
Duck...Same error as before. Got any ideas? Thanks, Jeremy
__________________
Nothing better than a good ride.
Reply With Quote
  #6 (permalink)  
Old 07-21-03, 18:09
The_Duck The_Duck is offline
Registered User
 
Join Date: Jul 2003
Posts: 2,292
I edited my code above.
state what you are trying to do.

Are you passing in the 2 date variables? I am guessing yes.

What do you want to do with your output?

Throw it in a new table? send it back out the proc?
__________________
- The_Duck
you can lead someone to something but they will never learn anything ...
Reply With Quote
  #7 (permalink)  
Old 07-21-03, 18:38
JCScoobyRS JCScoobyRS is offline
Registered User
 
Join Date: Feb 2003
Location: In your thoughts
Posts: 195
Well...I'm a developer and I was told I could create a Crystal Report from data coming from a Stored Procedure. All I need to do is create a procedure that will take my two variables, sdate and edate, and run a query and output to the screen as any other query. Can you help? Thanks, Jeremy
__________________
Nothing better than a good ride.
Reply With Quote
  #8 (permalink)  
Old 07-21-03, 18:58
The_Duck The_Duck is offline
Registered User
 
Join Date: Jul 2003
Posts: 2,292
sounds good to me.

You need to throw your output into variables.

Try this:

PHP Code:
CREATE OR REPLACE PROCEDURE attendance
  
(     sdate IN DATE,
        
edate IN DATE,
        
V_EM_KEY OUT varchar2
        
V_EM_DPKEY OUT varchar2
        
V_EM_TMKEY OUT varchar2
        
V_EM_LAST_NAME OUT varchar2,
        
V_EM_FIRST_NAME OUT varchar2
        
V_ATX_CLOCK_IN OUT varchar2
        
V_ATX_CLOCK_OUT OUT varchar2
        
V_ATX_DATE  OUT varchar2
   
)
AS
BEGIN
  SELECT 
        EM
.EM_KEY
        
EM.EM_DPKEY
        
EM.EM_TMKEY
        
EM.EM_LAST_NAME,
        
EM.EM_FIRST_NAME
        
ATX.ATX_CLOCK_IN
        
ATX.ATX_CLOCK_OUT
        
ATX.ATX_DATE
  INTO
        V_EM_KEY

        
V_EM_DPKEY
        
V_EM_TMKEY
        
V_EM_LAST_NAME,
        
V_EM_FIRST_NAME
        
V_ATX_CLOCK_IN
        
V_ATX_CLOCK_OUT
        
V_ATX_DATE
  FROM 
        ATX

        
EM
  WHERE 
       
(ATX.ATX_EMKEY EM.EM_KEY) AND 
        
ATX.ATX_DATE BETWEEN 
            sdate 
AND edate 
  ORDER BY 
        ATX
.ATX_DATE
        
EM.EM_LAST_NAME;

END;

__________________
- The_Duck
you can lead someone to something but they will never learn anything ...
Reply With Quote
  #9 (permalink)  
Old 07-21-03, 19:04
aruneeshsalhotr aruneeshsalhotr is offline
Registered User
 
Join Date: Jul 2003
Location: US
Posts: 314
Re: Stored Procedure Error

Hi
The way the stored procedures work in case of select statement, is that you specify into clause, which have the local variables names declared in the DECLARE section.
Hope that helps.
Thanx and Regards
Aruneesh

Quote:
Originally posted by JCScoobyRS
Here is my code to create an SP:

Code:
CREATE OR REPLACE PROCEDURE attendance
  (sdate IN DATE,
   edate IN DATE)
AS
BEGIN
  SELECT ALL EM.EM_KEY, EM.EM_DPKEY, EM.EM_TMKEY, EM.EM_LAST_NAME,
  EM.EM_FIRST_NAME, ATX.ATX_CLOCK_IN, ATX.ATX_CLOCK_OUT, ATX.ATX_DATE
  FROM ATX, EM
  WHERE (ATX.ATX_EMKEY = EM.EM_KEY) AND ATX.ATX_DATE BETWEEN TO_CHAR(sdate) AND TO_CHAR(edate) ORDER BY ATX.ATX_DATE, EM.EM_LAST_NAME;
END attendance;
/
SHOW ERRORS
Now, I get these errors when ran:

Code:
Warning: Procedure created with compilation errors.

Errors for PROCEDURE ATTENDANCE:

LINE/COL ERROR
-------- -----------------------------------------------------------------
6/3      PLS-00428: an INTO clause is expected in this SELECT statement
6/3      PL/SQL: SQL Statement ignored
Can someone see where I'm going wrong? Thanks, Jeremy
Reply With Quote
  #10 (permalink)  
Old 07-21-03, 19:12
JCScoobyRS JCScoobyRS is offline
Registered User
 
Join Date: Feb 2003
Location: In your thoughts
Posts: 195
Quote:
Originally posted by The_Duck
sounds good to me.

You need to throw your output into variables.

Try this:

PHP Code:
CREATE OR REPLACE PROCEDURE attendance
  
(     sdate IN DATE,
        
edate IN DATE,
        
V_EM_KEY OUT varchar2
        
V_EM_DPKEY OUT varchar2
        
V_EM_TMKEY OUT varchar2
        
V_EM_LAST_NAME OUT varchar2,
        
V_EM_FIRST_NAME OUT varchar2
        
V_ATX_CLOCK_IN OUT varchar2
        
V_ATX_CLOCK_OUT OUT varchar2
        
V_ATX_DATE  OUT varchar2
   
)
AS
BEGIN
  SELECT 
        EM
.EM_KEY
        
EM.EM_DPKEY
        
EM.EM_TMKEY
        
EM.EM_LAST_NAME,
        
EM.EM_FIRST_NAME
        
ATX.ATX_CLOCK_IN
        
ATX.ATX_CLOCK_OUT
        
ATX.ATX_DATE
  INTO
        V_EM_KEY

        
V_EM_DPKEY
        
V_EM_TMKEY
        
V_EM_LAST_NAME,
        
V_EM_FIRST_NAME
        
V_ATX_CLOCK_IN
        
V_ATX_CLOCK_OUT
        
V_ATX_DATE
  FROM 
        ATX

        
EM
  WHERE 
       
(ATX.ATX_EMKEY EM.EM_KEY) AND 
        
ATX.ATX_DATE BETWEEN 
            sdate 
AND edate 
  ORDER BY 
        ATX
.ATX_DATE
        
EM.EM_LAST_NAME;

END;

This may sound dumb but how do I call it then? I have tried:

PHP Code:
EXEC attendance('01-JUL-2003','15-JUL-2003'
And I get the following error:

PHP Code:
BEGIN attendance('01-JUL-2003','15-JUL-2003'); END;

      *
ERROR at line 1:
ORA-06550line 1column 7:
PLS-00306wrong number or types of arguments in call to 'ATTENDANCE'
ORA-06550line 1column 7:
PL/SQLStatement ignored 
Thanks, Jeremy
__________________
Nothing better than a good ride.
Reply With Quote
  #11 (permalink)  
Old 07-21-03, 21:03
billm billm is offline
Drunkard
 
Join Date: Nov 2002
Location: Desk, slightly south of keyboard
Posts: 697
If you're trying to get the data out to crystal, you need to use a REF CURSOR.

Ie (in a package spec)

TYPE CurType is REF CURSOR;

in a function in the package

PROCEDURE Fred( Parm1 IN DATE, Parm2 IN DATE, curResults OUT CurType ) IS
BEGIn
OPEN curResult FOR SELECT ....
END;

In crystal...
BEGIN
MyPackage.Fred( date1, date2, cursortype );
END;

Google for "package ref cursor" for fuller syntax/details.

Hth
Bill
Reply With Quote
  #12 (permalink)  
Old 07-22-03, 11:37
The_Duck The_Duck is offline
Registered User
 
Join Date: Jul 2003
Posts: 2,292
Do what Bill said.
I hate Crystal reports.


I thought Crystal does all this for you at the GUI level as you build the report?
__________________
- The_Duck
you can lead someone to something but they will never learn anything ...
Reply With Quote
  #13 (permalink)  
Old 07-22-03, 11:42
JCScoobyRS JCScoobyRS is offline
Registered User
 
Join Date: Feb 2003
Location: In your thoughts
Posts: 195
I will but isn't there a way to query the sp we created and get data back instead of that error? Thanks, Jeremy
__________________
Nothing better than a good ride.
Reply With Quote
  #14 (permalink)  
Old 07-22-03, 11:44
JCScoobyRS JCScoobyRS is offline
Registered User
 
Join Date: Feb 2003
Location: In your thoughts
Posts: 195
My point here is that I'm learning and I was told that a stored procedure could benefit me in this situation because it allows me to run a query with variables that would be passed when calling the stored procedure. This sp would be ran from an application that I'm writing and it would be easiest if I could do something like:

PHP Code:
EXEC attendance('01-JUL-2003','15-JUL-2003'
and have results returned. Thanks, Jeremy
__________________
Nothing better than a good ride.
Reply With Quote
  #15 (permalink)  
Old 07-22-03, 11:59
The_Duck The_Duck is offline
Registered User
 
Join Date: Jul 2003
Posts: 2,292
Quote:
Originally posted by JCScoobyRS
I will but isn't there a way to query the sp we created and get data back instead of that error? Thanks, Jeremy
yes there is.
If you use my code you could then do a DBMS_OUTPUT.put line

set serveroutput on

throw this line into your proc after the select statement, like this:
PHP Code:
dbms_output.put_line ('data  -->  '|| V_EM_KEY||'   '||V_EM_DPKEY||'   '||V_EM_TMKEY||'   '||V_EM_LAST_NAME||'   '||        V_EM_FIRST_NAME||'   '|| V_ATX_CLOCK_IN||'   '|| V_ATX_CLOCK_OUT||'   '||V_ATX_DATE); 
Otherwise you could add error-handling to your SP.
__________________
- The_Duck
you can lead someone to something but they will never learn anything ...
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On