Question

TABLE DESC:

Product (Prodid, Prodesc, Price, Stock)
Purchase (Purid, Proid, qty, supname) 
Sales (Saleid, Proid, qty, custname) 

I need to create a procedure which accepts a prodid and displays all the sales and purchase records of it.

This is my code:

create or replace procedure display (p in varchar2)
AS
pur_dis purchase%rowtype;
sal_dis sales%rowtype;
BEGIN
select * INTO pur_dis from purchase where proid=p;
select * INTO sal_dis from sales where proid=p;
end;
/

when i try to execute It displays only "PL/SQL procedure successfully completed"

But I needed the purchase table values and sales table values to be displayed for that particular id. What to do?

Était-ce utile?

La solution

If you need to display in your worksheet, you may use dbms_output.put_line

make necessary changes in the procedure to display:

create OR REPLACE
PROCEDURE display(
          p IN VARCHAR2)
AS
     pur_dis purchase%rowtype;
     sal_dis sales%rowtype;
BEGIN
     SELECT * INTO pur_dis FROM purchase WHERE proid=p;
     dbms_output.put_line('Displaying your values:'||pur_dis.Purid||' '||pur_dis.Proid||' '||pur_dis.qty||' '||pur_dis.supname);
     SELECT * INTO sal_dis FROM sales WHERE proid=p;
END;
/

call the procedure:

SET SERVEROUTPUT ON
begin
display(value_of_p);
end;
/
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top