comparing string values in the same table
I have a table with ID (14 digit string values) starting with "A". Ex: A21849B1020792. There may be a different ID with the same substring 'B1020792' in the same table, example: A12349B1020792. If this happens, the ID of the last creation date of must be returned in the result. In other words, comparison is done on the same table. "In the example provided, say A12349B1020792 has the date of 1 January 2015 'and A21849B1020792 has date February 1, 2015", since A21849B1020792 has the most recent date, the result must contain only A21849B1020792.
ID create_date
--- ------------------
A21849B1020792 02/01/2015
A12349 B1020792 01/01/2015
A12345B1234567 01/03/2015
A43567B1234567 01/04/2015
Here's the query I used:
substr (a.id, 7) select sc, max (a.create_date) cd1
of table a, table b
where a.id! = b.id
and substr (a.id, 7) = substr (b.id, 7)
and a.id like 'A %' and b.id like 'A %' / * (I used a % because I am interested only IDs that begin with A) * /.
and a.id ('A12349B1020792', 'A21849B1020792','A12345B1234567 ','A43567B1234567')
Group of substr (a.id, 7);
Result:
---------
sc cd1
--- ------
B1020792 02/01/2015
B1234567 04/01/2015
There is one thing that I'm not able to do with my request, that is, be able to get real IDs list and not list of substrings. If I added a.id column in the select clause and the group by clause, the query includes both by substr (a.id, 7) and a.id and as a result, the query returns four lines as below:
substr (a.id, 7) select sc, max (a.create_date) cd1, a.id ID
of table a, table b
where a.id! = b.id
and substr (a.id, 7) = substr (b.id, 7)
and a.id like 'A %' and b.id like 'A %' / * (I used a % because I am interested only IDs that begin with A) * /.
and a.id ('A12349B1020792', 'A21849B1020792','A12345B1234567 ','A43567B1234567')
Group by substr (a.id, 7), a.id.
Result:
---------
sc cd1 ID
--- ------ ---------
01/01/2015 A12349B1020792 B1020792
B1020792 01/02/2015 A21849B1020792
B1234567 01/03/2015 A12345B1234567
B1234567 01/04/2015 A43567B1234567
My goal is to retrieve a list of all the unique identifiers that have the later dates.
ID:
---
A21849B1020792
A43567B1234567
Thanks for your time in advance!
Hello
user11951344 wrote:
I have a table with ID (14 digit string values) starting with "A". Ex: A21849B1020792. There may be a different ID with the same substring "B1020792" in the same table, example: A12349B1020792. If this is the case, the ID of the last creation date must be returned in the result. In other words, comparison is done on the same table. "In the example provided, say A12349B1020792 updated 1 January 2015 ' and A21849B1020792 a date February 1, 2015", as A21849B1020792 has the most recent date, the result should contain only the A21849B1020792.
ID create_date
--- ------------------
A21849B1020792 02/01/2015
A12349B1020792 01/01/2015
A12345B1234567 03/01/2015
A43567B1234567 01/04/2015
Here's the query I used:
substr (a.id, 7) select sc, max (a.create_date) cd1
of table a, table b
where a.id! = b.id
and substr (a.id, 7) = substr (b.id, 7)
and a.id like 'A %' and b.id like 'A %' / * (I used a % because I am interested only IDs that begin with A) * /.
and a.id ('A21849B1020792', 'A12345B1234567', 'A12349B1020792', 'A43567B1234567')
Group of substr (a.id, 7);
Result:
---------
sc cd1
--- ------
B1020792 02/01/2015
B1234567 01/04/2015
There is one thing that I am not able to do with my request, that is, the ability to retrieve the list of IDs real and not a list of substrings. If I added a.id column in the select clause and the group by clause, the query groups according to the two substr (a.id, 7) and a.id and as a result, the query returns four lines as below:
substr (a.id, 7) select sc, max (a.create_date) cd1, a.id ID
of table a, table b
where a.id! = b.id
and substr (a.id, 7) = substr (b.id, 7)
and a.id like 'A %' and b.id like 'A %' / * (I used a % because I am interested only IDs that begin with A) * /.
and a.id ('A21849B1020792', 'A12345B1234567', 'A12349B1020792', 'A43567B1234567')
Group by substr (a.id, 7), a.id.
Result:
---------
sc cd1 ID
--- ------ ---------
B1020792 01/01/2015 A12349B1020792
B1020792 02/01/2015 A21849B1020792
B1234567 03/01/2015 A12345B1234567
B1234567 01/04/2015 A43567B1234567
My goal is to retrieve a list of all the unique identifiers that have the later dates.
ID:
---
A21849B1020792
A43567B1234567
Thanks for your time in advance!
If it makes sense to treat the first 6 characters of the ID separately from the rest of the id in this problem, maybe it makes sense to store those two parts of the id in two different columns. Relational databases work best when each column of each row contains 1 single piece of data (at most). It is so fundamental to the design of table that he called the first normal form.
Given that the two parts are stored in column 1, so you can something like this Request Top - N:
WITH got_r_num AS
(
SELECT r.id
r.create_date AS cd1
, RANK () OVER (PARTITION OF SUBSTR (r.id, 7))
ORDER BY r.create_date DESC
) AS r_num
FROM table_x g - g for data values
JOIN table_x r - r for related values
ON SUBSTR (r.id, 7) = SUBSTR (g.id, 7)
WHERE g.id IN ('A12349B1020792'
, "A21849B1020792".
, "A12345B1234567".
, "A43567B1234567".
)
- AND g.id LIKE 'A %' - if necessary. The above condition ensures already g.id start with "A".
AND r.id LIKE 'a % '.
)
SELECT id, create_date
OF got_r_num
WHERE r_num = 1
;
If you would care to post CREATE TABLE and INSERT instructions for the sample data, and then I could test this.
Tags: Database
Similar Questions
-
Compare two rows in the same table
Hi all
I need to compare two rows in the same table, I don't know hoe to do it in pl/sql. Please help me on this.
example:
price of ro TR
xya0001 AMA.7 12
xya0003 ama6 14
xya0004 AMA.7 16
in table b is a unique value for each line, I need to compare the price column and see if the first value is less than or greater than the following value and, if there is more to put the corresponding value of br to a variable, and if it is less, put the corresponding value of the br to another variable. I don't know a method to do this, as I'm new to pl/sql. Please help me in thisfor data in(select tr,br,price, lag(price) over ( order by tr) newcol from yourtable) loop if nvl(data.newcol,0) > data.price then variable1:=data.br; else varable2:=data.br; end if; end loop;
-
Updated with the values in the same table, for other records corresponding to conditions
Hi Experts,
Sorry do not provide the structure of the table (it is a simple structure)
I have a requirement where I need to update the columns of a table based on the same table with some match empid and date values. If the date and empid match so I have these values to any other folder and update of one who is not having details of Office . I need the Update query
Before the update my array of values is as below
Sort_num Emp_id Bureau start_date
1 101 AUS 01/01/2013
2 101 01/01/2013
3 101 15/01/2013
4 103 USA 01/05/2013
5 103 01/01/2013
6 103 05/01/2013
7 104 FRA 01/10/2013
8 104 10/01/2013
9 104 01/01/2013After update my table should be as below
Sort_num Emp_id Bureau start_date
1 101 AUS 01/01/2013
2 101 AUS 01/01/2013
3 101 15/01/2013
4 103 USA 01/05/2013
5 103 01/01/2013
6 103 USA 01/05/2013
7 104 FRA 01/10/2013
8 104 FRA 01/10/2013
9 104 01/01/2013Thanks in advance
I don't have the time to create the table with the data, but basically, you should be able to code the following text
update one table
Office set = (select desktop in table b where b.emp_id = a.emp_id)
and b.start_date = a.start_date
and b.office is not null
)
where is ([as well as overall query])
and a.office is null
In my opinion, who will do the trick.
HTH - Mark D Powell.
-
Create a query to compare the values in the same table
Suppose you have the table, below even ID occur for the same month as well as different months
ID value of months
--------------------------------------------------------------
226220 201203 100
1660 201204 200
26739 201204 1010
7750 201205 31.1
I need a query to determine the results laid below
The month ID value Prior_month_value Prior_Month
----------------------------------------------------------------------------
1234 201203 10 201201 100
3456 201206 56.1 201204 78
Help, please
Published by: Jaguar on 10 July 2012 03:00With the information we have, it's the best we can get to...
SQL> with t as (select 226220 as ID, 201203 as Month, 100 as Value from dual union all 2 select 1660, 201204, 200 from dual union all 3 select 26739, 201204, 1010 from dual union all 4 select 7750, 201205, 31.1 from dual) 5 -- 6 -- end of example data 7 -- 8 select decode(rownum,1,1234,3456) as id 9 ,decode(rownum,1,201203,201206) as month 10 ,decode(rownum,1,10,56.1) as prior_month_value 11 ,decode(rownum,1,201201,201204) as prior_month 12 ,decode(rownum,1,100,78) as value 13 from ( 14 select * from t where rownum <= 2 15 ) 16 / ID MONTH PRIOR_MONTH_VALUE PRIOR_MONTH VALUE ---------- ---------- ----------------- ----------- ---------- 1234 201203 10 201201 100 3456 201206 56.1 201204 78
Waste in... trash out.
-
Compare several records in the same table
Hello, I m writing a bat file so I can export information that I question.
I have an automatic integration which checks from time to time if there is no new client´s and generates a trigger.
If an error levonorgestrol I the process is repeated until the client is located in the database.
I can't create tables or change the structure.
My problem is that I need to compare the record more updated with the CLIENT_ID field
Let me give you an example:
Table A
ERROR_MESSAGE CREATEDUSERID CLIENT_ID
0 success 01/01/2009
1 error 01/01/2009
2 success 01/01/2009
1 success 01/02/2009
3 success 01/02/2009
4 error 01/02/2009
I need to compare "1" client created on 01/01/2009 this error gived with new records to see if there's success and my
query should only return the client_ID '4' and export with sqlplus
Could you please help me?Hello
It works very well with my data.
What data do you use? After a few lines of sample data (CREATE TABLE AS executable... or INSERT... statements are best) that give you wrong results.Make sure that everything is spelled correctly.
For example, roughly halfway through the query, you sayand io.status = 'Erro'
and at the end you say
having max(decode(io.status, 'Error', 1, 2)) ...
That is the same ("Error" or "Error") in both places?
-
update of column based on the values of the same table
I have the T1 table with 4 columns "col1", "col2", "col3", "col4", "col5", "col6" as follows
Col1 Col2 Col3 Col4 Col5 Col6
1111 Ville1 C AA DDD A1
2222 city SD HHH A1 1
3333 City2 B EE OOO
4444 City 1 B JJ SSS A1
5555 City2 C KK VVV
6666 City2 RR QQQ
7777 City2 B BBB XX
I've already updated column value 6 'A1' where the 2 column is 'Ville1 '.
Now, I want to update Col. 6 where col2 is the of ' with the following conditions
If Col 3 = 'B', then Col6 should be = col4
Otherwise, it should be = col5SET col6 = DECODE(col3,'B',col4,col5)
"WHERE col2 = s" -
COMPARING TWO ROWS IN THE SAME TABLE AND DELETE THEM USING DELETION BLOCK
Hi all
I have a problem. I have an Employee table
employee
Emp_name Emp_id Emp_status Emp_date
John 1 P 11-27-2010
Mike 2 26/11/2010 S
Simon P 3 22 / 11 / 2010
Dennis C 4 25/11/2010...
I compare the rows in the table and their employee_status if 'P', should I remove the... Here, I should delete lines 1 and 3 as their Emp_status is 'P '. I only use BULK DELETE... I tried to use the join query internal and deletion, but it does not work... Can someone help me...Ooops, it should be:
and e2.emp_status in ('P', 'C')
not
and e2.emp_status in ('P', 'A')
Here it goes:
SQL> select * 2 from employees 3 / E EMP_NAME EMP_KEY X - ---------- ---------- ---------- C John 123 1 P Mike 123 2 P Paul 123 6 C Harry 124 5 A Gass 125 7 C Gass 125 7 6 rows selected. delete employees e1 where 2 = ( select count(distinct e2.emp_status) from employees e2 where e2.emp_key = e1.emp_key and e2.emp_status in ('P','C') ) / 3 rows deleted. SQL>
SY.
-
Mr President
If I have the two LOV in the same table then how to connect when I select first and second LOV value also change?
My two fields are FLOW AND DR_NAME
FLOW = ACCT_ID
DR_NAME = ACCT_NAME
I created with success of LOV for these fields.
First LOV gives acct_id in the debit field and second LOV gives the value of acct_name to dr_name.
How can I report these lov, it's that when I change my acct_id then acct_name also change
I have these two tables
CREATE TABLE "NOM" ( "ACCT_ID" VARCHAR2(7) NOT NULL ENABLE, "ACCT_NAME" VARCHAR2(50) NOT NULL ENABLE, "O_BAL" NUMBER(13,2), CONSTRAINT NOM_PK PRIMARY KEY ("ACCT_ID")ENABLE ); CREATE TABLE "VOUCHERDET" ( "V_ID" VARCHAR2(9) NOT NULL ENABLE, "LINEITEM" NUMBER , "DEBIT" VARCHAR2(7) , "DR_NAME" VARCHAR2(50), "CREDIT" VARCHAR2(7) , "CR_NAME" VARCHAR2(50), "PARTICULARS" VARCHAR2(100), "AMOUNT" NUMBER(21,2), CONSTRAINT VOUCHERDET_PK PRIMARY KEY ("V_ID","LINEITEM")ENABLE, CONSTRAINT PUR_SAL_LINE_POD_FK FOREIGN KEY(PROD_ID) REFERENCES PRODUCTS (PROD_ID)ENABLE, CONSTRAINT VOUCHERDET_DEBIT_FK FOREIGN KEY ("DEBIT") REFERENCES "NOM" ("ACCT_ID") ENABLE, CONSTRAINT VOUCHERDET_CREDIT_FK FOREIGN KEY ("CREDIT") REFERENCES "NOM" ("ACCT_ID") ENABLE, CONSTRAINT VOUCHERDET_V_FK FOREIGN KEY ("V_ID") REFERENCES "VOUCHER" ("V_ID") ON DELETE CASCADE ENABLE );
Concerning
so, instead of this second ActId, choose ACCT_NAME:
-
Make a column based on another value of the column in the same table
JDev 11.1.1.6.0
It may be a silly question but I'm stuck
I need to conditionally return a column that said Condition is as if the value in the other column of the same table B is equal to F. I should make A column only when this condition is met. I tried the following code:
< af:column sortProperty = "PhoneNumber1." sortable = "false". headerText = "#{bindings." A.hints.PhoneNumber1.label}. ID = "c146. rendering = "#{rank." PhoneNumber1ResponseFlag eq 'F'} ">" < af:outputText value = "#{rank." PhoneNumber1}. ID = "ot130" / > < / af:column > < af:column sortProperty = "PhoneNumber1ResponseFlag." sortable = "false". headerText = "#{bindings." B.hints.PhoneNumber1ResponseFlag.label}. ID = "c80" rendered = "true" > < af:outputText value = "#{rank." PhoneNumber1ResponseFlag}. ID = "ot129" / > < / af:column > The data presented in the table for the PhoneNumber1ResponseFlag column are F. Still my condition does not work.
Well, I've finally sorted it myself by managed bean.
Here are the steps I followed:
- Wrote a new bean managed.
- Added a Boolean variable called flag and made to true when the "'PhoneNumber1ResponseFlag ' current line attribute is equal to F."
- Changing the property made column on this indicator.
-
How to update columns with the value of other lines in the same table
Hello
I use Oracle 11.2, I'd use SQL statements to update a column based on values in other rows in the same table. Here are the details:
create table TB_test (number 4 myId, crtTs date, date of MDPU);
insert into tb_test (1, to_date ('20110101', 'YYYYMMDD'), null);
insert into tb_test (1, to_date ('20110201', 'YYYYMMDD'), null);
insert into tb_test (1, to_date ('20110301', 'YYYYMMDD'), null);
insert into tb_test (2, to_date ('20110901', 'YYYYMMDD'), null);
insert into tb_test (2, to_date ('20110902', 'YYYYMMDD'), null);
After you run the SQL code, I would like to have the following result:
1, 20110101, 20110201
1, 20110201, 20110301
1, 20110301, null
2, 20110901, 20110902
2, 20110902, null
Thanks for your suggestion.I guess you need this, otherwise please explain logic correctly:
SQL> merge into tb_test t 2 using ( 3 select rowid as rid 4 , lead(crtts) over(partition by myid order by crtts) as updts 5 from tb_test 6 ) v 7 on (t.rowid = v.rid) 8 when matched then update 9 set t.updts = v.updts 10 ; 5 rows merged. SQL> select * from tb_test order by 1,2; MYID CRTTS UPDTS ---------- --------- --------- 1 01-JAN-11 01-FEB-11 1 01-FEB-11 01-MAR-11 1 01-MAR-11 2 01-SEP-11 02-SEP-11 2 02-SEP-11
-
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
-
Comparing the same tables of two schemas
I had already posted a similair on this thread. So, I thought I would start a new thread on this to avoid confusion
I want to generate a report that shows the difference in the data type of the columns in the same table in two different patterns.
The query using LESS shows the difference below.
But, since it is a report, I want to see the form of results the two schemas that has column of different data types with the same names of tablecreate table SCOTT.mytab1 (empid number); create table HR.mytab1 (empid varchar2(34)); SELECT table_name, column_name, OWNER schema, data_type FROM dba_tab_cols where owner = 'SCOTT' AND TABLE_NAME = 'MYTAB1' MINUS SELECT table_name, column_name, OWNER schema, data_type FROM dba_tab_cols where owner = 'HR' AND TABLE_NAME = 'MYTAB1' Result: TABLE_NAME COLUMN_NAME SCHEMA DATA_TYPE --------------- --------------- ---------- ------------ MYTAB1 EMPID SCOTT NUMBER
Expected results:
Anyway I could do this?TABLE_NAME COLUMN_NAME SCHEMA DATA_TYPE --------------- --------------- ---------- ------------ MYTAB1 EMPID SCOTT NUMBER MYTAB1 EMPID HR VARCHAR2
Why not get a single line with two types of data:
select a.table_name, a.column_name, a.data_type schema1_type, b.data_type schema2_type from all_tab_columns a, all_tab_columns b where a.owner = 'SCOTT' and b.owner = 'HR' and a.table_name=b.table_name and a.column_name=b.column_name and a.data_type!=b.data_type;
This extracted single query columns present on the two schemas but with different data types. These columns only on one of the two schemas are not extracted.
Max
-
Comparison of columns in the same Table, with the exception
Hi all
I need compare two values of column in the same table. But should ignore a few characters like space, comma, point
Following should be consistent
How is it possible'ABcd f' = 'AbCDf' 'xyz ..' = 'xy z'
See you soon
Sexywith t as ( select 'ABcd f' col1,'AbCDf' col2 from dual union all select 'xyz ..','xy z' from dual union all select 'xyz ..x','xy z' from dual ) select * from t where upper(translate(col1,'a ,.','a')) = upper(translate(col2,'a ,.','a')); COL1 COL2 ------- ----- ABcd f AbCDf xyz .. xy z
Published by: JAC on 4 February 2013 17:22
-
Name of the file and the measure in the same table?
Hello
I wrote the following VI which opens each image file in a folder and measure a certain size on the image. He then puts the result in a table.
The table has a column and N lines since I N images in my folder. How can I change this VI so that it puts the name of the file in the same table as well as the measurement?
I want the table to look like:
File1 measurement1
File2 GCA2
...
and so on.
Currently, it just shows
measurement1
GCA2
....
and so on.
The VI are:
You cannot use the Table Express. Like the properties page says: this is for digital data. You will need to use a bit of real LabVIEW to create the table. A table is simply a string 2D array. Convert the digital chain, build an array of 1 d of the filename and numberic strings and use a shift register to build a 2D array. Something like the code below.
-
Insert select on the same table: possible without side effects?
I have a very large table T1 containing millions of records. I need to treat its lines and create a few new lines based on selection.
Table T1 contains events and one of them, with the code 100, is created by the further development of other events inside the table.
My code is as follows:
insert /*+append */ into T1 (code,...) values (100, c1,c2,...) select c1,c2... from T1 where (code=20 or code=10) and <other conditions>...
as you can see I'm extract T1 lines to insert again in T1 with a different code and I use the direct path in order to get good performance.
My fear is: choose is made from the same table I risk data loss? In general it is a good practice? Or is it better to create another table?
Hello
No I don't think that there may be loss of data. But that may depend on the behavior of the application and your where clause.
I will explain how it is treated, so you can see if it's ok:
1. the table is locked because of the insert add, (as)
2 lines are read by select and make compatible from the State that was at the beginning of the query - 1.
3 rows are inserted at the end, after the high-water line
4 columns for new lines are sorted to be merged in the index
5. high watermark is adjusted - visible new lines and lock is released
Note that 2. and 3. occur at the same time: rows are inserted all read.
Note that anyone can choose in the table during the operation - they see the changes committed only - if the State 1.
all other DML are waiting for the lock being released, and will see new ranks and then
If you have things that prevent the direct-path insert, append the hint will be ignored. So, if you must rely on close to 1. then the best lock explicitly with table lock. But I don't think that you need.
Kind regards
Franck.
Maybe you are looking for
-
After account reset white screen again
After reset, my personal account has changed, the old 23183 is now 33500 and I have the same problem - white screen.
-
How can I configure my Airport Express to mesh with new cable modem bridge mode?
Time Warner sent me a new cable modem and my Airport express still flashing orange light. How can I configure the Airport express in bridge mode?
-
Hi all In my house, the extreme is connected to a fiber modem 250 / 250 MB/s and I plugged a time Machine as an Express via CAT6 UTP. All serve as a router and provide 2.4 and 5 GHz wifi on the different floors of the House. Just a question: Express
-
Compare the numbers of channels
Hello can someone show me how to compare strings like this? If the STRING of TEXT/is TestSystem100000-001 TestSystem100000-002 TestSystem100000-003 TestSystem200000-001 TestSystem200000-002 TestSystem200000-003 If its then its OLD model TestSystem100
-
I have a computer running Windows XP (sp 3) and received the above error message. When I first start the computer, I got the following error message "Generic Host process for Win32 has encountered a problem and needs to close." When I select the 'd