Question on Updating the rows of a table using a SELECT Statement
Hi,
I am trying to set all of the R_IDs in one table to the ID from another table using a join.
Here is the SQL I came up with. I don't this is correct though.
UPDATE TABLEA A
SET R_ID=(Select Id from TABLEB B
WHERE A.DEE=B.DEE AND
B.RNUM=1);
Does this make sense?
You can try the join view.
UPDATE ( SELECT table_a.id AS a_id,
table_b.id AS b_id,
table_a.col1 AS a_col1,
table_b.col1 AS b_col1,
table_a.col2 AS a_col2,
table_b.col2 AS b_col2,
table_a.col3 AS a_col3,
table_b.col3 AS b_col3
FROM table_a,
table_b
WHERE table_a.id = table_b.id)
SET a_col1 = b_col1,
a_col2 = b_col2,
a_col3 = b_col3;
However it may result in
ORA-01779: cannot modify a column which maps to a non key-preserved tableThis is because the key-preserving property of a table does not depend on the actual data in the table. It is, rather, a property of its schema. For example, if in table_b there was at most one record for each id value, then table_a.id would be unique in the result of a join of table_a and table_b, but table_a would still not be a key-preserved table. By adding the unique/primary key on the id column of table_b we can assure that if table_b.id were part of the result set of the join view then it would be unique. This makes table_a key preserved.
Thus, in order to update a join view we must assure that the columns involved in the join view from the source table are unique. We do this by creating a unique or primary key on those columns.
However, if you do not mind taking responsibility for making sure that there is one-to-one cardinality between the source and destination rows, then you might try the correlated subquery
UPDATE table_a
SET (col1, col2, col3 ) =
( SELECT col1, col2, col3
FROM table_b
WHERE table_b.id = table_a.id )
WHERE EXISTS
( SELECT col1, col2, col3
FROM table_b
WHERE table_b.id = table_a.id )
Similar Messages
-
How to update the data in sqlserver table using procedure in biztalkserver
Hi,
Please can any one answer this below question
how to update the data in sqlserver table using procedure in biztalkserver
while am using executescalar,typedprocedure getting some warning
Warning:The adapter failed to transmit message going to send port "SendtoSql1" with URL "mssql://nal126//MU_Stage2?". It will be retransmitted after the retry interval specified for this Send Port. Details
Please send me asap....
Thanks...Hi Messip,
A detailed error would have helped us to answer you more appropriately but
You can follow the post which has step by step instructions, to understand how to use Stored Procedure:
http://tech-findings.blogspot.in/2013/07/insert-records-in-sql-server-using-wcf.html
Maheshkumar
S Tiwari|User
Page|Blog|BizTalk
2013: Inserting RawXML (Whole Incoming XML Message) in SQL database -
Updating a row of a table using rowid
Hi folks,
I am trying to update some rows in a table using rowid of the corresponding rows.Sometimes this updates wrong rows. This is because ORACLE by itself makes some statistics on the particular table using "Analyze table..." statement and it changes the order of the rowids. But if I delete the statistics,the updation works fine. Is there any way to update the correct rows and also to keep the statistics created by ORACLE? P.s: I am using ORACLE thin Driver to connect to Oracle 8.1.6
Thanks,
Karthi.First make it clear: analyze table command never changes ROWIDs. Actually, the ROWID of a row never changes untill it's deleted from its table. So make sure if you are using the correct ROWID.
Thnx -
How to join THREE different tables into internal table using one select statement .
How to join THREE different tables into internal table using one select statement .
Hi experts,
I would like to request your guidance in solving the problem of joining the data from three different database tables into one internal table
Scenario:
Database tables:
SPFLI
SFLIGHT
SBOOK.
Table Fields:
SPFLI - CARRID CONNID COUNTRYFR CITYFRM COUNTRYTO CITYTO
SFLIGHT - CARRID CONNID FLDATE SEATSMAX SEATSOCC SEATSMAX_C
SEATSOCC_C SEATSMAX_F SEATSOCC_F
SBOOK - CARRID CONNID CLASS
MY INTERNAL TABLE IS IT_XX.
Your help much appreciated.
Thanks in advance.
Pawan.Hi Pawan,
please check below codes. hope it can help you.
TYPES: BEGIN OF ty_xx,
carrid TYPE spfli-carrid ,
connid TYPE spfli-connid ,
countryfr TYPE spfli-countryfr,
cityfrom TYPE spfli-cityfrom ,
countryto TYPE spfli-countryto,
cityto TYPE spfli-cityto ,
fldate TYPE sflight-fldate ,
seatsmax TYPE sflight-seatsmax ,
seatsocc TYPE sflight-seatsocc ,
seatsmax_b TYPE sflight-seatsmax_b,
seatsocc_b TYPE sflight-seatsocc_b,
seatsmax_f TYPE sflight-seatsmax_f,
seatsocc_f TYPE sflight-seatsocc_f,
class TYPE sbook-class,
END OF ty_xx,
t_xx TYPE STANDARD TABLE OF ty_xx.
DATA: it_xx TYPE t_xx.
SELECT spfli~carrid
spfli~connid
spfli~countryfr
spfli~cityfrom
spfli~countryto
spfli~cityto
sflight~fldate
sflight~seatsmax
sflight~seatsocc
sflight~seatsmax_b
sflight~seatsocc_b
sflight~seatsmax_f
sflight~seatsocc_f
sbook~class
INTO TABLE it_xx
FROM spfli INNER JOIN sflight
ON spfli~carrid = sflight~carrid
AND spfli~connid = sflight~connid
INNER JOIN sbook
ON spfli~carrid = sbook~carrid
AND spfli~connid = sbook~connid.
Thanks,
Yawa -
How to get the value from a function using a select statement
I have a function(user defined not built in) that returns multiple values(like an array). My question is how do i get those values in a select statement. when i tried to retrieve it,
select pack.my_members from dual;
i am getting an error
ORA-00902: invalid datatype
I am sure this must be a syntax error with the select statement
The following is the function that give the array of data
package pack
package spec
Type my_table is table of varchar2(25);
function the_members
return pack.my_table;
pakcage body
function the_members return pack.my_table
Remarks: This function returns a table containing names of the
members
is
tm pack.my_table:= pack.my_table('first member','second member','third member','fourth member');
begin
return tm;
end the_members;Check this example on Pipelinedfunction
-
Can we update The extended VBPA database table using BAPI
Hi,
We have a table VBPA appended with two fields start date and end date. Our scenario is to when modifying the sales order using the bapi BAPI_SALESORDER_CHANGE we need to update the two fields star_date and end_date of VBPA table for the corresponding Ship to or Sold to partner for the Given Sales Order.
Thanks,
Venkat.Hi,
YES You can, You should be updating this to fields using a BAPI - "BAPI_SALESORDER_CHANGE" and use table user this BAPI "EXTENSIONIN" to update this fields. Refer to BAPI documentation for more reference. Please check below code which was done for VBAK (2 date fields).
Regards,
Tim
DATA:
ZBAPISDH1 TYPE BAPISDH1,
ZBAPISDH1X TYPE BAPISDH1X,
ZEXTENSIONIN TYPE TABLE OF BAPIPAREX WITH HEADER LINE,
BAPE_VBAK TYPE BAPE_VBAK,
BAPE_VBAKX TYPE BAPE_VBAKX.
ZBAPISDH1X-UPDATEFLAG = 'U'.
BAPE_VBAK-VBELN = P_VBELN.
BAPE_VBAK-ZZSD_FROM = P_START.
BAPE_VBAK-ZZSD_TO = P_END.
BAPE_VBAKX-VBELN = P_VBELN.
BAPE_VBAKX-ZZSD_FROM = CO_X.
BAPE_VBAKX-ZZSD_TO = CO_X.
ZEXTENSIONIN-STRUCTURE = 'BAPE_VBAK'.
ZEXTENSIONIN-VALUEPART1 = BAPE_VBAK.
APPEND ZEXTENSIONIN.
CALL FUNCTION 'BAPI_SALESORDER_CHANGE'. -
Create a counter for the rows in a table using script editor?
Hi ,
I want to add afield in a particular table with first field is its serial number . How to use scripting editor to fill the serial number ?
How to create a counter ?
Edited by: Rajan.Dexter9 on Jan 30, 2012 9:40 PMHello Rajan,
Create a field in the table and name it as 'SERIAL'. Create a variable called 'count' with default value as 0. Now in script editor, for javascript language and calculate event, write the following script.
var fields = xfa.layout.pageContent(xfa.layout.page(this)-1, "field", 0);
for (var i=0; i <= fields.length-1; i++)
if (fields.item(i).name == "SERIAL")
count.value = count.value + 1;
this.rawValue = count.value; -
How to Update Particular row in a table from OAF page
Hi Can anyone please help me on the following requirement:
In my oaf page i am displaying table values(supplier site details from base tables) with update and delete icons . When i click on update button a new page opens in which we used to update the values and click on apply button which again comes back to the original page.
So when i click on apply button on update page i have to first search for the site in the site table whether it exists or not, if not exists i have to create a new row and save the data, if site exists in the table i have to update the row of a table for that particular site. I have written code for this but unable to achive the requirement, it is not updating the existing row of the table. And i am doing all this on the Temp tables.
So now when i save, previous transaction is also updating along with the current transaction. That means when i m trying to save 2nd transaction values , 1st transactions values are getting updated with the 2nd transaction values(2 rows are getting updated)
Can anyone help me with the code used for updating the current row of the table. Please correct me if i m doing anyting wrong in code.
following is the current code i m using and which is failing :
Controller Code
if(pcontactaction.equals("createECdetailsEvent")) {
String currentSiteName=pageContext.getParameter("SiteName");
System.out.println("Selected Site Name is : " + currentSiteName);
Serializable x[]={reqNum,suppId,currentSiteName,pnotifMethod,pfaxNum};
System.out.println("Invoking AM Method.........");
am.invokeMethod("initCreateECDetails",x);
System.out.println("initCreateECDetails Method Executed. ");
//am.invokeMethod("save");
localOAApplicationModule.getTransaction().commit();
pageContext.setForwardURL(
"OA.jsp?page=/oracle/apps/floaf/flpos/supregister/webui/ECDetailsPG"
, null //not needed as we are retaining menu context
,OAWebBeanConstants.KEEP_MENU_CONTEXT
, null //not needed as we are retaining menu context
,null // no parameters are needed
,true //retain AM
,OAWebBeanConstants.ADD_BREAD_CRUMB_NO
,OAWebBeanConstants.IGNORE_MESSAGES);
AM Code
public void initUpdateECDetails(String request_number,String supplier_id,String site_name,String site_id,String notification_method,String fax_number)
OADBTransaction localOADBTransaction = getOADBTransaction();
String siteToUpdate;
siteToUpdate=site_name;
String siteidToUpdate;
siteidToUpdate=site_id;
System.out.println("Site Name to Update or Create is : " + siteToUpdate);
System.out.println("Site Id to Update or Create is : " + siteidToUpdate);
System.out.println("Inside Update EC Details MEthod.");
OAViewObject suppSiteDetVO = getFLPOSSuppSiteDetailsVO1();
FLPOSSuppSiteDetailsVORowImpl sro=null;
String existingWhereClause = suppSiteDetVO.getWhereClause();
suppSiteDetVO.setWhereClause(null);
suppSiteDetVO.setWhereClauseParams(null);
suppSiteDetVO.setWhereClause("SUPPLIER_ID = :1 AND REQUEST_NUMBER = :2 AND SITE_ID = :3 ");
suppSiteDetVO.setWhereClauseParam(0, supplier_id);
suppSiteDetVO.setWhereClauseParam(1, request_number);
suppSiteDetVO.setWhereClauseParam(2, site_id);
suppSiteDetVO.executeQuery();
suppSiteDetVO.setWhereClauseParams(null);
suppSiteDetVO.setWhereClause(existingWhereClause);
int rowcount = suppSiteDetVO.getRowCount();
System.out.println("Fetched Rows : " + rowcount);
if (rowcount == 0) {
Row row = suppSiteDetVO.createRow();
System.out.println("Row is : " +row);
suppSiteDetVO.insertRow(row);
String siteId = getOADBTransaction().getSequenceValue("FLPOS_SITE_ID_SEQ").toString();
System.out.println("New Site ID : " + siteId);
row.setNewRowState(Row.STATUS_INITIALIZED);
row.setAttribute("RequestNumber", request_number);
row.setAttribute("SupplierId", supplier_id);
row.setAttribute("SiteName", site_name);
row.setAttribute("SiteId", siteId);
row.setAttribute("FaxNo",fax_number);
row.setAttribute("NotificationMethod",notification_method);
System.out.println("New Row Created for Supplier Site.");
System.out.println("Data Saved to table.");
else{
System.out.println("Inside Else Block ");
try {
System.out.println("Inside Try Block ");
Row[] row = suppSiteDetVO.getAllRowsInRange();
for (int i = 0; i < rowcount; i++) {
sro = (FLPOSSuppSiteDetailsVORowImpl)row;
String psiteName=sro.getSiteName();
Number psiteid=sro.getSiteId();
System.out.println(" p Site Name is : " +psiteName);
System.out.println(" p site id is " +psiteid);
if(psiteid.equals(siteidToUpdate) ) {
sro.setAttribute("FaxNo",fax_number);
sro.setAttribute("NotificationMethod",notification_method);
//getOADBTransaction().commit();
break;
catch (Exception e) {
System.out.println("Exception in update : " + e);
}Please answer following:
1. Are you using EO based VOs or ReadOnly VO?
2. What is your VO Query for the search and update?
3. Why have you based your logic on site_name; you should have used site_id?
4.Are you getting correct site name in handling createECdetailsEvent event in CO?
5. In case of update are you getting correct values on the Update Site Details?
6. On coming back from Update page to Supplier Site Search page, do you see old values of the site or the new values in the results table?
Please share the screenshot if possible.
-Prince
[email protected]
http://princekapoor82.blogspot.com -
Need help in SQL Query: Update a row in a table & insert the same row into another table
I want to update a row in a table say Table A and the updated row should be inserted into another table say Table B. I need to do it in a single SQL query and i don't want to do it in PL/SQL with triggers. And i tried with MERGE statement but its working with this scenario. (Note: I'm using Oracle Database 10g Enterprise Edition Release 10.2.0.1.0).
Thanks in Advance.Using Sven's code as an example, you could save the updated row in a sql plus variable. (also untested):
SQL> var v_id number
update tableA
set colB='ABC'
where colC='XYZ'
returning id into :v_id;
insert into table A_History (ID, colA, colB, ColC)
select id, ColA, ColB, ColC
from tableA
where id = :v_id; -
Best way to update individual rows of a Table?
I've taken a look at some examples, though haven't gotten any clarification on this. I am looking to have something close to a listbox or table to where I can update just a single column of row values at a 1 time per second pace. I am looking to display our data-acquisition values in a table or listbox. The single listbox seemed to work good for this, but I was unable to use row headers to list the channel names next to the channel values. I was thinking about connecting the cursor values of two list-boxes to do this, but didn't find any info on this for the single list-box.
I have a few questions:
1) I have a 1D array to where I want to use that array of data to constantly update the first column (with a multitude of rows) of a table. I am looking for the best route so as not to take up too much processing time in doing this.
What is the best way to update individual rows of a table? Invoke Node "Set Cell Value" ... or is there another method?
2) Why is it that after every other iteration the row values are erased?
Also, for adding additional strings to the original arrray ... is it best to use the "Array Subset" and then the "Build Array" function, or the "Array Subset" and "Insert Into Array" function?
See the attached example.
Thanks.
Solved!
Go to Solution.
Attachments:
Table Example.vi 19 KBJeff·Þ·Bohrer wrote:
2) Why is it that after every other iteration the row values are erased?
Classic race condition. dump the for loop and p-node and just wire the 2D array to the table terminal.!
I'm not seeing the race condition. What I am seeing is the table emptying after the last element was written to it on every other run. I saw watched this with highlight execution on.
But I'm in full agreement with just writing to the terminal. It is a 1D array, so you will need to use a build array and transpose 2D array in order for it to write properly.
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines -
Update all rows in a table which has 8-10 million rows take for ever
Hi All,
Greetings!
I have to update 8million rows on a table. Basically have to reset the batch_id with the current batch number. it contains 8-10 million rows and i have tried with bulk update and then also it takes long time. below is the table structure
sales_stg (it has composite key of product,upc and market)
=======
product_id
upc
market_id
batch_id
process_status
I have to update batch_id,process_status to current batch_id (a number) and process_status as zero. I have to update all the rows with these values for batch_id = 0.
I tried bulk update an it takes more than 2hrs to do. (I limit the update to 1000).
Any help in this regard.
Naveen.The fastest way will probably be to not use a select loop but a direct update like in William's example. The main downside is if you do too many rows you risk filling up your rollback/undo; to keep things as simple as possible I wouldn't do batching except for this. Also, we did some insert timings a few years ago on 9iR1 and found that the performance curve on frequent commits started to level off after 4K rows (fewer commits were still better) so you could see how performance improves by performing fewer commits if that's an issue.
The other thing you could consider if you have the license is using the parallel query option. -
URGENT:Update multiple rows of a table as a transaction
Hi,
I am trying to update mutliple rows in one table as a transaction, but only update on the last row is commited to database. Updates on the previous rows is not committed.
I must be missing some thing which is obvious. Has any got a clueeeeeeeeeee?
code:
for (int i = 0; i < selectedFaultNumbers.length; i++) {
String nationalFaultNumber = selectedFaultNumbers;
String fault = nationalFaultNumber.substring(0,13);
national_faultsRowSet2.setCommand("SELECT national_faults.national_fault_number, national_faults.status_id, national_faults.master_fault_number FROM national_faults WHERE national_faults.national_fault_number= '"+fault+"'");
national_faultsRowSet2.execute();
if (national_faultsRowSet2.next()) {
national_faultsRowSet2.updateInt("status_id", FAULT_STATUS_ASSOCIATED);
national_faultsRowSet2.updateString("master_fault_number",nationalfltno);
national_faultsRowSet2.updateRow();
national_faultsRowSet2.execute();
Any help wil be GREATLY appreciated.
Cheers
kushHi Giri,
Thanks for getting back to me.
If I understood correct, sample example updates a rowset which is bound to datatable and changes are committed to database using datatablemodel.
In my case rowset is not bound to a datatable and user is not updating the rowset.
PageBean has to update few rows in a table when a new row is inserted in to that table.
Please correct me if I got it wrong. Is there any other solution ???
Thanks very much
kush -
Updating multiple rows in a table in ADF
Hi
How do we update multiple rows in a table.
Onclicking a update button the changed rows must be updated.Hi Prince,
currently I am selecting one row from the table and rendering a region at the top of the table and capturing the user entered data with the following code:
ViewObjectVOImpl vo = getViewObjectVO1();
Row CurrentRow = vo.getCurrentRow();
//After this I perform the checks like user entered value is not null or check input as per business logic.
if(CurrentRow.getAttribute("attributeName") ==null){
//Add what message you want to display
//Add other business logic.
After making all the checks, i commit it.
getOADBTransaction().commit();
Now in my new page I am capturing the user input in the table itself like an excel sheet. Suppose there are ten rows in my advanced table on my page, and each row has one editable field. I have one save button at the bottom of the table.
Now on clicking the save button I have to capture the user input, check whether there is any null value and if all the entered data is correct then only I should commit it.
Can you please let me know how we can accomplish that.
Regards
Hawker -
Counting all the rows in a table
I've just come across what I think is a big oversight in the Power Query UI: it doesn't seem to be possible to find the total number of rows in a table using just the functionality available in the UI. I can do this very easily if I write my own expression
using Table.RowCount(), but I would have expected to be able to do this through the UI. At the moment, when I go to the Group By dialog (which is where I'd expect to be able to do this) and delete all the columns in the Group By section the OK button gets
greyed out.
Am I missing something here?
Chris
Check out my MS BI blog I also do
SSAS, PowerPivot, MDX and DAX consultancy and run
public SQL Server and BI training courses in the UKHi Miguel,
No, what I was talking about was to be able to use the Group By dialog and have no column to group by - that's to say, I'd just want to be able to count the number of rows in a table (or return the sum of all values in a column, or the min/max etc) and return
a single value. I know I could do this by inserting an artificial column that only contains one distinct value, and using that in the Group By, or by writing my own expression that uses Table.RowCount(), but it seems like a very basic operation that should
be easier to do in the UI.
Chris
Check out my MS BI blog I also do
SSAS, PowerPivot, MDX and DAX consultancy
and run public SQL Server and BI training courses in the UK -
How to Update the statistics of a table
Dear Experts,
I want to update the statistics of a table D010INC table.How can i update it.
Plz provide me detailed steps.
Regards,
Farook.
Edited by: farook shaik on Dec 15, 2008 1:04 PMcheck this SAP help
http://help.sap.com/saphelp_nw04/Helpdata/EN/df/455e97747111d6b25100508b6b8a93/content.htm
Maybe you are looking for
-
Export Audio to Movie - where is that function in Logic 9?
I have noticed that a very useful function in my Logic Pro 8 (version 8.0.2) options/movie/export audio to movie is not found in the Logic 9 version. One of my friends has this version (and an Intel Mac) but I cannot help him working with music and v
-
Change Display In "Open" Dialog??
Hi ... Brand new here. Hope you guys can point me in the right direction. I'm using Adobe 9. When I open a file, all the files in the directory are displayed in "List" mode. Is there a way to make the box display them in "Details" mode?? I understand
-
22 inch LaCie Blue II to new iMac - possible?
I have a new 21" iMac and an old 22 inch LaCie Blue II computer Monitor that I'd like to add as a second monitor because I like the tonal quality for print - is it possible? Will I be able to span or is the old LaCie to slow? Thanks Chris
-
How to print a gift return label if only know the return number and order number
I have a macbook pro, it's a gift, and I want to return it. But at first time, I forgot to print the return label, now I know the order number and return number, when I click "Print return label", it appeared I need to sign in, but I don't have a app
-
LDB PSJ Selection field CN_ACTVT problem.
Hi Guys, I recently discovered that in LDB PSJ selection field CN_ACTVT is empty in the program, if program runs in background. Do any body know the work around, so that values are passed into program from the LDB selection screen to the program. Tha