update of column based on another column
Hi allI want to update the column 2 of the table based on the value of update in column 1 and the existing value in column 1
Assume that table1 has columns ID, col1 and col2
I update col2 based on the update to col1 value and comparing the existing value of col1 in the table.
trying to decode, I think it should work.
Thank you.
Not like that.
You change a column of type CHAR, VARCHAR2 column, right? Thus, the data will be same. (Completed with space). For the new data inserted into a column VARCHAR2 TRIM is not necessary.
Tags: Database
Similar Questions
-
Update the value of the column based on another value of the column to another table
Hi all
I have something very confused me and need your help.
Having two tables A and B.
Table A have 2 column (+ id + and desc1)
Table B have column 2 also (+ transnum + and desc2)
Now, I want to update the column desc2 of table B identical desc1 of table was where transnum of Table B same as the id of the table has.
I use this SQL
update of a2 set a2.desc2 = a1.desc1 of a2 on a2.transnum = a1.id inner join a1
but this error occurs
Error from line 5 in order:
update of a2 set a2.desc2 = a1.desc1 of a2 on a2.transnum = a1.id inner join a1
Error in the command line: 5 column: 35
Error report:
SQL error: ORA-00933: SQL not correctly completed command
* 00933. 00000 - "command not properly ended SQL."
* Question: *.
* Action. *
Hope someone can help me. TQ for help...SQL> create table a1 (id number(2),des varchar2(10)); Table created. SQL> create table b1 (transnum number(2),des varchar2(10)); Table created. SQL> insert into a1 values (1,'maran'); 1 row created. SQL> insert into b1 values (1,'ram'); 1 row created. SQL> commit; Commit complete. SQL> update b1 set des=(select des from a1 where b1.transnum=a1.id); 1 row updated. SQL> select * from b1; TRANSNUM DES ---------- ---------- 1 maran
-
In the form of table-update a column based on the other
Greetings,
I want to update a column based on the value of another column in a tabular presentation. What should I use? Calculation or validation process?
-VatsaYes, get rid of the update of "pims_component" - this is the cause of the error table mutation - and simply set
: new.state_ind: = Ls_state;
CITY
-
Compare multiple columns and update a column based on the comparison
Hi all
I have to update the column STATUS of the slot structure of the table.
Status should be 'P' if all the columns count are equal on the other should be "F".
The value of the column can be "NA'. If the value is NA, then avoid this comparison column; compare only other 3 columns.
My output should look like below.
State of cnt1, cnt2 cnt3 ID cnt4
1 4 4 4 4 P
2 4 5 4 4 F
3 4 4 NA 4 P
NA 4 4 3 4
I tried with the statemnt with BOX WHEN conditions and DECODE UPDATE, but could not succeed, can someone please help
To do this, if you use my statement in response #11 box (Re: Re: comparison of multi-column and update a column based on the comparison of)
-
update of column with the number of sequence based on the condition
HelloVersion of DB: database Oracle 11 g Enterprise Edition Release 11.2.0.1.0 - 64 bit Production
Here's the script to reporduce:
CREATE TABLE T2
(
PARAMLOCATION NVARCHAR2 (16).
PARAMTYPE VARCHAR2 (3 BYTE),
PARAMNUM VARCHAR2 (3 BYTE)
)Insert into T2
(PARAMLOCATION)
Values
('49');
Insert into T2
(PARAMLOCATION)
Values
(« 12 ») ;
Insert into T2
(PARAMLOCATION)
Values
(« 50 ») ;
Insert into T2
(PARAMLOCATION, PARAMTYPE)
Values
('loc51', 'B');
Insert into T2
(PARAMLOCATION, PARAMTYPE)
Values
('loc52', 'B');
Insert into T2
(PARAMLOCATION, PARAMTYPE)
Values
('loc53', 'B');
Insert into T2
(PARAMLOCATION)
Values
("loc54");
Insert into T2
(PARAMLOCATION)
Values
("loc55");
Insert into T2
(PARAMLOCATION, PARAMTYPE)
Values
('aoc01', 'I');
Insert into T2
(PARAMLOCATION, PARAMTYPE)
Values
('aoc02', 'I');
Insert into T2
(PARAMLOCATION)
Values
("loc58");
Insert into T2
(PARAMLOCATION, PARAMTYPE)
Values
("doc03", "DL");
Insert into T2
(PARAMLOCATION, PARAMTYPE)
Values
("doc02", "DL");
Insert into T2
(PARAMLOCATION, PARAMTYPE)
Values
("doc01", "DL");I should update the column in table (paramnum) function sequential paramtype as this: also you can not order in paramlocation, its like that paramlocation comes first start sequence ordering from there based on paramtype.
PARAMLOCATION PARAMTYPE PARAMNUM 49 12 50 loc51 B 1 loc52 B 2 loc53 B 3 loc54 loc55 aoc01 AI 1 aoc02 AI 2 loc58 doc03 DL 1 doc02 DL 2 doc01 DL 3 Please advice.
Hello
I'll assume you have a column called load_order, which corresponds to the order of the lines:
CREATE TABLE T2
(
NUMBER OF LOAD_ORDER
PARAMLOCATION NVARCHAR2 (16).
PARAMTYPE VARCHAR2 (3 BYTE),
PARAMNUM VARCHAR2 (3 BYTE)
) ;Insert into T2
(LOAD_ORDER, PARAMLOCATION)
Values
(1, '49');
Insert into T2
(LOAD_ORDER, PARAMLOCATION)
Values
(2, '12');
Insert into T2
(LOAD_ORDER, PARAMLOCATION)
Values
(3, '50');
Insert into T2
(LOAD_ORDER, PARAMLOCATION, PARAMTYPE)
Values
(5, 'loc51', 'B');
Insert into T2
(LOAD_ORDER, PARAMLOCATION, PARAMTYPE)
Values
(8, 'loc52', 'B');
Insert into T2
(LOAD_ORDER, PARAMLOCATION, PARAMTYPE)
Values
(13, 'loc53', 'B');
Insert into T2
(LOAD_ORDER, PARAMLOCATION)
Values
(13.2, "loc54");
Insert into T2
(LOAD_ORDER, PARAMLOCATION)
Values
(13.5, 'loc55');
Insert into T2
(LOAD_ORDER, PARAMLOCATION, PARAMTYPE)
Values
(50, 'aoc01', 'I');
Insert into T2
(LOAD_ORDER, PARAMLOCATION, PARAMTYPE)
Values
(80, 'aoc02', 'I');
Insert into T2
(LOAD_ORDER, PARAMLOCATION)
Values
(81, 'loc58');
Insert into T2
(LOAD_ORDER, PARAMLOCATION, PARAMTYPE)
Values
(82, "doc03", "DL");
Insert into T2
(LOAD_ORDER, PARAMLOCATION, PARAMTYPE)
Values
(83, "doc02", "DL");
Insert into T2
(LOAD_ORDER, PARAMLOCATION, PARAMTYPE)
Values
(99, "doc01", "DL");Any data type, this column is or what are the values it contains, as long as you can derive from the order of the rows of values in the column. (Of course, the values can be consecutive integers, only they do not have to be). If you do not have this type of column, you don't have any order to your lines, and what you request is impossible.
Since you have a load_order column, here's a way to get the results you requested:
MERGE INTO dst t2
WITH THE HELP OF)
WITH got_grp AS
(
SELECT load_order
paramlocation
paramtype
ROW_NUMBER () OVER (ORDER BY load_order)
-ROW_NUMBER () OVER (PARTITION BY CASE
WHEN paramtype IS NULL
THEN 0
END
ORDER BY load_order
) AS the grp
THE t2
)
SELECT load_order
paramlocation
ROW_NUMBER () OVER (PARTITION BY grp
ORDER BY load_order
), Paramnum
OF got_grp
WHERE the paramtype IS NOT NULL
) CBC
WE (dst.paramlocation = src.paramlocation)
WHEN MATCHED THEN UPDATE
SET dst.paramnum = src.paramnum
;
Results:
LOAD_ORDER PARAMLOCATION BY
---------- ---------------- --- ---
1 49
2 12
3 50
loc51 5 B 1
loc52 8 B 2
13 loc53 B 3
13.2 loc54
loc55 13.5
50 aoc01 AI 1
80 aoc02 AI 2
loc58 81
1 DL of 82 doc03
2 DL doc02 83
3 DL of 99 doc01
-
How do column filter based on another column
In my report, I have column a thru d. I would like to create a filter based on another column where column is column B. I can enter a value that the column cannot be equal to, but I would use a column instead of a value.
Thank you.
JonathanTry this: icon on the filter columns->-> convert this advanced filter for SQL
You can reference any other columnBTW: Have you had a chance to look at my suggestion for your post
Tables from a Table -
How update the column in the table based on the value selected in apex4.1
Hi all
I have the following tables,
and it has the values as follows,leave_type table,it has the following fields, 1.emp_name, 2.sick 3.casual
leave_master table and it includes the following fieldsemp_name sick casual guru 10 10 mishra 10 10
I have the form based on the table "leave_master"1.emp_name, 2.leave_type 3.no_of_days
Here, the leave_type has the LOV which includes.
sick and casual.
When the form is filled out and clicked on the button submit,
I need to update the column leave_type in table leave_type,
for example,.
then I want to update the leave_type column,if emp_name:guru leave_type:sick no_of_days:3
sick sick = - no_of_days for the 'guru' of name
That is to say, ill = 10-3 = 7
then the leave_type of the table must be,
someone can such me what code or method I can use?emp_name sick casual guru 7 10 mishra 10 10
Thank you.
Published by: Gurujothi on May 24, 2012 21:54
Published by: Gurujothi on May 24, 2012 21:54Try something like this...
BEGIN
IF: PXX_LEAVE_TYPE = "Sick" THEN
UPDATE LEAVE_TYPE
THE PATIENT VALUE = SICK -: PXX_NO_OF_DAYS
WHERE EMP_NAME =: PXX_EMP_NAME;
ON THE OTHER
UPDATE LEAVE_TYPE
DEFINE CASUAL = CASUAL -: PXX_NO_OF_DAYS
WHERE EMP_NAME =: PXX_EMP_NAME;
END IF;
COMMIT;
END; -
Delete based on another column dublicate records
How can I remove duplicate records, based on another column.
the table structure
CREATE TABLE IA_EXPORT_LEVEL
(
A_NO VARCHAR2 (22 BYTE),
IM VARCHAR2 (18 BYTE),
ctn_level NUMBER (2)
)
reviews
A_NO IM ctn_level
S1 S1 1
S1 M1 2
S1 h1 3
H2 S2 1
S2 h2 2
S3 h1 2
S3 h1 3
S4 h6 4
S4 h6 5
I want to delete all records other than the minimum value of the ctn_level
output should like below
S1 S1 1
H2 S2 1
S3 h1 2
S4 h6 4
Published by: OraFighter on December 16, 2011 13:44DELETE FROM IA_EXPORT_LEVEL where rowid IN (select rid from (select rowid rid, row_number() over (partition by A_NO,IM order by ctn_level) rn from IA_EXPORT_LEVEL ) where rn > 1 ) /
Hope your question.
-
Get the cumulative values in a single column based on another column in reports
Hi all
I have a requirement to get cumulative values based on another column.I 'Sales rep name' in the first column.
Since there is no rank option in the PivotTable, I do this in the report table.
Correspondent "Values of the invoice line" in the second column.
Want to have cumulative of all the values for each sales invoice line.
Then apply rank and display the top 10 sales reps based on invoice lines.
Looking for the best entries...
Thanks in advance...Try below
2nd column: "name of Sales rep.
column 2: SUM ("invoice line values ' BY 'Name of Sales rep'") and sort this field desc.
3rd column: fx RANK (SUM ("invoice line values" BY "Sales rep name")), to hide this column, so that you don't confuse your users.and put the filter on the 3rd column below 5
I hope this works for you
-
Update of the table based on another
Hello
I'm trying to update a date column in a table based on another table. There is a unique ID in each table that identifies and connects each person:
This is the error:update patient_bu a set a.entry_date = (select b.entry_date from CLIENT_MED_DT b where a.id = b.id)
ORA-01427: einreihig subquery returns multiple rows
The problem (I think) is that the select statement back several dates for records people. There are some people / records that have multiple entry dates, but I'm only interested in the most recent date.
How can I update this table with only the most recent date?
Thanks for any help,
MattOh well, I forgot the UPDATE clause:
SQL> create table patient_bu 2 (id number 3 ,entry_date date); Table created. SQL> create table client_met_dt 2 (id number 3 ,entry_date date); Table created. SQL> merge into patient_bu a 2 using (select id 3 ,max(entry_date) max_date 4 from client_met_dt 5 group by id 6 ) b 7 on (a.id = b.id) 8 when matched then update 9 set a.entry_date = b.max_date; 0 rows merged.
-
Update a column to keep the old values and by adding a new
I have to update a column...
Select * from test;
TYPE_TEXTE RULE_NBR
-----------------------------------
30 AAX, AAR, AAV, AAB, AAK
40 BBD, WWN, AAF, AAB, AAK
now, I have to add BBB, WWW where rule_nbr = 30 and CCC, TTT where rule_nbr = 40
so this stmt update will do...
UPDATE TEST
Type_texte SET = "AAX, AAR, AAV, AAB, AAK, BBB, WWW.
WHERE rule_nbr = '30';
Update test
Set the argument type_texte = "BBD, WWN, AAF, AAB, AAK, CCC, TTT.
where rule_nbr = '40';
I was wondering is there an another way to update the sameLPS says:
UPDATE TEST
SET Type_texte = concat (type_text, 'BBB, WWW')
WHERE rule_nbr = '30';Update test
Set the argument type_texte = concat (type_text, 'CCC, TTT')
where rule_nbr = '40';Check your answer ;) should be concat(type_text,',BBB,WWW') or type_texte |', BBB, WWW'
You missed the point.See you soon,.
Manik. -
update to column values (false) in a copy of the same table with the correct values
Database is 10gr 2 - had a situation last night where someone changed inadvertently values of column on a couple of hundred thousand records with an incorrect value first thing in the morning and never let me know later in the day. My undo retention was not large enough to create a copy of the table as it was 7 hours comes back with a "insert in table_2 select * from table_1 to timestamp...» "query, so I restored the backup previous nights to another machine and it picked up at 07:00 (just before the hour, he made the change), created a dblink since the production database and created a copy of the table of the restored database.
My first thought was to simply update the table of production with the correct values of the correct copy, using something like this:
Update mnt.workorders
Set approvalstat = (select b.approvalstat
mnt.workorders a, mnt.workorders_copy b
where a.workordersoi = b.workordersoi)
where exists (select *)
mnt.workorders a, mnt.workorders_copy b
where a.workordersoi = b.workordersoi)
It wasn't the exact syntax, but you get the idea, I wanted to put the incorrect values in x columns in the tables of production with the correct values of the copy of the table of the restored backup. Anyway, it was (or seem to) works, but I look at the process through OEM it was estimated 100 + hours with full table scans, so I killed him. I found myself just inserting (copy) the lines added to the production since the table copy by doing a select statement of the production table where < col_with_datestamp > is > = 07:00, truncate the table of production, then re insert the rows from now to correct the copy.
Do a post-mortem today, I replay the scenario on the copy that I restored, trying to figure out a cleaner, a quicker way to do it, if the need arise again. I went and randomly changed some values in a column number (called "comappstat") in a copy of the table of production, and then thought that I would try the following resets the values of the correct table:
Update (select a.comappstat, b.comappstat
mnt.workorders a, mnt.workorders_copy b
where a.workordersoi = b.workordersoi - this is a PK column
and a.comappstat! = b.comappstat)
Set b.comappstat = a.comappstat
Although I thought that the syntax is correct, I get an "ORA-00904: 'A'. '. ' COMAPPSTAT': invalid identifier ' to run this, I was trying to guess where the syntax was wrong here, then thought that perhaps having the subquery returns a single line would be cleaner and faster anyway, so I gave up on that and instead tried this:
Update mnt.workorders_copy
Set comappstat = (select distinct)
a.comappstat
mnt.workorders a, mnt.workorders_copy b
where a.workordersoi = b.workordersoi
and a.comappstat! = b.comappstat)
where a.comappstat! = b.comappstat
and a.workordersoi = b.workordersoi
The subquery executed on its own returns a single value 9, which is the correct value of the column in the table of the prod, and I want to replace the incorrect a '12' (I've updated the copy to change the value of the column comappstat to 12 everywhere where it was 9) However when I run the query again I get this error :
ERROR on line 8:
ORA-00904: "B". "" WORKORDERSOI ": invalid identifier
First of all, I don't see why the update statement does not work (it's probably obvious, but I'm not)
Secondly, it is the best approach for updating a column (or columns) that are incorrect, with the columns in the same table which are correct, or is there a better way?
I would sooner update the table rather than delete or truncate then re insert, as it was a trigger for insert/update I had to disable it on the notice re and truncate the table unusable a demand so I was re insert.
Thank youHello
First of all, after post 79, you need to know how to format your code.
Your last request reads as follows:
UPDATE mnt.workorders_copy SET comappstat = ( SELECT DISTINCT a.comappstat FROM mnt.workorders a , mnt.workorders_copy b WHERE a.workordersoi = b.workordersoi AND a.comappstat != b.comappstat ) WHERE a.comappstat != b.comappstat AND a.workordersoi = b.workordersoi
This will not work for several reasons:
The sub query allows you to define a and b and outside the breakets you can't refer to a or b.
There is no link between the mnt.workorders_copy and the the update and the request of void.If you do this you should have something like this:
UPDATE mnt.workorders A -- THIS IS THE TABLE YOU WANT TO UPDATE SET A.comappstat = ( SELECT B.comappstat FROM mnt.workorders_copy B -- THIS IS THE TABLE WITH THE CORRECT (OLD) VALUES WHERE a.workordersoi = b.workordersoi -- THIS MUST BE THE KEY AND a.comappstat != b.comappstat ) WHERE EXISTS ( SELECT B.comappstat FROM mnt.workorders_copy B WHERE a.workordersoi = b.workordersoi -- THIS MUST BE THE KEY AND a.comappstat != b.comappstat )
Speed is not so good that you run the query to sub for each row in mnt.workorders
Note it is condition in where. You need other wise, you will update the unchanged to null values.I wouold do it like this:
UPDATE ( SELECT A.workordersoi ,A.comappstat ,B.comappstat comappstat_OLD FROM mnt.workorders A -- THIS IS THE TABLE YOU WANT TO UPDATE ,mnt.workorders_copy B -- THIS IS THE TABLE WITH THE CORRECT (OLD) VALUES WHERE a.workordersoi = b.workordersoi -- THIS MUST BE THE KEY AND a.comappstat != b.comappstat ) C SET C.comappstat = comappstat_OLD ;
This way you can test the subquery first and know exectly what will be updated.
This was not a sub query that is executed for each line preformance should be better.Kind regards
Peter
-
Automatically update the column in the table in OBIEE
Hi people,
I have a requirement to say I need to update a column of table based on a condition, but this update should happen on a daily basis (I mean that it would be held once per day) by checking if all the records in this column meets the condition then update
example:-column = 'pending', then using the "approved". As records of transactions every day in the table lights. OBIEE should check and update the line so the next time it does not show this line as "pending".
I thought of 2 approaches to this
(1) through the write-back, it is possible to update but manually (the question is it can't be automated or on demand on daily basis and update multiple records on a go)
(2) write a stored procedure or a function of update, but how can I perform this procedure either regular or run once daily.how to use it?
Any thoughts on the above two points or any method you can think off the coast.
Any help is appreciated!
See you soon,.
KKMurielle,
This shud be easy...
-Create a direct database... with the Update statement
for example: Update table set col = "Approved" where col = 'pending '.
-Create an ibot using the RFI above and plan on a daily basis.This will update the complete table with the new value on a daily basis based on the State
-
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,
;
-
How to update exists column on the table with the exact number and auto increment
Hello
I have a table with more than 10 million rows and there is a column called 'number_zaq', I want to update this column on line frist from 2000 and + 1 for the next all ranks.
Update your_table
Set number_zaq = rownum + 2000-1;
Maybe you are looking for
-
Toshiba virtual Store account Reset - 33537
Hello I want to reset my Toshiba e-store account:-33537
-
Anyone know where I can sp2 for individual computer please. Can not update of Internet Explorer 6 is
-
How do I remove the Flash DRIVE and external hard drive write protection
Original title: A distress call My Kingston Traveller of 16G flash drive as my 320 G external drive HP say that they are write protected. I'm not sure how that becomes activated but would really like to know how to disable.
-
I use my printer for a caravan club, printing envelopes, forms, leaflets etc. What I want to know is how much electricity my officejet 6700 consumes during printing. I print as much as possible about the project to save the ink. I print on 150-200
-
What should I do to be able to open an e = Power Point e-mail attachment marked PPTX?