Update multiple columns from multiple tables in a single UPDATE request
Hello
I'm trying to figure if I'm heading in the right direction.
I want to update multiple columns from multiple tables in a single UPDATE request. Also, I would like to update multiple columns in a table from the tables.
Scenario 1
UPDATE Table2, Table 3 SET T2.Column1 = T1.Column1 ,T2.Column2 = T1.Column2 ,T3.Column2 = T1.Column2 FROM Table1 T1, Table2 T2, Table3 T3 WHERE T1.id = T2.id and T1.id = T3.id
Scenario 2
UPDATE Table3 SET T3.Column1 = T1.Column1 T3.Column2 = T1.Column2 ,T3.Column3 = T2.Column3 ,T3.Column4 = T2.Column4 FROM Table1 T1, Table2 T2, Table3 T3 WHERE T3.id = T1.id and T3.id = T2.id
Hello
For scenario 1, you must write separate instructions UPDATE table2 and table3.
To guard against someone else change one of these tables while you act so you can copy all relevant data in a global temporary table and update this global temporary table table3.
ENGAGE only when two tables have been changed.
You can write a procedure or an INSTEAD OF trigger to do all this.
For scenario 2, you can reference many tables that you need when new table3. It might be more efficient and simpler to use the MERGER rather than UPDATED. For example:
MERGE INTO table3 dst
WITH THE HELP OF)
SELECT t1.id
t1.column1
t1.column2
t2.column3
t2.column4
FROM table1 t1
JOIN table2 t2 ON t1.id = t2.id
) src
WE (dst.id = src_id
WHEN MATCHED THEN UPDATE
SET dst.column1 = src.column1
dst.column2 = src.column2,
dst.column3 = src.column3,
dst.column4 = src.column4,
;
Tags: Database
Similar Questions
-
histogram with just a few columns from a table
I want to get a histogram of a few columns from a table (4 - 6-... 22)
-
How to remove a column from a table in a dell identtiymananger 7.0
How to remove a column from a table in a dell identtiymananger 7.0
Hello
In Version 7 of the removal of a single custom column can be accomplished by a stored procedure, available in the database called: QBM_PColumnDrop
Hope that helps.
Cordially Fatih
-
Explicit cursor, column from several tables in a variable
Here's the situation. This DB has tables of metadata. An example of table name would be g3e_attribute. Once you insert a record in a metadata table a trigger of executions insert and insert records in the g3e_attribute_0009 table (table of language, this is what I call it). It would insert in g3e_attribute_000C is the default language is the French. There is also a delete trigger so that if you delete a record in a table of metadata it deletes the corresponding language table. Well, somehow we have entered the language tables that are not in the metadata table. A problem with the system.
There are 139 tables of language so I prefer not to do it manually.
So I'm keen to make this code
delete < table language > where < primary > not in (select < primary > in < metadata table >).
So I need to loop through the table and and the corresponding primary keys.
I have this code to get the table names
Select table_name, substr (table_name, 0, (length (table_name)-5)) in all_tables where table_name like 'G3E_ % _000% ';
This will display both the language metadata tale table names and.
The table of language with either _0009 or _000C as a suffix, I take everything but the last 5 characters to get the table metadata.
And I have the code to find the primary key of the table.
SELECT column_name FROM ALL_CONS_COLUMNS A JOIN ALL_CONSTRAINTS C ON A.CONSTRAINT_NAME = C.CONSTRAINT_NAME WHERE 'G3E_LEGENDENTRY' AND C.CONSTRAINT_TYPE = C.TABLE_NAME = 'P ';
So I just need to loop through all the tables. Put these pieces together, that's where I encountered a problem. I started to do a procedure, but I ran into a problem.
When you loop, you move the record being the explicit cursor in a variable. Well, you can set the variable as a vertain column type (%), or type (%ROWTYPE) of the line. Although the sql I use to create the cursor takes columns from multiple tables and returns three columns. So I'm not sure how ot define the variable. The only work around I found was to make a table column_name that contains the table table,. Define the variable as rowType.
Is there an easier way to do this?
Thank youA couple of points.
You should not really mix ansi joins and joins in the place where clause. Choose a style and stick to it.
You can't do the DDL directly in pl/sql. You need to do this, use dynamic sql. something like:
create or replace PROCEDURE SYNC_LANGMETATABLES AS CURSOR c_TABLE_PRIMARY IS select D.table_name, substr(D.table_name,0,(length(D.table_name)-5)), column_name from all_tables D, JOIN ALL_CONSTRAINTS C on C.TABLE_NAME = D.TABLE_NAME join ALL_CONS_COLUMNS A ON A.CONSTRAINT_NAME = C.CONSTRAINT_NAME where D.table_name like 'G3E_%_000%' AND C.CONSTRAINT_TYPE = 'P'; v_LANGTABLE ALL_TABLES.TABLE_NAME%TYPE; v_METATABLE ALL_TABLES.TABLE_NAME%TYPE; v_PRIMKEY ALL_CONS_COLUMNS.COLUMN_NAME%TYPE; BEGIN OPEN c_TABLE_PRIMARY; LOOP FETCH c_TABLE_PRIMARY INTO v_LANGTABLE,v_METATABLE,v_PRIMKEY; EXIT WHEN c_TABLE_PRIMARY%NOTFOUND; execute immediate 'delete from '||v_langtable||' where '||v_PRIMKEY|| ' NOT IN(SELECT '||v_PRIMKEY||' FROM v_METATABLE)'; END LOOP; CLOSE C_TABLE_PRIMARY; END;
John
-
Hi Experts,
I have a DB table has columns of more than 50.
I question this table, it should only return one line at any time. as sqldeveloper below image.
here, I need to build block pl/sql-query, Discover the column in the table as a key and query result as values.
Eg: Key - Value
TASK_EVENT_ID - 1765
EVENT_TYPE - ASR_UPDATE
... etc until all of the columns in my table.
Experts please comment on that point, appreciate your help on this.
Thank you
-Vincent.
Here is an approach using DBMS_SQL to iterate over the columns of key / value to assign... (Little code snipped for brevity)
create or replace procedure (task_expired)
v_store_id in full,
v_task_action_id in full,
v_job_id in full
)
as
-[SNIP code...]
v_sql VARCHAR2 (4000): = ' select * from my_table where PK = 123'; -Your SQL here!
v_v_val VARCHAR2 (4000);
v_n_val NUMBER;
v_d_val DATE;
v_ret NUMBER;
c NUMBER;
d NUMBER;
col_cnt INTEGER.
f BOOLEAN;
rec_tab DBMS_SQL. DESC_TAB;
col_num NUMBER;
vAsString VARCHAR2 (4000);
BEGIN
-[SNIP code...]
Message_properties. CORRELATION: = "EDF_EVENT";
MSG: = SYS. AQ$ _JMS_BYTES_MESSAGE. Construct();
Msg.set_string_property ('queueName', ' shipping/csi_cth');
Msg.set_string_property ('MODE', 'CR8');
c: = DBMS_SQL. OPEN_CURSOR;
DBMS_SQL. PARSE (c, v_sql, DBMS_SQL. NATIVE);
d: = DBMS_SQL. Execute (c);
DBMS_SQL. DESCRIBE_COLUMNS (c, col_cnt, rec_tab);
1.col_cnt J
LOOP
CASE rec_tab (j) .col_type
WHEN 2 THEN
DBMS_SQL. DEFINE_COLUMN (c, j, v_n_val); -Number
WHEN 12 CAN
DBMS_SQL. DEFINE_COLUMN (c, j, v_d_val); -Date
ON THE OTHER
DBMS_SQL. DEFINE_COLUMN (c, j, v_v_val, 2000); -Else treat as varchar2
END CASE;
END LOOP;
LOOP
v_ret: = DBMS_SQL. FETCH_ROWS (c);
WHEN OUTPUT v_ret = 0;
1.col_cnt J
LOOP
-Fetch each column to the correct data type based on coltype
CASE rec_tab (j) .col_type
WHEN 2 THEN
DBMS_SQL. COLUMN_VALUE (c, j, v_n_val);
vAsString: = to_char (v_n_val);
WHEN 12 CAN
DBMS_SQL. COLUMN_VALUE (c, j, v_d_val);
vAsString: = to_char (v_d_val, ' DD/MM/YYYY HH24:MI:SS');
ON THE OTHER
DBMS_SQL. COLUMN_VALUE (c, j, v_v_val);
vAsString: = v_v_val;
END CASE;
Msg.set_string_property (rec_tab (j) .col_name, vAsString);
END LOOP;
END LOOP;
DBMS_SQL. CLOSE_CURSOR (c);
DBMS_AQ. ENQUEUE (queue_name-online 'cbus.aqjms_common',
Enqueue_options => Enqueue_options,
Message_properties => Message_properties,
Payload-online msg,
Msgid => Message_handle);
dbms_output.put_line ('00 Msgid =' |) Message_handle);
dbms_output.put_line('===Done=');
-[SNIP code...]
END;
/
-
Get columns from the table shown in the iterator
Hello...
I have the table in a collection of standard panel. So, I can show/hide certain columns in the table using the columns in the view menu.
Then I'm trying to do is export to excel (using apache poi) by looping through the table iterator. What I can't do is search if the column is not displayed. I don't want all the columns that are exported without worrying. How can I achieve this?
My bean is similar to the following for loop through the iterator:
BindingContext bindingContext = BindingContext.getCurrent ();
BindingContainer bindingContainer = bindingContext.getCurrentBindingsEntry ();
DCIteratorBinding dcIteratorBinding = (DCIteratorBinding) bindingContainer.get ("EmployeesIterator");
lines [] oracle.jbo.Row = dcIteratorBinding.getAllRowsInRange ();
for (oracle.jbo.Row line: lines) {}
{for (String colName: {row.getAttributeNames ())}
output to excel cell here using row.getAttribute (colName) m:System.NET.SocketAddress.ToString)
}
}
Thank you.
Hello
It's like ask the engine in your car to what colors the seats have. The iterator doesn't know anything about the visible state of a column. If the displayed columns must be determined from the table instance (richeTableau)
The following article solves exactly the requirement that you have: Oracle ADF: Build Your Own it comes with a sample that you can download here: http://www.oracle.com/technetwork/issue-archive/2013/13-jul/o43adf-1940728.zip
Have a look at CustomPanelCollectionBean.java:
The method and code that you want to look for is:
private String getRowHtml (row rw) {}
StringBuffer rowHtmlBuf = new StringBuffer();
Read visible columns in the table of the table instance. This way the
PanelCollection can be used to show/hide columns and exclude
printing to HTML
Table richeTableau = this.getRichTable ();
the list of columns determine the print attributes
The list of columns in
= table.getChildren (); int attrCount = columns.size ();
rowHtmlBuf.append (this.addRowStart ());
for (int i = 0; i)< attrcount;="" i++)="">
for all visible columns, add columns to print
If (((RichColumn) columns.get (i)) .isVisible ()) {}
If (rw.getAttribute (i) instanceof ViewRowSetImpl) {}
ignore the collections of detail used for master/detail example
constraints in British Colombia ADF
} ElseIf (rw.getAttribute (i) instanceof oracle.jbo.domain.Timestamp) {}
shorten date to exclude the infromation times
SimpleDateFormat sdf = new SimpleDateFormat("dd-MM-yyyy");
String dateFormatString = sdf.format (((Timestamp) rw.getAttribute (i)) .getData ());
rowHtmlBuf.append (this.addDataCell (dateFormatString));
} else {}
Prnt attribute values and if sure that null values don't raise a NPE. Add a white character to NULL
attribute values
rowHtmlBuf.append (this.addDataCell (rw.getAttribute (i)! = null? rw.getAttribute (i) m:System.NET.SocketAddress.ToString ():))
" "));
}
}
}
rowHtmlBuf.append (this.addRowEnd ());
Return rowHtmlBuf.toString ();
}
You need to access the Rich Table instance (for example using the JSF component binding) to then compare the attribute in the iterator with the visibility of the column
Frank
-
Correspondence of the columns from one table to another
I have a database column that contains the name of a person. I have another table that has a column that contains the names separated by a comma.
I want to match records where all records of two columns have a corresponding name. I tried this:
< cfquery name = "MyQuery" datasource = "myds" >
SELECT *.
OF TBL_A
WHERE TBL_A.customername IN (#DifferentQuery.ListOfNames #)
< / cfquery >
Everything that I try results in only get a recording. Basically, I want to get all records from a table where one of its columns contains the name of a column in another table.
It's a many-to-many relationship. That is to say an editorial can be linked to many ads, and vice versa. He is best represented with three tables. Such as:
Table: [Editorial] column: [EditorialID (PK), EditorialText,...]
Table: Columns of the [advertiser]: [AdvertiserID (PK), AdvertiserName]
Table: [Editorial_Advertisers] columns: [EditorialID, AdvertiserID]
The name of the advertiser throw himself into a column...
my client can decide which ads get related to which editorials
The third table stores the relationship between ads and editorials. So instead of storing a list of advertisers, you need to insert record for each EditorialID + AdvertiserID combination. You can then use joins to retrieve all the advertisements for EditorialID 123.
SELECT a.AdvertiserName FROM Editorial_Advertiser ea INNER JOIN Advertiser a ON ea.AdvertiserID = a.AdvertiserID WHERE ea.EditorialID = 123
-
Remove the column from the table compress
I try drop column from table DPRUEBA, with compression option:
Any idea?SQL>select * from v$version 2 / BANNER ---------------------------------------------------------------- Oracle Database 10g Enterprise Edition Release 10.2.0.4.0 - 64bi PL/SQL Release 10.2.0.4.0 - Production CORE 10.2.0.4.0 Production TNS for Linux: Version 10.2.0.4.0 - Production NLSRTL Version 10.2.0.4.0 - Production 5 filas seleccionadas. Transcurrido: 00:00:00.09 SQL> SQL>CREATE TABLE DPRUEBA 2 (COL1 NUMBER, 3 COL2 NUMBER) COMPRESS 4 / Tabla creada. Transcurrido: 00:00:00.06 SQL> SQL>ALTER TABLE DPRUEBA DROP COLUMN COL2 2 / ALTER TABLE DPRUEBA DROP COLUMN COL2 * ERROR en línea 1: ORA-39726: operación de agregación/borrado de columnas no soportada en tablas comprimidas Transcurrido: 00:00:00.06
You can always do something like this
SQL> CREATE TABLE DPRUEBA 2 (COL1 NUMBER, 3 COL2 NUMBER) COMPRESS 4 / Table created. SQL> SQL> ALTER TABLE DPRUEBA DROP COLUMN COL2 2 / ALTER TABLE DPRUEBA DROP COLUMN COL2 * ERROR at line 1: ORA-12996: cannot drop system-generated virtual column SQL> SQL> create table new_DPRUEBA 2 as 3 select col1 4 from DPRUEBA 5 / Table created. SQL> SQL> drop table DPRUEBA 2 / Table dropped. SQL> SQL> rename new_DPRUEBA to DPRUEBA 2 / Table renamed. SQL> SQL> desc DPRUEBA Name Null? Type ----------------------------------------- -------- ---------------------- COL1 NUMBER SQL> SQL> SQL> drop table DPRUEBA 2 / Table dropped. SQL> SQL>
Note: you must take care of the constraints and triggers, and others
-
How to remove columns from the table on the master 1-0?
I have an array of 96 columns with strings. I also have the array of int 96-elemets (mask) with 1 and 0.
What I want to do is to is to remove (or hide - but I read that it is not possible) all the columns with index corresponding to 0 in the mask table.
example:
columns in the table
1 2 3 4 5
mask
0 1 0 0 1
I want to remove the columns 1, 3 and 4 and leave only 2 and 5 in my table.
How can I do?
If I create loop for with i as the index of the column, when I do DeleteTableColumns() columns number decreases, and I get an error of range out of
Or do I have an option to hide the unnecessary columns (not set their width to 1, it's very ugly-looking)?
Please help me (())
Hello rovnyart!
1. removal of columns in the table:
I suspect that the reason why you get the out-of-range error is due to fact that in your loop, you delete the columns in the table, you'll eventually end up by referring to a column that no longer exists, because the other columns before it have been deleted. While you remove each column of your table in the loop for example, the column index number will move, because you deleted the other columns in front of her.
To resolve this, even if you delete a column in your loop, make sure that you take also into account that the index of the column is moved because of the removed columns.
2 hide columns in table:
You can use the ATTR_COLUMN_VISIBLE attribute to hide columns in the table:
http://zone.NI.com/reference/en-XX/help/370051Y-01/CVI/uiref/cviattrcolumnvisible_column/
3 alternatives:
Note that another alternative would also use a tree instead, control as the tree control also supports the hidable columns:
http://forums.NI.com/T5/LabWindows-CVI/table-hide-column/TD-p/569773
Best regards!
-Johannes
-
Several lines to a format of columns from two tables
Oracle Database 11 g Enterprise Edition Release 11.1.0.7.0 - 64 bit Production
The difficulty to return several lines simple lines/columns in two tables.
Table 1:
ID BOOK_NBR
1 1001
1 2001
2 1010
3 1020
Table 2:
AUTHOR BOOK_NBR
1001 JOHN_1
2001 JOHN_2
MARY 1010
1020 JUNE
Desired output:
ID BOOK_NBR AUTHOR BOOK_NBR AUTHOR
1 1001 JOHN_1 2001 JOHN_2
2 MARY 1010
3-1020 JUNE
There are an unknown number of BOOK_NBR to one ID.
Any guidance would be appreciated.
-
SQL Ldr-load from multiple files to multiple tables in a single control file
Hello
It is possible to load data from files dishes mutiple at several tables using a control file in SQL Loader? The flat file to database table relation is 1:1. All data from a flat file goes to a table in the database.
I have about 10 flat files (large volume) that must be loaded into 10 different tables. And this must be done on a daily basis. Can I start charging for all 10 tables in parallel and a file command? Should I consider a different approach.
Thank you
SisiWhat operating system? ('Command Prompt' looks like Windows)
UNIX/Linux: a shell script with multiple calls to sqlldr run in the background with '&' (and possibly nohup)
Windows: A file of commands using 'start' to start multiple copies of sqlldr.
http://www.PCTOOLS.com/Forum/showthread.php?42285-background-a-process-in-batch-%28W2K%29
http://www.Microsoft.com/resources/documentation/Windows/XP/all/proddocs/en-us/start.mspx?mfr=truePublished by: Brian Bontrager on May 31, 2013 16:04
-
How to update one column from another table
Hello
We have some sellers who are defined as employees but without employee_id for some reason any. So I would like to update the correct number of a view of HR records. Here is what I tried:
update of po.po_vendors x
Define employee_id = (select apps.per_people_v7 person_id y)
where y.first_name |' '|| y.last_name = x.vendor_name)
Error received: a row subquery returns more than one line.
If I use this instruction to check, I'm correct employee_id or person_id home:
Select apps.per_people_v7 person_id y, po.po_vendors x
where y.first_name |' '|| y.last_name = x.vendor_name
When I checked/compared with some old posts here, I could not just see where I did mistake. Please notify.
Thank you
Ning
Because for the same vendor id, you have a (employee id) id of the person twice in the target table. As Boneist said "fix data, difficulty of the request, fix the requirement...". »
How many sellers are there in your target table?
-
transfer of some columns from one table to another table...?
I had 2 table... .one is PAYMAST n other TBL... In PEXMAST & TBL 10 collar each, I had and I want to transfer 4 columns of TBL to PEXMAST...
How do I do this. ???A table must be regarded as line and column.
When you say a column, it should be associated with a line.
Here is an example
Let's say I have two table T1 (ID, NAME) and T2 (ID, Name1)
Now if I say I want to spend for T2 T1 name1, what I will do?
1 create a column name1 in T1.
alter table t1 add name1 varchar2(50)
2. put up-to-date T1 by joining T1.ID and T2.ID like that.
update t1 set t1.name1 = (select t2.name1 from t2 where t2.id = t1.id)
As you can see you need a column ID to define the relationships between the two table T1 and T2. If you have one, you can do the same with yours.
-
How to delete columns from a table
Hello
I have a 2D chart composed of 12 columns. I want to just use the first three columns within LabView. What is the best way to extract the data from these three columns?
Greetings
Kristoffer
You can watch from two different angles:
- You can remove the extra columns
- You can keep only the fist three columns
Would be easier to use "subset of the table" and select the first three columns. See photo.
(This assumes you want the three columns as a 2D array. If you want in three tables 1 d, you would use 'index array' resized to three exits.)
-
Copy columns from one Table to the other with PL/SQL in Apex
So my goal long-term is to throw this PL/SQL statement in a trial DMBS_SCHEDULER Apex 4.1 to create historical snapshots of the data a week but I'm hooked on this code:
declare
V_DEKIT_ID varchar (255);
V_NT varchar (255);
Number to resume;
Date of V_DDATE;Start
for DEKIT_ID in (select * from DKT_HIST)loop
Select DEKIT. DEKIT_ID in V_DEKIT_ID of DEKIT;
Select DEKIT. NT in DEKIT V_NT;
Select DEKIT. QUANTITY back of DEKIT;
Select CURRENT_DATE in double V_DDATE;insert into DKT_HIST (DEKIT_ID, NT, QUANTITY, DDATE)
values (V_DEKIT_ID, V_NT, V_QUANTITY, V_DDATE);
end loop;end;
I enter this code in the SQL prompt in the SQL workshop and it is said that she is treated, but when I look at the destination table (DKT_HIST), there is no data. Any help would be appreciated. In this code I want to copy the three columns of the DEKIT table as well as the current date and copy them to DKT_HIST for each row in the table DEKIT.
Thank you
-Steve
The reason why your code did nothing is probably because your loop, using the history table. And since there no data in the historical table first, there is nothing to loop.
BUT!
Good code is the task with the least possible effort. Which in your case should result in a code similar to this:
begin insert into DKT_HIST (DEKIT_ID,NT,QUANTITY,DDATE) select DEKIT_ID,NT,QUANTITY, trunc(sysdate) from DEKIT; end;
Maybe you are looking for
-
IT IS A DESKTOP COMPUTER AND WAS WORKING FINE UNTIL 2 DAYS AGO. Thank you. Moved from IE
-
Photosmart all-in-one printer: loss of the network printer connection
My wife has worked with verizon until our internet high speed - it was realized from wep to wpa2 - it has helped our speed but now the printer does not connect to our network eventhough our network name and password are correct. How can I get this fi
-
Original title: units media center update my media center does not work. opening moves the cursor to disappear. tried to download the update day but failed to get a verification code. use 32-bit family vista premium and validator wants xp does not de
-
Will IE9 offered through Windows Update since March 14.
I see that IE9 is released in final version March 14. This means - he will be pushed by WU almost at the same time, or is this just a final version to download manually with WU release planned at a later date?
-
Workspace still does not work with the 4K monitors
I have an Apple Thunderbolt Display Monitor, and I have a Dell 4 K monitor as my secondary monitor. I put all my panels exactly how I'd like, and then I save it as a workspace. If my Dell monitor won't turn on after waking up the Mac Pro to sleep (so