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 > Data Access, Manipulation & Batch Languages > ANSI SQL > need help with procedure

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 12-13-03, 01:40
aurel1412 aurel1412 is offline
Registered User
 
Join Date: Dec 2003
Posts: 14
need help with procedure

I have 3 table called List1. List 2, and List3
The columns in List1 are ID, Name
The columns in List2 are ID (Foreign Key references List1), companyID (Foreign Key references List1)
The columns in List3 are companyID, companyName

I want to write a producere to insert a person to List1 and List2 and then ensure that the companyID is valid (between 1-10), and if its invalid i have to rollback the person insert operation

PLEASE HELP!

Last edited by aurel1412; 12-13-03 at 03:35.
Reply With Quote
  #2 (permalink)  
Old 12-13-03, 03:26
Bart71 Bart71 is offline
Registered User
 
Join Date: Oct 2003
Location: Germany - Stuttgart
Posts: 14
I think you should at first evaluate the company-id from table3 and THEN insert the person and the link in table2. so you don't need rollback or delete...

function get_company_id (p_name in varchar2) return number
is
l_n_ret number;
begin
select id
into l_n_ret
from table3
where company_name = p_name;

return l_n_ret;

exception when others then return 0;
end;


procedure insert_person(p_comp_name in varchar2.p_pers_name in varchar2)
is
l_comp_id number;
begin
l_comp_id:=get_company_id(p_comp_name);
if l_comp_id > 0
then
insert the data in table1 and 2
commit;
end if;
end;
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