update of several columns of values in another table
HelloI have two tables in a database of 11 GR 2 that contain similar data. There is no FK relationship between the two tables, and for now, I need the data in MASTER to match what is in the SECONDARY. Table data types are the same with the same length.
Table 1 is called MASTER and columns are:
MTID
ADDRESS1
ADDRESS2
CITY
Table 2 is called SECONDARY and columns are:
SDID
ADDRESS1
ADDRESS2
CITY
MID and SID are the same on both, but the rest of the columns may be the same or in some cases are different.
I ran the following query that lets me know there are 20 k odd rows that have different data in these lines (I'm not at work at the mo so do not have the exact query I ran or table column names, but it's close enough).
select
m.address1 as maddress1,
s.address1 as saddress1,
m.address2 as maddress2,
s.address2 as saddress2,
m.city as mcity,
s.city as scity
from master m, secondary s
where m.mtid = s.sdid
and m.address1 != s.address1
or m.address2 != s.address2
or m.city != s.city
/
I need to update the rows in the master of secondary school where these values are different. I tried a few different queries updated with no luck.I want to do something like
update m.address1
set m.address1=s.address1
where m.address1 != s.address1
and m.mtid = s.stid;
But I want to update columns address1 and address2, city of master.Any ideas on how I can do this? After you run the update results of my select query should return no rows.
Thanks in advance and I hope that the question made sense.
1008991 wrote:
I got a similar error as well:update master m set (sm_user_addr_1, sm_user_addr_2, sm_user_city, sm_user_postal_cde) = (select sm_user_addr_1, sm_user_addr_2, sm_user_city, sm_user_postal_cde from secondary s where s.sd_key = m.sm_key ) where exists ( select 1 from secondary s where s.sd_key = m.sm_key and (s.sm_user_addr_1 != m.sm_user_addr_1 or s.sm_user_addr_2 != m.sm_user_addr_2 or s.sm_user_city != m.sm_user_city or s.sm_user_postal_cde != m.sm_user_postal_cde)); ERROR at line 3: ORA-01427: single-row subquery returns more than one row
It simply means that you have several lines with the same sd_key for a given sm_key.
Is that you have secondaries for one master. You must choose only one line
If you need additional terms in your where clause
select sm_user_addr_1, sm_user_addr_2, sm_user_city, sm_user_postal_cde
from secondary s
where s.sd_key = m.sm_key
Tags: Database
Similar Questions
-
Update of an array of values from another table
Hi here is my requirement. Please help on this
I have a table_a
EmpID pri_location alt_location months of the year
123 2012 Oct
123 2013 Sep
123 2013 Sep
124 2013 Sep
124 2013 Oct
125 2013 SepAnother table_b
EmpID pri_location alt_location
124 NY LA
125 LA NY
123 NJ DC
I need update statement where my table_a should be updated as below for 2013, only Ms
EmpID pri_location alt_location months of the year
123 2012 Oct
NJ 123 DC 2013 Sep
NJ 123 DC 2013 Sep
124 NY 2013 Ms
124 2013 Oct
125. THE NY 2013 SepI make this request, but it is not updated as required
upgrading from table_a a set (pri_location, alt_location) = (select pri_location, alt_location from table_b b where the b.empid = a.empid and a.year = 2013 and a.month = Sep)
Please help on this
Thank you
upgrading from table_a a set (pri_location, alt_location) = (select pri_location, alt_location from table_b b where b.empid = a.empid) where a.year = 2013 and a.month = Sep
Try this and after back if it works!
Kind regards
Hrvoje
-
A statement UPDATE changes the line if the update changes the column even value?
HI -.
I have a main classification and the corresponding audit table. I have a trigger. I created using the suggestion:http://www.runningoracle.com/product_info.php?products_id=211
Now the problem that I am facing is that: if I run the same query (same value) update on the main table for n times (with the same data)... my audit table is updated with a new record every time. He is not able to determine that the value is the same.
My goal is to load the audit table data if the value in a cell in the main table is really have changed.
A statement UPDATE changes the line if the update changes the column even value?
Best regards
I have a main Table and the corresponding Audit Table. I have a trigger. I created using the suggestion:http://www.runningoracle.com/product_info.php?products_id=211
Why?
You try to resolve what made you what are the PROBLEM that select as the solution?
Now the problem that I am facing is that: if I run the same query (same value) update on the main table for n times (with the same data)... my audit table is updated with a new record every time.
Yes - it is EXACTLY what you say that you wanted to do and EXACTLY what the code does in this article.
He is not able to determine that the value is the same.
I think you mean that the code does NOT check if the value is the same. You can certainly change the code to do this check. But I have a question to start with your need for such a solution.
My goal is to load the audit table data if the value in a cell in the main table is really have changed.
OK - then modify the code to check EACH COLUMN and compare its NEW value to the OLD value and insert only the table of audit if SOME (or columns you care specifically) have changed.
A statement UPDATE changes the line if the update changes the column even value?
It depends on what you mean by 'change the line '. Of course to update a column with the SAME value does not change the resulting data value.
But the physical structure of the line, the location of the pieces of line and information in the header block (YVERT, etc.) will change. And, as others have said Oracle doesn't know and doesn't care, so if the new value of a column is the same as the old value will create redo, undo and the rest.
Start over and tell us what PROBLEM you're trying to solve. Then we can help you find the best way to solve it.
-
Update of several columns on multiple tables
Hello
I try to update several columns on two different tables, and I would like to know how to proceed in a SQL statement.
I have the data I want to update in this SQL statement...
#####################################
Select srv. X_SERVICING_DEALER as 'The merchant name', -(want to update this column)
SRV. X_SERVICING_SITE as ' dealer # ', -(want to update this column)
dlrx. ATTRIB_50 'Région',--(tiens à mettre à jour cette colonne)
dlrx. ATTRIB_49 as 'District', -(want to update this column)
DLR.x_zone_cd as 'Zone'-(want to update this column)
Of
s_srv_req srv,
s_org_ext dlr,
s_org_ext_x dlrx
where dlr.row_id = srv.pr_con_org_id
and dlr.row_id = dlrx. par_row_id
and srv.row_id = 1-1RSEXAV';
#####################################
Any guidance would be appreciated. Thanks in advance.
Chris
> I'm trying to update several columns on two different tables, and I would like to know how to proceed in a SQL statement.
You can not. Only one table can be updated at the same time.
-
Validation form column against the value of another Table
Hello
I'm new to this forum, so please bear with me a bit! I only have a small amount of writing PL/SQL experience, and I've never written Javascript or JQuery before. I am an Oracle DBA and I coding experience C and PERL, so I have a strong technical background. But I need some advice on the best way to approach a problem.
I have an application of data base in Oracle Apex (version 4.2) with a tabular form on a table: Let's say that #1 with the conditions of licence 1 a, 1 b, and1C. I have to make sure that the value entered in col B is not greater than the value of a column in another table (for example table #2 pass 2 (a). From a conceptual point of view, the amount of money available is in the #2 table, and my tabular form lines are an act of spending money (such as orders or invoices), so I have to make sure that we spend more that we have. Who is?
Does anyone have tips for the best way to do it? I'm figuring that the biggest problem here is perhaps to account for people who enter multiple lines in the form of tables at the same time, right? So, if a person is entered 3/invoices, I need a total to ensure that they do not have spend more than we have in the #2 table.
I really appreciate your help!
Best regards
Laurie Baublitz
Ah, I was not totally with you on this charge then. My validation works overall, but it totals the amount for each line, regardless of the task. Okay - who was not totally my solution but more a demonstration of the technique that you can use to validate your tabular presentation in this way.
You could solve this issue with a safe collection, or with a table plsql where you add an entry for each task name and keep the amount stored in there.
Anyway, it would be better for you to spend a little time on playback on the plsql collections or collections apex!
Remember, this is a sample and you will need to take stock of it. The best solutions are those where you need to experiment with 8)
DECLARE TYPE tt_taskamount IS TABLE OF NUMBER INDEX BY VARCHAR2(20); t_taskamount tt_taskamount; l_task VARCHAR2(20); l_amount NUMBER; l_max NUMBER; BEGIN -- F02 is the taskname -- F03 is the amount -- adapt to your situation! FOR i IN 1..apex_application.g_f02.count LOOP l_task := apex_application.g_f02(i); l_amount := apex_application.g_f03(i); IF NOT t_taskamount.exists(l_task) THEN t_taskamount(l_task) := l_amount; ELSE t_taskamount(l_task) := t_taskamount(l_task) + l_amount; END IF; -- it's not the best idea to perform a select each time and could be -- done better but for the sake of the example it's fine -- not too bad either if the rowcount is small. SELECT maxamount INTO l_max FROM table2 WHERE taskname = l_task; IF t_taskamount(l_task) > l_max THEN -- returning will stop further processing and throw an error message as soon as a budget has been overrun -- it might or might not be required behaviour but that's up to you RETURN 'The max amount ('||l_max||') for task ' || l_task ||' has been exceeded. Reduce the total amount on associated tasks!'; END IF; END LOOP; END;
-
How can I update this table with values from another table?
Hello
I have a table 'governed '. I want to replace the values in the column "regies.agent" by the value of the column "regies_personnes.id."
As you can see the tables have a column of common values. IE regies.agent = regies_personnes.nom
Table 'governed ':
Insert into 'authorities' (AGENT) values ('Humberdot Alain");
Insert into 'authorities' (AGENT) values ("Danard Patrick");
Table 'regies_personnes ':
Insert into REGIES_PERSONNES (NAME, ID) values ("Humberdot Alain", 1);
Insert into REGIES_PERSONNES (NAME, ID) values ("Danard Patrick", 2);
Before having it
SQL > select agent of authorities;
Humberdot Alain
Patrick Danard
After the update, the result should be
SQL > select agent of authorities;
1
2
Thank you for your kind reply.You can
update regies r set agent = (select id from regies_persones p where r.agent = p.nom) where exists (select id from regies_persones p where r.agent = p.nom)
-
Select column based on values in another table names.
I would like to generate a sql statement based on the values in a table. For example, I would start "Select division from tableA".
In the above example, 'division' would be a value of a column in TableB. Perhaps to looking like this.
Table B
The ColumnName of primary key
-----
-----
Division of 1234
Division of 3456
Department of 7890
I don't want back 'Division' of table B, based on the primary key = 1234 and then generate the SQL above.
Any ideas?
TIAIt can be done through a PL/SQL block or the stored procedure.
Below is a PL/SQL block to give you an idea:declare NewColumnName varchar2(50); SqlString Varchar2(200);begin select ColumnName into NewColumnName from TableB where PrimaryKey = 1234; sqlString := 'select ' || NewColumnName || ' from TableA'; execute immediate sqlString;end;
-
Copy a column of data in another table?
Hello world
I am a beginner SQL who spent ridiculous amounts of time trying to find a solution to a problem no doubt very simple.
I have two tables composed of 162000 lines each. A table has the following format:
table T1
PID NUMBER
NUMBER OF PG
NUMBER OF PCS
PS NUMBER
NUMBER OF PL
NUMBER OF DRIFTWOOD
(coercion, but a simple data)
The DRIFTWOOD column is empty, all the others are completely filled.
The other table is filled only one column:
table T2
NUMBER OF CALCULATEDCHANCE
My intention is to copy all the rows in the column T2 CALCULATEDCHANCE in the column CYBERJER from T1.
Insert will not work because it adds records. I tried to use the update, but maybe I don't get the syntax right. All I got is to copy the first value of DRIFTWOOD in all lines of CALCULATEDCHANCE.
Thanks in advance for your answers!Try
update T2 set calculatedchance = dbms_random.value(0,100);
-
Insert values from another table
Hello I have a table:
T1
---
ID
user
and another table:
T2
---
intellectual property
Mac
So I modified T1:
ALTER table T1 add ip number (20);
ALTER table T1 add mac number (20);
So I have:
T1
---
ID
user
intellectual property
Mac
T1 and T2 are the same number of lines.
Now, I want to insert the values of IP and mac of T2 in the fields ip address and mac of T1.
IP and mac of T2 fields can be "not null".
How can I do?
Thanks in advanceand what do you think about something like this:
UPDATE t1 SET t1.mac = (SELECT t2.mac FROM t2 WHERE t2.id = t1.id), t1.ip = (SELECT t2.ip FROM t2 WHERE t2.id = t1.id)
Give it a shot... validate the results before stolen.
HTH,
Thierry -
TABLE OF UPDATE SQL BASED ON THE VALUE OF THE TABLE HELP
Here is an example of a table that I have and I need basically help make and update statement. My syntax is all messed up. I have update the 'INDY' column WHEN THE NUM AND NUM 2 and INDY are the same. In other words it since it needs to update the last N with a 'Y '.
I hope this feeling...TABLE NAME TEST_1 NUM NUM2 INDI 1 A Y 1 A Y 1 A N
Here's what I have so far but it dosent seem to work... someone can point me in the right direction.
UPDATE T_TEST SET INDI = 'Y' WHERE NUM IN (SELECT COUNT(NUM) FROM T_TEST WHERE INDI = 'Y' GROUP BY NUM HAVING COUNT(NUM) > 1);
UPDATE T_TEST T1 SET INDI = CASE (SELECT COUNT(*) FROM T_TEST T2 WHERE T2.NUM = T1.NUM AND T2.NUM2 = T1.NUM2) WHEN 1 THEN 'N' ELSE 'Y' END / 3 rows updated. SQL> SELECT * 2 FROM T_TEST 3 / NUM N I ---------- - - 1 A Y 1 A Y 1 A Y SQL>
SY.
-
How to insert duplicate values in another table.
angle of attack!
I created two tables a and b
create table one
(key primary code number);
create table b
(code number,
DAT date);
insert into the table of a (code)
values (1234);
insert into the table of a (code)
values (1235);
commit;
Select * from a;
one
-----
1234
1235
-----
insert into the table of a (code)
values (1234);
commit;
ERROR on line 1:
ORA-00001: unique constraint (GMS. SYS_C0030897) violated
{color: #ff0000} * I need, when the user inserts duplicate data, must be inserted into another table b.* {color}
How can I do in forms 6i? Help, please. Thanks in advance.
Hello
What is the relationship with the forms?
Anyway, you can create a trigger on table A that intercepts the error in an exception block, and then create a new row in table B.
If the error comes from a forms based block, intercept the error in a trigger insert.François
-
How to create a table with a column that is the value in another table?
Hi all,
It's my first post n I changed my ODI of DATASTAGE platform. Help me friends n I know basic steps in 11 ODI version which I was training in my company. I hope to have your support and can do everything an action ODI related documents.
My question is...
Table T1 > > > > > > > > > >
service id / / / attr.name / / / attr.value
S1 / / / product_code / / / P1
S1 / / / provider / / / pro1
S2 / / / product_code / / / P2
S3 / / / provider / / / pro3
Table T2 > > > > > > > > > > > > > > >
ID / / / product_code / / / provider
S1 / / / p1 / / / pro1
S2 / / / p2 / / / nullvalue
S3 / / / nullvalue / / / pro3
I have a table T1 since I should show the table T2 is released. Can we say everything on how to write a logic and steps to follow.
Thanks in advance.
Published by: 854662 on April 26, 2011 01:59Hello
U go.
1 the interface:
"Put a filter in your 1 on attr.name = array ' PRODUCT_CODE.
In the map target TABLE2
SERVICE_ID = TABLE1. SERVICE_ID
PRODUCT_CODE = TABLE1. ATTR_VALUEUse SQL IKM append control
Interface 2:
"Put a filter in your 1 on attr.name = array ' PROVIDER '.
In the map target TABLE2
SERVICE_ID = TABLE1. SERVICE_ID
PROVIDER = TABLE1. ATTR_VALUEDo SERVICE_ID as KEY (when you click the column target in properties, you can see KEY under properties of the target column) and use the incremental update of the IKM Oracle.
PS: I assume that Oracle as the source and target.
And you can refer to the documentation,
https://Apex.Oracle.com/pls/Apex/f?p=44785:24:4413167952886630:no:24:P24_CONTENT_ID, P24_PREV_PAGE:5185, 29
http://odiexperts.com/
And of course this OTN.
Thank you
Guru -
Hello
I'm trying to achieve the following objectives:
1. in table A, select rows based on the values in column 2. something like SELECT * FROM TABLE A WHERE (COLUMN2 = 'X' or Column2 IS NULL)
2 and these values selected, I want to update Column3 from Table A if TableA.column1 = TableB.column1, but only if there is exactly one game. If there are multiple matches, column 3 of the table article updated.
That's what I've tried so far.
UPDATE TABLE_A
SET
TABLE_A.COLUMN3 = (SELECT COLUMN3 OF TABLE_B
WHERE ((TABLE_B.COLUMN1 = TABLE_A.COLUMN1) AND ( TABLE_B.COLUMN1 IN (SELECT Column1 FROM TABLE_B GROUP BY COLUMN1 , HAVING COUNT (*) = 1)))
WHERE EXISTS (SELECT * FROM TABLE_A)
WHERE ((TABLE_A.COLUMN2 = 'X' OU TABLE_A.COLUMN2 = 'Y') AND (TABLE_A.COLUMN4 IS NULL OR TABLE_A.COLUMN4 = ' ')));
More details on my DB environment:
Version Info:
Oracle Database 11 g Enterprise Edition Release 11.2.0.4.0 - 64 bit Production
PL/SQL Release 11.2.0.4.0 - Production
Toad, but, depending on whether the query updated all lines. I would really appreciate if someone could tell me how to fix my request.
Thanks in advance.
Exists it predicate in the block of update will be set to true if there is at least one row in table_a where column2 is X or Y and column4 is null or a space. You need to correlate exists it with the outer query query (I'm guessing on column1) to get the result I think you want. However, who would update all rows in table_a who meets the criteria, there is a corresponding row in table_b, affecting Column3 lines form null not matched or not. (Again), I'm guessing that's not your intention. If you only want to update the lines in table_a which have a corresponding line in table_b and meet the other predicate, then I think you want something more like:
Update table_a
Set table_a.column3 = (select column3 of table_b
where table_b.column1 = table_a.column1 and
Table_B.Column1 in (select column1 from table_b
Group by column1, having count (*) = 1))
where ((table_a.column2 = 'X' ou))
table_a.Column2 = 'Y') and
(table_a.column4 is null or)
table_a.column4 = ' ')) and
table_a.Column1 in (select column1 from table_b
Group by column1, having count (*) = 1)
John
-
Update trigger that inserts the record in another table
I searched the forum and the web for an example like this and I can not find a:
A field is updated in the TABLE_A and it triggers a single record TABLE_B insert that has the old and the new value of the field.
I write a lot of complex data warehouse SQL-based reports, but very rarely do much PL/SQL, any help would be appreciated.
Thanks in advance.Hello
You can specify that the trigger should fire only when certain columns are referenced, like this:
create or replace trigger test_fund_trig before update OF FUNDING on table_a ...
If you do this, the trigger will not draw on statements such as:
UPDATE table_a SET mod_date = SYSDATE;
You should always use an IF statement, as I mentioned earlier, if you do not want to follow the updates where the value of this column has not really changed.
-
Update of data based on records in another table
I have 2 tables
Table 1
Name Date of article
Jon apples 2013/06/11 00:30:00 hrs
Sam Oranges
NISH applesTable 2 - Net number
Number of name components
NISH apples 10
NISH Oranges 17
NISH banana
Sam 10 apples
Sam Oranges 1
Sam bananas 1
Jon potatoes 8I need to create a job that checks the table 1 for new records added after the last race and then add the count in table 2 accordingly.
Please guide on how to do this using the PL/SQl or something similarYou need a third table where you store the time stamp of the last execution or an additional field in table 1 which indicates if a record has been processed already. (or the Date column has this information?).
Then he must know if all possible combinations of the name and are already in Table2. If so, a simple update would do the job. If this isn't the case, you should take a look at the merge statement:
http://docs.Oracle.com/CD/B28359_01/server.111/b28286/statements_9016.htm
Good bye
DPT
Maybe you are looking for
-
HP Notebook PC QE339UA #AB 2000: number of portable 2000 HP
Hi all I'm having a problem with my laptop HP 2000. It gives me the Windows startup error (status 0xc000000f) And I don't have the recovery partition in my computer. I need a cheaper way to get this laptop. I do not need the data on this computer an
-
Win 7 activate problem BIOS installed at the factory to operate non-vista 0xc004f035
A laptop g62 b10st is purchased for a scientific research project. I can use the University a license Windows 7. BIOS Insyde installed non-vista. I can't activated Win 7 via key Service Manager license. 0xc004f035 error code
-
How to put across a 4-20mA signal
Hello First of all, I don't know where to look for so that I could be in the wrong place. If someone could help me find a way or a manual, would be great. I have a cRIO with 9203 module receive a signal 4-20ma with a flow meter. I added the cRIO in L
-
don't know what to do
-
My cam was working then it stoped.my cam is built in