If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > Oracle > insert data into multiple tables using pl/sql procedure

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old
Registered User
 
Join Date: Apr 2012
Posts: 2
insert data into multiple tables using pl/sql procedure

Hi All,

First i created a simple function to get the next available dept_id.Then i created a procedure in order to insert the data in to emp and dept tables.

Below is my procedure:

create or replace procedure sampleSP

(ename in varchar2,

sal in number,

dname varchar2)

is

x number;

begin

x:=getDept; //Function to get the deptid

insert into dept values(x,dname);


insert into emp values(ename,sal,x);

end;

/

Procedure created successfully.

Testing Procedure:

begin

sampleSP('Admin','X',1500); //I am not inserting the dept value since i am using the function to get the id in the procedure

end;

/

Getting an error fk violation error for employee deptid while running the procedure.Let me know where i am doing wrong.
Reply With Quote
  #2 (permalink)  
Old
Registered User
 
Join Date: Aug 2003
Location: Where the Surf Meets the Turf @Del Mar, CA
Posts: 7,497
ERROR? What Error? I don't see any error.
Is COPY & PASTE broken for you.
post DDL for all tables involved.
Is FK violation due to problem with parent or child table?
__________________
You can lead some folks to knowledge, but you can not make them think.
The average person thinks he's above average!
For most folks, they don't know, what they don't know.
Don't say, show. Don't promise, prove.
Reply With Quote
  #3 (permalink)  
Old
Registered User
 
Join Date: Apr 2012
Posts: 2
insert data into multiple tables using pl/sql procedure

Hi,

The error is fk violation while running the procedure.My child table is employee table which has dept_id as foreign key.

Error is coming when running the procedure:

I passed 3 values dname=>'Admin' ename=>'X' sal=>1500 and not passing any department value since i will get it in the procedure through function.

Thanks in advance.
Reply With Quote
  #4 (permalink)  
Old
Registered User
 
Join Date: Aug 2003
Location: Where the Surf Meets the Turf @Del Mar, CA
Posts: 7,497
create or replace procedure sampleSP
(ename in varchar2,
sal in number,
dname varchar2)

sampleSP('Admin','X',1500);

ENAME=>'Admin'
SAL=>'X"
DNAME=>1500

if you do not start using COPY & PASTE, I will stop responding.
__________________
You can lead some folks to knowledge, but you can not make them think.
The average person thinks he's above average!
For most folks, they don't know, what they don't know.
Don't say, show. Don't promise, prove.
Reply With Quote
  #5 (permalink)  
Old
Lead Application Develope
 
Join Date: Jun 2004
Location: Liverpool, NY USA
Posts: 2,393
I need the EXACT error you are getting (the entire string) and the logic behind getdept.
__________________
Bill
You do not need a parachute to skydive. You only need a parachute to skydive twice.
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On