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 > Creating procedures in PL/SQL

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 07-10-03, 00:12
izy izy is offline
Registered User
 
Join Date: Jul 2003
Posts: 10
Creating procedures in PL/SQL

I want to create a procedure that takes a product number as an argument and displays the name of the product. This is what I have so far, but I am getting errors. I was wondering if someone could please help me out with this. Thanks.

PROCEDURE displayProd(prono PRODUCTS.PNO%TYPE, name PRODUCTS.PNAME%TYPE)

IS


BEGIN

SELECT PRODUCTS.PNAME
FROM PRODUCTS, ODETAILS
WHERE PRODUCTS.PNO = ODETAILS.PNO;

dbms_output.print_line('The name of the product is ' || name);

END displayProd;

/
Reply With Quote
  #2 (permalink)  
Old 07-10-03, 05:13
alligatorsql.com alligatorsql.com is offline
Registered User
 
Join Date: Jul 2001
Location: Germany
Posts: 189
Hello

Hello,

which errors do you get ?

Here are some suggestion ...

1) define your in or out vars for better reading
2) define a field name as a placeholder for the result in your select
3) What is print_line ??? Do you mean put_line ???

PROCEDURE displayProd(prono IN PRODUCTS.PNO%TYPE, name OUT PRODUCTS.PNAME%TYPE)

IS
BEGIN
SELECT PRODUCTS.PNAME
INTO name
FROM PRODUCTS, ODETAILS
WHERE PRODUCTS.PNO = ODETAILS.PNO;

dbms_output.put_line('The name of the product is ' || name);

END displayProd;

Hope that helps ?

Best regards
Manfred Peter
(Alligator Company Software GmbH)
http://www.alligatorsql.com
Reply With Quote
  #3 (permalink)  
Old 07-10-03, 13:43
izy izy is offline
Registered User
 
Join Date: Jul 2003
Posts: 10
I get an error that says: invalid sql statement. i think i need a create or replace procedure. I tried that, and it said: Warning: Procedure created with compilation errors. So, I still don't know what the prob. is.
Reply With Quote
  #4 (permalink)  
Old 07-10-03, 15:39
MicheleDD MicheleDD is offline
Registered User
 
Join Date: Jul 2003
Location: Germantown, MD
Posts: 5
Quote:
Originally posted by izy
I get an error that says: invalid sql statement. i think i need a create or replace procedure. I tried that, and it said: Warning: Procedure created with compilation errors. So, I still don't know what the prob. is.
Does it have to be a procedure? I think a function would be more appropriate. You would pass in one argument (the product number) and return one argument (the associated product name).

However, if you need to write a procedure (i.e., a homework assignment) then the recommendations from the previous reply should work (i.e., including the INTO clause into your SQL statement).
Reply With Quote
  #5 (permalink)  
Old 07-10-03, 19:20
alligatorsql.com alligatorsql.com is offline
Registered User
 
Join Date: Jul 2001
Location: Germany
Posts: 189
Hello

Hello,


of course the beginning is
CREATE OR REPLACE PROCEDURE ....

If you would like to see the errors use f.e. the AlligatorSQL at
http://www.alligatorsql.com/download/alligator.zip

or use the statement

SELECT e.*
FROM sys.error$ e,
sys.all_objects a
WHERE a.object_id = e.obj#
AND a.owner = 'SCOTT'
AND a.object_name = 'MYPROC'
ORDER BY e.sequence#

(Please change the owner SCOTT and the object_name MYPROC to your schema and procedure name)

Hope that helps ?

Best regards
Manfred Peter
(Alligator Company Software GmbH)
http://www.alligatorsql.com
Reply With Quote
  #6 (permalink)  
Old 07-11-03, 01:46
izy izy is offline
Registered User
 
Join Date: Jul 2003
Posts: 10
Re: Creating procedures in PL/SQL

Sorry, I meant something else. I am told to write a procedure that displays the names of products for these orders that have not been shipped. When I run this, I get a 'Warning: Procedure created with compilation errors. I have no idea what the problem is. Am I declaring the null right?

CREATE OR REPLACE PROCEDURE ItemsShipped(myname IN PRODUCTS.PNAME%TYPE)

IS

BEGIN
SELECT PRODUCTS.PNAME
INTO myname
FROM PRODUCTS, ORDERS, ODETAILS
WHERE PRODUCTS.PNO = ODETAILS.PNO AND ORDERS.ONO = ODETAILS.ONO AND
ORDERS.SHIPPED IS NULL;

END ItemsShipped;

/

Quote:
Originally posted by izy
I want to create a procedure that takes a product number as an argument and displays the name of the product. This is what I have so far, but I am getting errors. I was wondering if someone could please help me out with this. Thanks.

PROCEDURE displayProd(prono PRODUCTS.PNO%TYPE, name PRODUCTS.PNAME%TYPE)

IS


BEGIN

SELECT PRODUCTS.PNAME
FROM PRODUCTS, ODETAILS
WHERE PRODUCTS.PNO = ODETAILS.PNO;

dbms_output.print_line('The name of the product is ' || name);

END displayProd;

/
Reply With Quote
  #7 (permalink)  
Old 07-11-03, 04:41
alligatorsql.com alligatorsql.com is offline
Registered User
 
Join Date: Jul 2001
Location: Germany
Posts: 189
name declared as IN

Hello,

the only thing I can see is, that you have declared the myname parameter as an IN and you shift the result into this var.

Please declare it as IN OUT ...

Again ...

If you have error use a GUI that displays you the errors or select the error table like I mentioned before.

Otherwise you are developing in the dark

Best regards
Manfred Peter
(Alligator Company Software GmbH)
http://www.alligatorsql.com
Reply With Quote
  #8 (permalink)  
Old 07-11-03, 05:54
andrewst andrewst is offline
Moderator.
 
Join Date: Sep 2002
Location: UK
Posts: 5,171
Re: Creating procedures in PL/SQL

Quote:
Originally posted by izy
Sorry, I meant something else. I am told to write a procedure that displays the names of products for these orders that have not been shipped. When I run this, I get a 'Warning: Procedure created with compilation errors. I have no idea what the problem is. Am I declaring the null right?

CREATE OR REPLACE PROCEDURE ItemsShipped(myname IN PRODUCTS.PNAME%TYPE)

IS

BEGIN
SELECT PRODUCTS.PNAME
INTO myname
FROM PRODUCTS, ORDERS, ODETAILS
WHERE PRODUCTS.PNO = ODETAILS.PNO AND ORDERS.ONO = ODETAILS.ONO AND
ORDERS.SHIPPED IS NULL;

END ItemsShipped;

/
In SQL Plus, just type SHOW ERROR after receiving the warning. In this case, you should see this:

SQL> show error
Errors for PROCEDURE ITEMSSHIPPED:

LINE/COL ERROR
-------- -----------------------------------------------------------------
4/1 PL/SQL: SQL Statement ignored
5/6 PLS-00403: expression 'MYNAME' cannot be used as an INTO-target
of a SELECT/FETCH statement

This is bacause IN parameters are read-only. Change IN to OUT or IN OUT.
__________________
Tony Andrews
http://tinyurl.com/tonyandrews
Reply With Quote
  #9 (permalink)  
Old 01-13-11, 02:18
raj.sreenu raj.sreenu is offline
Registered User
 
Join Date: Oct 2010
Posts: 4
Smile Pls-00403


Thank you very much for your 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