Can I update 2(or multiple) columns in a table based on one of update col?
Hi All,
I have a table emp:
empno number
,salary number
,comm number
Now, the comm column is always a % of the salary column (but still would like to store the comm in the table as a column).
Assuming that someone get a salary increment and I need to update the commission as well based on the new salary value, should I still use 2 update statements or is there anyway, I can achive in a single update clause itself?
example:
if the old values were:
=============
1234 10000 1000
and if I do the following,
update emp
set salary = salary + 3000
,comm = salary * 10/100
where empno = 1234;
the comm value still points to the old salary value and the table looks like:
emp:
===
1234 13000 1000
instead of:
1234 13000 1300 (10% of the new salary - 13000)
so, the only way to achieve this is to issue 2 update statements? Or is there any way of achieving in one single update statement? Please let me know.
Am on Oracle 10.2.0.3.0.
Thanks,
Srini.
Or you could create a after update trigger on salary column that updates comm whenever Sal updates.
What happens if someone else issues an update on salary and forgets to update the commission? Wont you have incorect data then?
Also, commision is a redundant column . I dont think it is a good idea to have computed values as a separate column.
Thanks,
Rajesh,
Similar Messages
-
How to update multiple columns from different tables using cursor.
Hi,
i have two tables test1 and test2. i want to udpate the column(DEPT_DSCR) of both the tables TEST1 and TEST2 using select for update and current of...using cursor.
I have a code written as follows :
DECLARE
v_mydept1 TEST1.DEPT_CD%TYPE;
v_mydept2 TEST2.DEPT_CD%TYPE;
CURSOR C1 IS SELECT TEST1.DEPT_CD,TEST2.DEPT_CD FROM TEST1,TEST2 WHERE TEST1.DEPT_CD = TEST2.DEPT_CD AND TEST1.DEPT_CD = 'AA' FOR UPDATE OF TEST1.DEPT_DSCR,TEST2.DEPT_DSCR;
BEGIN
OPEN C1;
LOOP
FETCH C1 INTO v_mydept1,v_mydept2;
EXIT WHEN C1%NOTFOUND;
UPDATE TEST2 SET DEPT_DSCR = 'PLSQL1' WHERE CURRENT OF C1;
UPDATE TEST2 SET DEPT_DSCR = 'PLSQL2' WHERE CURRENT OF C1;
END LOOP;
COMMIT;
END;
The above code when run says that it runs successfully. But it does not updates the desired columns[DEPT_DSCR].
It only works when we want to update single or multiple columns of same table...i.e. by providing these columns after "FOR UPDATE OF"
I am not sure what is the exact problem when we want to update multiple columns of different tables.
Can anyone help me on this ?oops my mistake.....typo mistake...it should have been as follows --
UPDATE TEST1 SET DEPT_DSCR = 'PLSQL1' WHERE CURRENT OF C1;
UPDATE TEST2 SET DEPT_DSCR = 'PLSQL2' WHERE CURRENT OF C1;
Now here is the upated PL/SQL code where we are trying to update columns of different tables --
DECLARE
v_mydept1 TEST1.DEPT_CD%TYPE;
v_mydept2 TEST2.DEPT_CD%TYPE;
CURSOR C1 IS SELECT TEST1.DEPT_CD,TEST2.DEPT_CD FROM TEST1,TEST2 WHERE TEST1.DEPT_CD = TEST2.DEPT_CD AND TEST1.DEPT_CD = 'AA' FOR UPDATE OF TEST1.DEPT_DSCR,TEST2.DEPT_DSCR;
BEGIN
OPEN C1;
LOOP
FETCH C1 INTO v_mydept1,v_mydept2;
EXIT WHEN C1%NOTFOUND;
UPDATE TEST1 SET DEPT_DSCR = 'PLSQL1' WHERE CURRENT OF C1;
UPDATE TEST2 SET DEPT_DSCR = 'PLSQL2' WHERE CURRENT OF C1;
END LOOP;
COMMIT;
END;
Please let us know why it is not updating by using using CURRENT OF -
How to use a USER_DATASTORE to index multiple columns in different tables
I would appreciate if somebody can give an example or point to links with examples on how to use USER_DATASTORE on multiple columns in different tables. THe Oracle Text documentation only shows multiple columns in the same table.
Thanks in advance.I am not sure why your getting the wrong results but you should seriously reconsider the approach your are taking. Using functions like this is very ineffecient and should be avoided at all cost.
-
Mapping multiple columns of a table to single dimension using odi
Hi John,
Can we map multiple columns of a table to a single dimnesion?
For example, in RDBMS, for the employee details, Grade position etc will be in different columns, and in Planning these would be as members of one dimension.
So while loading data from oracle to essbase can we map these multiple columns to single dimension?
If yes how?Hi,
In your staging area/target you can concatentate the columns.
So in your interface and on your target datastore, pick the column which is going to hold the details of the concatenation.
Then in the expression editor use the CONCAT function, or you could use ||
eg CONCAT(<sourceCol1>, <sourceCol2>)
or <sourceCol1> || <sourceCol2>
obviously you need to change the information between <sourceCol1> to your source datastore column
Cheers
John
http://john-goodwin.blogspot.com/ -
Sort functionality using MULTIPLE columns in a table control
Hi all,
I have a custom screen with table control.Now i need to provide SORT functinality in this screen for the columns in the table control.
My questins:
1.Is it possible to seelct MULTIPLE columns in a table control for SORTING?If yes,what explicit settings do i need to do while creatng the TABEL CONTROL in the screen?DO I need to select "Column selection " as MULTIPLE??
2.How do I write the code for SORT functinonality for multiple columns?
I know how to write the code for SORTING on basis of single column .
Thanks!Hi Rob,
Thanks for the reply.
However I was thinking to apply the same logic as for single columns as follows:
types : begin of ty_fields,
c_fieldname(20),
end of ty_fields.
data : t_fields type table of ty_fields,
wa_fields like line of t_fields.
WHEN 'SORTUP'.(Ascending)
loop at TABLE tc01-cols INTO wa_tc01 where selected = 'X'.
SPLIT wa_tc01-screen-name AT '-' INTO g_help g_fieldname.
wa_fields-c_fieldname = g_fieldname.
append wa_fields to t_fields.
endloop.
describe table t_fields lines l_index.
c_count = 1.
if c_count <= l_index.
read table t_fields into wa_fields index c_count.
case c_count.
when '1'.
l_field1 = wa_fields-c_fieldname.
when '2'.
l_field2 = wa_fields-c_fieldname.
and so on depending on the no of columns in the table control...
endcase.
endif.
SORT t_tvbdpl_scr BY l_fields1 l_fields 2......l_fieldn.
Let me know if the above method will work!Also for the above method to work will the type of fields(columns on whihc sort function will be applied) matter???
Thanks again for your time. -
Can data be sorted by multiple columns in numbers version 3
Since upgrading Numbers to version 3 (now 3.0.1) I have been unable to sort data in spreadsheets using multiple columns. Anyone found a solution?
Regards
kurrajong60Here's a simple example. Say you want this sorted first by Region then by Name then by Amount.
So if you set up a sort index column with a simple formula and all you have to do is this (two clicks):
Giving you this:
Of course you could do it as I think Hiroto is suggesting and manually sort first by column B, then sort by C, then sort by A.
But that's a lot of trouble and it's easy to confuse the order so you end up having to start over again.
SG -
Update 1 column,1 single table based on where results of multiple tables
I would like the my_id column in 1 table updated to the static value of 247 for my_id stored in the 1 single table based on the where clause, which uses the my_id column in it.
The update statement updates all rows in table1, instead of just the rows where
the condition ( (b.my_id=a.my_id)
and ( b.my_name like 'OIS SrClerk%')
and (a.f_id=m.f_id)
and (trunc(m.cr_time) < '02-Apr-2008')) is true
What needs to be changed?
update table1 a
set a.my_id=247
from table1 a, table2 b, table3 m
where
(b.my_id=a.my_id)
and ( b.my_name like 'OIS SrClerk%')
and (a.f_id=m.f_id)
and (trunc(m.cr_time) < '02-Apr-2008')Are you looking for this?
UPDATE table1 A
SET A.my_id = 247
WHERE EXISTS (SELECT 'x'
FROM table2 b,
table3 M
WHERE b.my_id = A.my_id
AND b.my_name LIKE 'OIS SrClerk%'
AND A.f_id = M.f_id
AND TRUNC (M.cr_time) < to_date('02-apr-2008 00:00:00','dd-mon-yyyy HH:MI:SS') )changed date string to to_date
Message was edited by:
devmiral -
Need to update multiple columns using another table
I have 2 tables. and i need to update rows of 1 table using another table
Table1
Serial_no. payment_date Payment_amt
101 22/11/2010 150
101 18/03/2011 355
102 15/04/2011 488
103 20/05/2011 178
102 14/06/2011 269
101 28/06/2011 505
Table2
Serial_no Charge_amt Last_paymt_dt Last_paymt_amt
101 255
102 648
103 475
I want to update Last_paymt_dt and Last_paymt_amt of table2 using Table1, I have written following update statement but it gives error that single row subquery return multiple row.
Update Table2
set (Last_paymt_dt,Last_paymt_amt) = (select max(payment_date, payment_amt) from table1
where table1.Serial_no = table2.Serial_no group by payment_amt)
kindly suggest how should i update.SQL> select * from table1
2 /
SERIAL_NO PAYMENT_DA PAYMENT_AMT
101 22/11/2010 150
101 18/03/2011 355
102 15/04/2011 488
103 20/05/2011 178
102 14/06/2011 269
101 28/06/2011 505
6 rows selected.
SQL> select * from table2
2 /
SERIAL_NO CHARGE_AMT LAST_PAYMT LAST_PAYMT_AMT
101 255
102 648
103 475
SQL> update table2
2 set (last_paymt_dt,last_paymt_amt) = (
3 select max(payment_date),
4 max(payment_amt) keep(dense_rank last order by payment_date)
5 from table1
6 where table1.serial_no = table2.serial_no
7 )
8 /
3 rows updated.
SQL> select * from table2
2 /
SERIAL_NO CHARGE_AMT LAST_PAYMT LAST_PAYMT_AMT
101 255 28/06/2011 505
102 648 14/06/2011 269
103 475 20/05/2011 178
SQL> SY. -
I am unable to sort multiple columns in a table created in Pages.
I had been using Appleworks up until I installed Lion and have now switched to iWork. I created a table within a Pages document and am able to sort a single column (using the Table Inspector and choosing Sort from Edit Rows and Columns) but the Sort option is grayed out when I attempt to sort multiple columns.
In another post, someone talked about this being a problem if you have merged fields. I do not believe I have done this (to be honest I don't know the function of merging fields).
This is very frustrating as I was easily able to sort these tables in Appleworks.Sharon Anderson wrote:
Thanks for your quick response! I have been trying that but then found that Numbers would only let me print in landscape view so I had to paste the table back into Pages. Is there a way to print in portrat view (from Numbers?)
Not so. In the lower left corner of the window, there's an icon that looks like a piece of paper. If you see this:
you are in Sheet View, or normal, mode. If you see this:
You are in Print View mode. Now you see the icons for portrait and landscape modes. Click your choice. Then arrange your content to fit the pages as you wish.
Jerry -
How can I take data from specific column in a table using VBA
Hi
I do not know how to take the values from the last column in a table, I know how to look over each row but I cannot take the last column values for each row I pass by.
This is the table for example:
| Date | Account1 | Account2 | Description | Amount |
|12/03/2008 | 123-32 | 325-78 | None | $50 |
|12/03/2008 | 123-32 | 325-78 | None | $20 |
|12/03/2008 | 123-32 | 325-78 | None | $10 |
|12/03/2008 | 123-32 | 325-78 | None | $40 |
I am using this code as a reference that User FiveNines gave me to loop through all the rows in the table, so What I need is to take the values of the column Amount for each row I go through.
Private Sub RSWVBAPage_afterPlay()
Dim tbl As HTMLTable
Dim tblRow As HTMLTableRow
Dim tblCell As HTMLTableCell
Dim strValue As String
Dim rButton As HTMLInputElement
' ******** This would be your global variable. I put this so that values are seperated by a semicolin you can use what ever format works for you.
strValue = "03/22/2008;03/22/2008;*************1977;*************1977;$25.25;Jan, Jun, Jul, Dec"
' Strip out the ; for inner text comparison
strValue = Replace(strValue, ";", "")
' This will get the table but can be modifoed to be more specific
Set tbl = RSWApp.om.FindElement(, "TABLE")
' This loops through all the rows in the table until a match to the strValue is found
For Each tblRow In tbl.rows
If tblRow.innerText = strValue Then
RSWApp.WriteToLog "Tables", "Passed", "Row is Present", True
End If
Next
End SubHi Lippix.
This is code that will loop the rows then loop the cells and check for "$" which will return dollar values. I also attached a script.
Private Sub RSWVBAPage_afterPlay()
Dim tbl As HTMLTable
Dim tblRow As HTMLTableRow
Dim tblCell As HTMLTableCell
Dim strValue As String
' This will get the table but can be modifoed to be more specific
Set tbl = RSWApp.om.FindElement(, "TABLE")
' This loops through all the rows in the table until a match to the strValue is found
For Each tblRow In tbl.rows
For Each tblCell In tblRow.cells
' cycle through the cells and only report those with a dollar value by searching for $
If InStr(1, tblCell.innerText, "$") <> 0 Then
RSWApp.WriteToLog tblCell.innerText
End If
Next
Next
End Sub -
Why can't i change row and column height in tables?
a mind-boggling problem to be sure. For some odd reason, I can't use the inspector to type in row/column heights for tables. I can use the up/down arrows, but those only work in increments of 1. I can manually adjust them one by one but as soon as I edit text in a different table cell, I have to start all over again. Does anyone else have this problem?
Hi Gerry & Ric
I had already tried both of your suggestions without any luck but I appreciate the help anyway. I should've been a bit more specific: I can actually type in the column/row height windows, but when I press return or tab, Pages ignores the numbers. I've tried using both the number pad and the regular keyboard numbers and every manner of clicking, enter, tab, control, alt......there must be some setting with my computer that is causing an incompatibility with Pages. Boh!
Susie -
Update beans after adding columns to DB tables
I am trying to use JDeveloper 10G , Studio Edition Version 10.1.3.0.4.3673
I am having difficulty finding out how to update CMP Entity Beans
after adding columns to DB tables.
I have found descriptions of how to do these from four sources.
None of these methods work.
They all refer to menu options, buttons or fields that aren't in the JDevb IDE.
List of options that don't exist :
"Synchronize with Database"
"attributes"
"Add from table"
"New from Table"
"Fields Tab"What version of EJBs are you using?
The only option I know of for EJBs will be to generate the bean from the table again, or manually add the field to the EJB.
The "Synchronize with Database" operation is there for ADF Business Components but not for EJBs. -
Where can I find meaings of each column in sys.tables
Command> host ttversion
TimesTen Release 11.2.2.2.0 (64 bit Linux/x86_64) (tt1122:53396) 2011-12-23T09:26:28Z
Instance admin: tttest
Instance home directory: /timesten/TimesTen/tt1122
Group owner: tttest
Daemon home directory: /timesten/TimesTen/tt1122/info
PL/SQL enabled.
Command> desc sys.tables;
System table SYS.TABLES:
Columns:
SYS26 TT_BIGINT NOT NULL
*TBLNAME TT_CHAR (31) NOT NULL
*TBLOWNER TT_CHAR (31) NOT NULL
SYS2 TT_SMALLINT NOT NULL
SYS18 TT_BIGINT NOT NULL
SYS1 TT_BIGINT NOT NULL
OWNER TT_INTEGER NOT NULL
SYS3 TT_INTEGER NOT NULL
SYS33 TT_BIGINT NOT NULL
SYS8 TT_BIGINT NOT NULL
SYS4 TT_SMALLINT NOT NULL
NUMVARY TT_SMALLINT NOT NULL
NUMNULL TT_SMALLINT NOT NULL
NUMCOLS TT_SMALLINT NOT NULL
LENGTH TT_BIGINT NOT NULL
SYS19 TT_BIGINT NOT NULL
SYS20 BINARY (1) NOT NULL
SYS21 BINARY (1) NOT NULL
SYS5 TT_SMALLINT NOT NULL
NUMLOB TT_SMALLINT NOT NULL
SYS65 TT_SMALLINT NOT NULL
SYS6 TT_BIGINT NOT NULL
SYS31 TT_BIGINT NOT NULL
SYS40 TT_BIGINT NOT NULL
SYS41 TT_BIGINT NOT NULL
SYS43 TT_BIGINT NOT NULL
SYS39 BINARY (1) NOT NULL
NUMCOMPRESS TT_SMALLINT NOT NULL
SYS64 TT_INTEGER NOT NULL
SYS7 TT_BIGINT NOT NULL
TBLID TT_BIGINT NOT NULL
NUMTUPS TT_BIGINT NOT NULL
MAXTUPS TT_BIGINT NOT NULL
SYS9 TT_INTEGER NOT NULL
SYS10 TT_INTEGER NOT NULL
SYS29 BINARY (4000) NOT NULL
SYS32 TT_BIGINT NOT NULL
SYS11 TT_BIGINT NOT NULL
PRIMCNT TT_SMALLINT NOT NULL
PRIMCOLS BINARY (32) NOT NULL
SYS22 TT_BIGINT NOT NULL
SYS12 TT_BIGINT NOT NULL
CACHEFLAG BINARY (1) NOT NULL
XLAFLAG BINARY (1) NOT NULL
PXLAFLAG BINARY (1) NOT NULL
SYS16 TT_SMALLINT NOT NULL
CACHEGROUP TT_BIGINT NOT NULL
OCACHEGROUP TT_BIGINT NOT NULL
MVID TT_BIGINT NOT NULL
MVIDS TT_VARCHAR (1024) NOT INLINE
CGFKIDS TT_VARCHAR (8192) NOT INLINE
PERMLTBLID TT_BIGINT NOT NULL
SYS44 TT_INTEGER NOT NULL
CVVERSIONNUM TT_INTEGER NOT NULL
SYS24 TT_SMALLINT NOT NULL
SYS57 TT_SMALLINT NOT NULL
SYS25 TT_INTEGER NOT NULL
REPNUMKEYCOLS TT_SMALLINT NOT NULL
REPTSCOLNUM TT_SMALLINT NOT NULL
REPRETURNSERVICE TT_CHAR (1) NOT NULL
REPRETURNBYREQUEST BINARY (1) NOT NULL
REPUSERID TT_BIGINT NOT NULL
SYS34 TT_INTEGER NOT NULL
SYS35 TT_INTEGER NOT NULL
SYS36 TT_BIGINT NOT NULL
SYS37 TT_BIGINT NOT NULL
REPKEYCOLS BINARY (32) NOT NULL
SYS27 BINARY (240) NOT NULL
REPACCESS TT_CHAR (1) NOT NULL
REPTSUPDATERULE TT_CHAR (1) NOT NULL
SYS45 TT_SMALLINT NOT NULL
SYS46 TT_BIGINT NOT NULL
SYS47 TT_INTEGER NOT NULL
SYS48 TT_INTEGER NOT NULL
SYS49 TT_INTEGER NOT NULL
SYS50 TT_INTEGER NOT NULL
SYS51 TT_INTEGER NOT NULL
SYS52 TT_INTEGER NOT NULL
SYS53 TT_INTEGER NOT NULL
SYS54 TT_INTEGER NOT NULL
SYS55 TT_BIGINT NOT NULL
SYS56 TT_BIGINT NOT NULL
SYS28 BINARY (16) NOT NULL
CACHEDTBLPOS TT_INTEGER NOT NULL
SYS58 TT_SMALLINT NOT NULL
SYS59 TT_SMALLINT NOT NULL
SYS60 TT_BIGINT NOT NULL
SYS61 TT_BIGINT NOT NULL
SYS62 TT_BIGINT NOT NULL
VALTBLIDS VARBINARY (8000) NOT INLINE
SYS63 TT_INTEGER NOT NULL
SYS66 TT_INTEGER NOT NULL
SYS67 TT_BIGINT NOT NULL
SYS68 TT_BIGINT NOT NULL
SYS17 BINARY (32) NOT NULL
1 table found.
(primary key columns are indicated with *)
I searched white book of Timesten11.2, but the columns of sys.tables in it is different from above.
also, in http://docs.oracle.com/cd/E13085_01/doc/timesten.1121/e17114/systemtables.htm#TTSYS379, I can't find it.
Thanks a lot .Why do you need to know this? Is there some specific information you are trying to find?
Note the columns SYS[n] are not and never have been documented. Although they may contain values these are internal to Engineering and not generally made public. There is no guarantee that the use of a SYS[n] column will stay the same between releases as well. -
Query to get the data of all the columns in a table except any one column
Can anyone please tell how to write a query to get the data of all the columns in a table except one particular column..
For Example:
Let us consider the EMP table.,
From this table except the column comm all the remaining columns of the table should be listed
For this we can write a query like this..
Select empno, ename, job, mgr, sal, hiredate, deptno from emp;
Just to avoid only one column, I mentioned all the remaining ( 7 ) columns of the table in the query..
As the EMP table consists only 8 columns, it doesn't seem much difficult to mention all the columns in the query,
but if a table have 100 columns in the table, then do we have to mention all the columns in the query..?
Is there any other way of writing the query to get the required result..?
Thanks..Your best best it to just list all the columns. Any other method will just cause more headaches and complicated code.
If you really need to list all the columns for a table because you don't want to type them, just use something like...
SQL> ed
Wrote file afiedt.buf
1 select trim(',' from sys_connect_by_path(column_name,',')) as columns
2 from (select column_name, row_number() over (order by column_id) as column_id
3 from user_tab_cols
4 where column_name not in ('COMM')
5 and table_name = 'EMP'
6 )
7 where connect_by_isleaf = 1
8 connect by column_id = prior column_id + 1
9* start with column_id = 1
SQL> /
COLUMNS
EMPNO,ENAME,JOB,MGR,HIREDATE,SAL,DEPTNO
SQL> -
How to update all the record for a particular column in a table based on search criteria.
Hi All,
I am new to ADF. I have a requirement, where i have to perform mass update on a table.
Scenario:
Ex: I have a dept manual search region. where i search with deptId: 20. I get 20 records in my table. now i have another region where i have a inputchoice list which contains all the columns names that exists in dept table. Beside that i have a input text box and an update button
Now user, first searches with dept id:20 and clicks on search button, where it shows 20 record in the table. He then select a column from input choicelist(ex: ManagerId), then enters new value in the input box(ex: abc) then clicks on update button.
Now i want, all the records in the ManagerId column with dept id:20 to be updated with the new value "abc"
Can anyone help me with the code.
Thanks in advance..Hi,
If you go to your VO and generate the ViewObjectImpl, in there you can create a method which will contain two parameters, 1 the attribute name and 2 the value.
Then you can follow something like explained in this post:
ADF Tutorial: How to apply bulk actions to a view object rows
The only difference is that you will need to create a method like this:
public void updateAttribute(String attribute, Integer value){
RowSetIterator iter = createRowSetIterator(null);
while (iter.hasNext()){
Row row = iter.next();
row.setAttribute(attribute, value);
Then you expose that as a client interface and then after you filter your table by your criteria you just need to execute this method passing the right parameters.
Regards
Maybe you are looking for
-
My 3rd Generation Ipod Touch (32 gigabytes) will not turn on or connect with iTunes
I set my ipod down, it was at near full battery, when I tried to unlock my ipod again, the screen stayed black. I tried holding down the lock button. Holding down both the lock button and the home button, and I tried connecting it to iTunes (nothing
-
Lot size dependent / independent
Hi, please advise when the system uses this lot size times data in mrp4 view? Where we need to specify that whether lot size dependent or independent need to select? When the system uses this data and when the system uses the planned delivery days an
-
My iphone 4 just stopped working in middle of texting
I was texting and my phone ust stopped working, I thought the battery died, but it has been charging all night. I tried another adapter and phone still won't charge. This is so weird. It is in an otter box at all times, no heat, water or dropping, ju
-
Disabling loudspeaker when playing music?
Hey Guys, I have noticed that the e65 doesnt have a built in FM radio, so i've turned to listening to mp3s. But i have one question. What really really really bugs me about Nokia's is that if the headset accidentally comes off the pop-port, then the
-
I moved the brightness to the right, then I deleted the history and the brightness still stayed to the right.