Home » RDBMS Server » Server Administration » Conditional Inserts
Conditional Inserts [message #371639] Fri, 17 November 2000 13:05 Go to next message
Troy Hopkins
Messages: 3
Registered: November 2000
Junior Member
Anybody know how to do conditional inserts using standard SQL?
Re: Conditional Inserts [message #371641 is a reply to message #371639] Sat, 18 November 2000 05:12 Go to previous messageGo to next message
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 Go to previous messageGo to next message
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 Go to previous messageGo to next message
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 Go to previous messageGo to next message
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 Go to previous messageGo to next message
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 Go to previous messageGo to next message
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
Re: Conditional Inserts [message #371682 is a reply to message #371641] Fri, 24 November 2000 08:31 Go to previous message
Alagu
Messages: 6
Registered: November 2000
Junior Member
Hi,

we can use DECODE function inside the insert statement

I have used decode functions in insert statements.

Thanks

Alagappan
Previous Topic: Re: Query - whoops - see scripts
Next Topic: ORA-01013: user requested cancel of current operation
Goto Forum:
  


Current Time: Sat May 04 01:31:52 CDT 2024