Home » SQL & PL/SQL » SQL & PL/SQL » temp variables and assignments probs
temp variables and assignments probs [message #4188] Fri, 15 November 2002 14:52 Go to next message
Todd Flynn
Messages: 3
Registered: November 2002
Junior Member
I'm trying to make a very simple PL/SQL transaction w/up to 3 purchases in a single transaction in portal and I've hit a wall. If I uncomment the below illustrated code, I get errors:

"Line No. 44 : PLS-00306: wrong number or types of arguments in call to '=' (WWV-17050"

and

"ORA-24344: success with compilation error (WWV-11230)"

I've even tried ':=' where I have the >> instead... but it still doesn't work. Am I assigning wrong? Please help me out.

(
emp_id IN NUMBER,
cust_id IN NUMBER,
tran_paymenttype IN VARCHAR2,
inv_id_input1 IN NUMBER,
inv_id_input2 IN NUMBER,
inv_id_input3 IN NUMBER)

as
temp_transseqnum number(6);
temp_sysdate date;
--item1 number (5, 2);
--item2 number (5, 2);
--item3 number (5, 2);

--trans_total number (6, 2);
begin

select trans_id.nextval
into temp_transseqnum
from dual;

select sysdate
into temp_sysdate
from dual;

insert into transaction
(tran_id, emp_id, cust_id, tran_datetime, TRANPAYMENTTYPE)
values
(temp_transseqnum, emp_id, cust_id, temp_sysdate, tran_paymenttype);

update inventory set inv_quantityinstock = inv_quantityinstock - 1
where inv_id = inv_id_input1;

update inventory set inv_quantityinstock = inv_quantityinstock - 1
where inv_id = inv_id_input2;

update inventory set inv_quantityinstock = inv_quantityinstock - 1
where inv_id = inv_id_input3;

--select cata_rentalprice
--into item1
--from catalog
>> --where inv_id = inv_id_input1;

--select cata_rentalprice
--into item2
--from catalog
>> --where inv_id = inv_id_input2;

--select cata_rentalprice
--into item3
--from catalog
>> --where inv_id = inv_id_input3;

--trans_total := item1 + item2 + item3;

exception
when others then
htp.p('PROC_TRANS_INV: ' || sqlcode || ' ' || sqlerrm);htp.br;

end;
Re: temp variables and assignments probs [message #4190 is a reply to message #4188] Fri, 15 November 2002 16:39 Go to previous messageGo to next message
Todd Barry
Messages: 4819
Registered: August 2001
Senior Member
I think this could be simplified to:

create or replace procedure foo
  (
   p_emp_id in transaction.emp_id%type,
   p_cust_id in transaction.cust_id%type,
   p_tranpaymenttype in transaction.tranpaymenttype%type,
   p_inv_id_input1 in inventory.inv_id%type,
   p_inv_id_input2 in inventory.inv_id%type,
   p_inv_id_input3 in inventory.inv_id%type
  )
as
  v_trans_total  catalog.cata_rentalprice%type;
begin
  insert into transaction 
  (tran_id, emp_id, cust_id, tran_datetime, tranpaymenttype) 
  values 
  (trans_id.nextval, p_emp_id, p_cust_id, sysdate, p_tranpaymenttype);
 
  update inventory 
     set inv_quantityinstock = inv_quantityinstock - 1
   where inv_id in (p_inv_id_input1, p_inv_id_input2, p_inv_id_input3);
 
  select sum(cata_rentalprice)
    into v_trans_total
    from catalog
   where inv_id in (p_inv_id_input1, p_inv_id_input2, p_inv_id_input3);
 
  -- do something with v_trans_total (display, return, etc.)
 
exception
  when others then
    htp.p('PROC_TRANS_INV: ' || sqlcode || ' ' || sqlerrm);
    htp.br;
end;
/


Note:
1) Variable typing for parameters and local variables
2) Elimination of variables for sysdate and sequence value
3) Consolidation of update and select statements
Re: temp variables and assignments probs [message #4192 is a reply to message #4188] Fri, 15 November 2002 18:41 Go to previous messageGo to next message
Todd Flynn
Messages: 3
Registered: November 2002
Junior Member
That looks alot tighter than mine. Thanks. Heres the problem though. I need a select into join of two tables. Cata_ID and cata_rentalprice are in different tables than the inventory table...and its kicking my butt how to figure it out. I know PL/SQL are alittle different than SQL.

I got cata_ID(pk) and cata_rentalprice in a catalog table. Catalog_ID (fk)... and inv_id in a inventory table. So I need to select the rental_price into the variable item1 based on the selection of inv_id_input off of inv_id whose relation is through the inventory.catalog_id to the catalog.cata_id to the catalog.cata_rentalprice.

Can someone show an example of a mult-table outer join with a select into invoved too?
Re: temp variables and assignments probs [message #4195 is a reply to message #4192] Sat, 16 November 2002 13:41 Go to previous messageGo to next message
Todd Flynn
Messages: 3
Registered: November 2002
Junior Member
Thanks Barbara and Todd. The proc simplification and select into statement worked well.

One more question please. I'm working this in Portal. I got DBA rights. When I put that proc in a form based off of those three tables that have no check constraints, or awkward restrictions (triggers, functions, etc) I get an error when I submit it. All the _IDs that I input do exist too in their respective tables too. The error is:

begin
"GROUP1DEV"."TRANS_PROC2" ( EMP_ID => 2, CUST_ID => 2, TRAN_PAYMENTTYPE => 'cash', INV_ID_INPUT1 => 1, INV_ID_INPUT2 => 7, INV_ID_INPUT3 => 10, INV_ID_INPUT4 => 9, INV_ID_INPUT5 => 6, INV_ID_INPUT6 => 5);
end;

ORA-01001: invalid cursor

Any ideas what this error is? I have no cursors in the procedure at all. I triple-checked everything and still get this error. I also haven't altered any tables before created the form.

Thanks.
Re: temp variables and assignments probs [message #4209 is a reply to message #4192] Mon, 18 November 2002 16:13 Go to previous message
Barbara Boehmer
Messages: 9091
Registered: November 2002
Location: California, USA
Senior Member
Since it works by itself, that tends to indicate that the problem is elsewhere. The only thing I can think of is to check the value of MAXOPENCURSORS and increase it if necessary. The complete text of the error message in the Oracle on-line documentation, copied below, suggests that:

ORA-01001 invalid cursor

Cause: Either a host language program call specified an invalid cursor or the value of the MAXOPENCURSORS option in the precompiler command were too small. All cursors must be opened using the OOPEN call before being referenced in any of the following calls: SQL, DESCRIBE, NAME, DEFINE, BIND, EXEC, FETCH, and CLOSE. The Logon Data Area (LDA) must be defined by using OLON or OLOGON. If the LDA is not defined, this message is issued for the following calls: OPEN, COM, CON, ROL, and LOGOFF.

Action: Check the erroneous call statement. Specify a correct LDA area or open the cursor as required. If there is no problem with the cursor, it may be necessary to increase the MAXOPENCURSORS option value before precompiling.
Previous Topic: Re: Best way to process large volume of data (Oracle9i)
Next Topic: how to convert "110000" into "one hundred ten thousand"
Goto Forum:
  


Current Time: Mon Apr 29 06:47:21 CDT 2024