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 > Data Access, Manipulation & Batch Languages > ANSI SQL > Newbie Procedure Problem

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 10-15-03, 10:12
donnie_darko donnie_darko is offline
Registered User
 
Join Date: Oct 2003
Location: England
Posts: 15
Newbie Procedure Problem

Hi there, I'm new to PL/SQL and have been given the following procedure:

create or replace procedure otime (hoursworked number) as
overtimehours number;
normalhours number;
message varchar2(30);
begin
normalhours := 35;
if hoursworked > normalhours then
overtimehours := hoursworked - normalhours;
message := 'Overtime Hours worked = ';
dbms_output.put_line(message);
dbms_output.put_line(overtimehours);
else
message := 'No Overtime!';
dbms_output.put_line(message);
end if;
end;

it compiles OK, but when I enter the command 'EXECUTE otime', I get he following error:

BEGIN otime; END;

*
ERROR at line 1:
ORA-06550: line 1, column 7:
PLS-00306: wrong number or types of arguments in call to 'OTIME'
ORA-06550: line 1, column 7:
PL/SQL: Statement ignored

I am using SQL *Plus on Oracle 9i on Windows XP.

I haven't created tables to use with this procedure as I wasn't sure if it
was necessary.


Also, how would I get the data from a column called hours in a table called
EMP, when using a procedure?

Many thanks,
James
Reply With Quote
  #2 (permalink)  
Old 10-15-03, 10:38
skd skd is offline
Registered User
 
Join Date: Sep 2003
Posts: 71
//1
I think execute works when you call a procedure from another procedure.

You may try this, save your procedure in file say for eg
procedure_otime.sql and then run at the sql prompt as

>start procedure_otime.sql;

or

>@procedure_otime.sql;


to display errors use show errors" at sql prompt


//2

To get the data from a column called hours in a table called
EMP, when using a procedure

v_hours EMP.hours%TYPE; /* assuming table is created */
BEGIN
SELECT hours INTO v_hours FROM EMP;
DBMS_OUTPUT.PUT_LINE(v_hours);
END;
Reply With Quote
  #3 (permalink)  
Old 10-15-03, 12:28
ndu35 ndu35 is offline
Registered User
 
Join Date: May 2003
Location: France
Posts: 112
Re: Newbie Procedure Problem

Try 'exec otime 42', you must pass one parameter to your proc.

Quote:
Originally posted by donnie_darko
Hi there, I'm new to PL/SQL and have been given the following procedure:

create or replace procedure otime (hoursworked number) as
overtimehours number;
normalhours number;
message varchar2(30);
begin
normalhours := 35;
if hoursworked > normalhours then
overtimehours := hoursworked - normalhours;
message := 'Overtime Hours worked = ';
dbms_output.put_line(message);
dbms_output.put_line(overtimehours);
else
message := 'No Overtime!';
dbms_output.put_line(message);
end if;
end;

it compiles OK, but when I enter the command 'EXECUTE otime', I get he following error:

BEGIN otime; END;

*
ERROR at line 1:
ORA-06550: line 1, column 7:
PLS-00306: wrong number or types of arguments in call to 'OTIME'
ORA-06550: line 1, column 7:
PL/SQL: Statement ignored

I am using SQL *Plus on Oracle 9i on Windows XP.

I haven't created tables to use with this procedure as I wasn't sure if it
was necessary.


Also, how would I get the data from a column called hours in a table called
EMP, when using a procedure?

Many thanks,
James
Reply With Quote
  #4 (permalink)  
Old 10-15-03, 13:44
donnie_darko donnie_darko is offline
Registered User
 
Join Date: Oct 2003
Location: England
Posts: 15
Re: Newbie Procedure Problem

Quote:
Originally posted by ndu35
Try 'exec otime 42', you must pass one parameter to your proc.
I tried this and I received the following error:

BEGIN otime 42; END;

*
ERROR at line 1:
ORA-06550: line 1, column 13:
PLS-00103: Encountered the symbol "42" when expecting one of the following:
:= . ( @ % ;
The symbol ":=" was substituted for "42" to continue.

Then I entered 'execute otime(45) and received the following:

"PL/SQL procedure successfully completed."

Which isn't correct as it should produce a message.
Reply With Quote
  #5 (permalink)  
Old 10-15-03, 13:52
donnie_darko donnie_darko is offline
Registered User
 
Join Date: Oct 2003
Location: England
Posts: 15
ok I seem to have sorted this problem now. I hadn't input the command 'SET SERVEROUTPUT ON' and it worked when I enter the command 'EXECUTE otime(45)'. Thanks for the help.
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