how do you call a procedure and get its variables in pl/sql

376 Views Asked by At

so I am trying to create a game blackjack in plsql, i plan on using 2 procedures that will give me values such as king of spade, 2 of hearts, etc. The main part is the problem where i create the loops and such, I CANNOT CALL THE PROCEDURE.

I tried to call it and sqlplus gives me an error saying 'procedurename' is not a procedure or is undefined which is totally bs.. because i created it and it is in schema so i should be able to use it, its probably just i am calling it wrong or something.

also if i want the variable values in the procedure such as x=1 and i want the value of x to be in my main driver, how do i call it? any changes on the procedure and how do i get it from main?

this is my main

    DECLARE
    draw integer;
    face varchar2(10);
    BEGIN
    draw;
    END;

i want to call draw and i want the values integer and face inside my procedure which are these

    create or replace procedure draw is

draw integer;
face varchar2(10);

    BEGIN
select dbms_random.value(1,13) into draw from dual;


if draw = 11 then
draw := 10;
face := 'Jack';
dbms_output.put_line(face|| ' of ');


elsif draw = 12 then
draw := 10;
face := 'Queen';
dbms_output.put_line(face|| ' of ');


elsif draw = 13 then
draw := 10;
face := 'King';
dbms_output.put_line(face|| ' of ');

elsif draw = 1 then
face := 'Ace';
dbms_output.put_line(face|| ' of ');

else
dbms_output.put_line(draw|| ' of ');

end if;
    END;

thanks in advance smart folks a.k.a experienced programmers!

1

There are 1 best solutions below

0
On

Newbie,

Assuming you need the values back in your main procedure the below should work. You need to declare the parameters as in out so that they are available back in the calling procedure.

DECLARE
    draw integer;
    face varchar2(10);
BEGIN
   drawCard( draw, face);
   dbms_output.put_line('In main Proc ' || face|| ' of ');
END;

create or replace procedure drawCard (draw in out integer, face in out varchar2) is

BEGIN
  select dbms_random.value(1,13) into draw from dual;


  if draw = 11 then
    draw := 10;
    face := 'Jack';
    dbms_output.put_line(face|| ' of ');


  elsif draw = 12 then
    draw := 10;
    face := 'Queen';
    dbms_output.put_line(face|| ' of ');

  elsif draw = 13 then
    draw := 10;
    face := 'King';
    dbms_output.put_line(face|| ' of ');

  elsif draw = 1 then
    face := 'Ace';
    dbms_output.put_line(face|| ' of ');

  else
    dbms_output.put_line(draw|| ' of ');

  end if;
END;