|
Re: Conditional Inserts [message #371641 is a reply to message #371639] |
Sat, 18 November 2000 05:12 |
Babu Paul
Messages: 38 Registered: November 2000
|
Member |
|
|
Hi,
Of course you can.
Here is a sample, I have to insert a record into emp with valid dept nos which means these dept nos should be exising in dept table. Assuming that there is no foreign key references on dept table
Here is the query for that
It is as good as having a foreign key reference...
DECLARE
---
----
BEGIN
----
----
INSERT INTO emp
SELECT v_ename
,v_dno
,v_sal
FROM dual
WHERE EXISTS(SELECT 1 FROM dept
WHERE dno = v_dno) ;
---
---
END ;
/
Good Luck!
Babu
|
|
|
Re: Conditional Inserts [message #371644 is a reply to message #371641] |
Mon, 20 November 2000 08:41 |
Troy Hopkins
Messages: 3 Registered: November 2000
|
Junior Member |
|
|
I was trying to find a way of doing it without PL/SQL. When I say conditional inserts, I mean
1. grab a record from a file.
2. test a condition
3. if met, stick that record in table
4. if not met, stick that record in different table.
Any ideas?
Thanks
|
|
|
Re: Conditional Inserts [message #371645 is a reply to message #371641] |
Mon, 20 November 2000 08:41 |
Troy Hopkins
Messages: 3 Registered: November 2000
|
Junior Member |
|
|
I was trying to find a way of doing it without PL/SQL. When I say conditional inserts, I mean
1. grab a record from a file.
2. test a condition
3. if met, stick that record in table
4. if not met, stick that record in different table.
Any ideas?
Thanks
|
|
|
Re: Conditional Inserts [message #371647 is a reply to message #371641] |
Mon, 20 November 2000 09:11 |
Babu Paul
Messages: 38 Registered: November 2000
|
Member |
|
|
Hi,
I can help you if you can tell me how do you read a record from a file. Is it that you are loading the records from the file to a table through sqlloader. If yes, you can then specify the condition in your control script itself. Otherwise if you are using any other method it should be make use of PL/SQL using UTL_FILE. In which case you will not be requiring this conditional insert at all.
Babu
|
|
|
Re: Conditional Inserts [message #371648 is a reply to message #371641] |
Mon, 20 November 2000 09:11 |
Babu Paul
Messages: 38 Registered: November 2000
|
Member |
|
|
Hi,
I can help you if you can tell me how do you read a record from a file. Is it that you are loading the records from the file to a table through sqlloader. If yes, you can then specify the condition in your control script itself. Otherwise if you are using any other method it should be make use of PL/SQL using UTL_FILE. In which case you will not be requiring this conditional insert at all.
Babu
|
|
|
Re: Conditional Inserts [message #371650 is a reply to message #371641] |
Mon, 20 November 2000 09:13 |
Babu Paul
Messages: 38 Registered: November 2000
|
Member |
|
|
Hi,
I can help you if you can tell me how you read a record from a file. Is it that you are loading the records from the file to a table through sqlloader. If yes, you can then specify the condition in your control script itself. Otherwise if you are using any other method it should be making use of PL/SQL eg. UTL_FILE. In which case you will not be requiring this conditional insert at all.
Babu
|
|
|
|