Updating columns of one table based on other table [message #346360] |
Mon, 08 September 2008 06:04  |
joebunny
Messages: 18 Registered: September 2008
|
Junior Member |
|
|
Hi All,
I have two tables and I upload data from an external source in both the tables.
Let the two tables be A and B.
Now the scenario is as follows.
First I upload data from an external source into table A.
Then I upload data from external source into table B. But as soon as I upload data into table B I want that depending on certain conditon of certain columns in table A, some columns in table B be updated.
for eg if table A has column named 'salary' and table B has column named 'type'.
When I upload data in table A and then into B my column named 'type' in table B should be updated to rich,medium or poor depending on the value of salary in table A for employees which are commom in both table A and B.
Can anybody suggest me how can I acheive this ? since I want my 'type' column to be updated automatically instead of running a query afterwards and then updating the type status in table B.
Any help would be appreciated.
Thanks in advance.
|
|
|
|
|
Re: Updating columns of one table based on other table [message #346372 is a reply to message #346363] |
Mon, 08 September 2008 06:39   |
joebunny
Messages: 18 Registered: September 2008
|
Junior Member |
|
|
Hi jo,
Thanks for your reply.
I used and after insert trigger on table B since the column to be updated was from table B ,but got an error messaeg saying the trigger was mutating itself, did not undertand what it meant actually.
So I used an after update trigger and thought I did not get any error but nothing seemed to happen to my column status either i.e it was not updated.
Can you suggest me what went wrong.
|
|
|
|
Re: Updating columns of one table based on other table [message #346377 is a reply to message #346367] |
Mon, 08 September 2008 06:44   |
joebunny
Messages: 18 Registered: September 2008
|
Junior Member |
|
|
Hi michel,
thanks for your reply,
I wish I could put my queries explicitly in a code.
I tried that and was able to do that.But the thing is that I want my column in table B to be updated automatically on its own after data upload in table B depending on the condition in table A for common records in both the tables.
As far as procedure is concerned ,can you explain in alittle detail how would I call the procedure after upoading data in table B.
Thanks
|
|
|
Re: Updating columns of one table based on other table [message #346378 is a reply to message #346360] |
Mon, 08 September 2008 06:47   |
joicejohn
Messages: 327 Registered: March 2008 Location: India
|
Senior Member |
|
|
Michel,
joebunny wrote on Mon, 08 September 2008 16:34 |
since I want my 'type' column to be updated automatically instead of running a query afterwards and then updating the type status in table B.
|
Can a procedure be sufficient for this requirement?
Regards,
Jo
|
|
|
|
|
Re: Updating columns of one table based on other table [message #346394 is a reply to message #346381] |
Mon, 08 September 2008 07:28   |
joebunny
Messages: 18 Registered: September 2008
|
Junior Member |
|
|
Quote: |
There 2 issues: initial loading, everyday task.
Which one are you talinkg about?
|
Its a once a month upload at the start of every month.
So you can say its quite a frequent task.
Quote: | Don't allow anyone to update the table but the procedure.
|
How can I acheive that.
Also I would like to mention that this is not a busin ess requirement but its for my own reference which I will be using for my further calculations in the application.
|
|
|
|
|
|
|
Re: Updating columns of one table based on other table [message #346636 is a reply to message #346422] |
Tue, 09 September 2008 03:52   |
JRowbottom
Messages: 5933 Registered: June 2006 Location: Sunny North Yorkshire, ho...
|
Senior Member |
|
|
Why not simply call the procedure from a Statement level After Insert trigger.
That way you get the benefit of explicitly defined business rules, plus you can guarantee that they get run at the right time.
create table test_0079 (col_1 number, col_2 number);
create or replace procedure test_0079_post_ins as
begin
update test_0079
set col_2 = sign(col_1);
end;
/
create or replace trigger test_0079_ais
after insert on test_0079
begin
test_0079_post_ins;
end;
/
insert into test_0079(col_1) select level -5 from dual connect by level <= 10;
select * from test_0079;
COL_1 COL_2
---------- ----------
-4 -1
-3 -1
-2 -1
-1 -1
0 0
1 1
2 1
3 1
4 1
5 1
10 rows selected.
|
|
|
|
|
|
Re: Updating columns of one table based on other table [message #346663 is a reply to message #346651] |
Tue, 09 September 2008 05:08  |
Frank
Messages: 7901 Registered: March 2000
|
Senior Member |
|
|
dr.s.raghunathan wrote on Tue, 09 September 2008 11:26 | dear michel
Quote: |
if it is a business requirement, put it explicitly in code.
|
Is there any specific reason to avoid triggers when it is a business requirement.
yours
dr.s.raghunathan
|
Triggers are also code.
Business requirements that are implemented by triggers are also explicitly put in code.
|
|
|