function values and fun query [message #4336] |
Thu, 28 November 2002 10:47 |
cormac
Messages: 25 Registered: November 2002
|
Junior Member |
|
|
Hi,
I'm very new to this pl/sql stuff and for some personal fun, I want to create a function that will give me an idea of how much I can win at the bookies(bookmakers!)
Can I use '&1'?
Any idea's how to do this better please let me know...
cheers
Cormac--see query below
CREATE OR REPLACE FUNCTION BOOKIE (p_BET in NUMBER ,
p_mul1 in number,p_div1 in number,p_winnings out number)
RETURN NUMBER
IS
cursor c_stake
is select '&1' from dual;
retval number;
e_max_bet exception;
v_bet number;
v_mul1 number;
v_div1 number;
BEGIN
v_bet := p_bet;
v_mul1 := p_mul1;
v_div1 := p_div1;
open c_stake;
if c_stake%found then
fetch c_stake into v_bet;
v_bet := (v_bet*v_mul1)/v_div1;
end if;
close c_stake;
v_bet := p_winnings;
return v_bet;
end;
/
|
|
|
|
Re: function values and fun query [message #4340 is a reply to message #4338] |
Fri, 29 November 2002 03:01 |
cormac
Messages: 25 Registered: November 2002
|
Junior Member |
|
|
MME,
yes, it is work in progress. I intend to use the exception later: I want to set a maximum stake!
As I said, I'm new to this and this is a fun, but useful way of getting my head around these pl/sql functions.
I changed it to this (no cursor with dual):
It compiles ok, but how do you it to return a value?
CREATE OR REPLACE FUNCTION BOOKIE (p_BET in NUMBER ,
p_mul1 in number,p_div1 in number,p_winn out number)
RETURN NUMBER
IS
WINNINGS NUMBER(30);
e_max_bet exception;
v_bet number;
v_mul1 number;
v_div1 number;
v_winnings number;
BEGIN
v_bet := p_bet;
v_mul1 := p_mul1;
v_div1 := p_div1;
v_winnings := winnings;
v_bet := (v_bet*v_mul1)/v_div1;
v_bet := v_winnings;
return v_bet;
end;
/
|
|
|
|
|