Home » SQL & PL/SQL » SQL & PL/SQL » help with procedures!
help with procedures! [message #614199] Sun, 18 May 2014 20:20 Go to next message
reuben123
Messages: 4
Registered: March 2014
Location: India
Junior Member
Hello everyone,
I have just started learning oracle, so my doubt might be really dumb, but i would really appreciate it if anyone could help me.

this is my code:


create or replace procedure new
is
BEGIN
EXECUTE IMMEDIATE 'insert into reuben values(:name,:num);
end;
/



my objective is to accept values from the user, during runtime of the procedure.
but when i try to do this i get several errors :
variables unbounded etc

please help!
Re: help with procedures! [message #614200 is a reply to message #614199] Sun, 18 May 2014 21:37 Go to previous messageGo to next message
BlackSwan
Messages: 26766
Registered: January 2009
Location: SoCal
Senior Member
Please read and follow the forum guidelines, to enable us to help you:

http://www.orafaq.com/forum/t/88153/0/ and please read http://www.orafaq.com/forum/t/174502/102589/

You do not need EXECUTE IMMEDIATE
how do you ensure correct datatype gets passed for each column?

It is a really Bad Idea (tm) to use RESERVED WORD ("new") for object name.

SQL> create table ruben (col1 varchar2(31), col2 number);

Table created.

SQL> CREATE OR replace PROCEDURE Foobar(name_in VARCHAR2, 
                                   num_in  NUMBER) 
IS 
BEGIN 
    INSERT INTO ruben 
    VALUES     (name_in, 
                num_in); 
END; 

/  2    3    4    5    6    7    8    9   10  

Procedure created.

SQL> exec foobar('NEWBIE',0);

PL/SQL procedure successfully completed.

SQL> 



& you better hope that RUBEN has only 2 columns
Re: help with procedures! [message #614210 is a reply to message #614200] Mon, 19 May 2014 02:35 Go to previous messageGo to next message
cookiemonster
Messages: 13920
Registered: September 2008
Location: Rainy Manchester
Senior Member
Oracle procedures and functions are not user interactive.
If you want a program that interacts with users and prompts them for input you should write it in a different language - java for example - and then have that program call the DB procedure to do the insert.
Re: help with procedures! [message #614213 is a reply to message #614199] Mon, 19 May 2014 03:00 Go to previous messageGo to next message
dariyoosh
Messages: 538
Registered: March 2009
Location: France
Senior Member
"reuben123 "
... I have just started learning oracle ...

Just in case you don't already have the link: PL/SQL Language Reference or better Oracle Database Documentation Library
Re: help with procedures! [message #614218 is a reply to message #614210] Mon, 19 May 2014 03:28 Go to previous message
Michel Cadot
Messages: 68645
Registered: March 2007
Location: Nanterre, France, http://...
Senior Member
Account Moderator

... or use an interactive SQL tool like SQL*Plus:
SQL> insert into reuben values('&name',&num);
Enter value for name: michel
Enter value for num: 1
insert into reuben values('michel',1)
            *
ERROR at line 1:
ORA-00942: table or view does not exist

But this is not a good way to do it from a performances point of view as you don't use bind variables. So it is good only if it is seldom used.

[Updated on: Mon, 19 May 2014 03:30]

Report message to a moderator

Previous Topic: ORA-01031: insufficient privileges
Next Topic: Looping joins
Goto Forum:
  


Current Time: Wed Apr 24 17:26:45 CDT 2024