Results 1 to 5 of 5
  1. #1
    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.

  2. #2
    Join Date
    Aug 2003
    Location
    Where the Surf Meets the Turf @Del Mar, CA
    Posts
    7,647
    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.
    There are no stupid questions, but there are a LOT of Inquisitive Idiots.

  3. #3
    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.

  4. #4
    Join Date
    Aug 2003
    Location
    Where the Surf Meets the Turf @Del Mar, CA
    Posts
    7,647
    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.
    There are no stupid questions, but there are a LOT of Inquisitive Idiots.

  5. #5
    Join Date
    Jun 2004
    Location
    Liverpool, NY USA
    Posts
    2,434
    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.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •