Duplicate records and modify data in another table
First of all, I have two tables (CUSTOMER and ADDRESS) with the following definition:
CUSTOMER has 7 columns (aa, ab, ac, ad, ae, af, ag)
AA is the primary key
AE, af, ag are the duplicate columns and he should be arrested by ae, af, ag
a foreign key between the CUSTOMER and ADDRESS
ADDRESS has 5 columns (bb, bc, bd, aa)
BB is the primary key
Here is an example of the content at the start
CUSTOMER
AA ab ac ad ae af ag
12 432 23 44 32 22 44
13 32 33 213 32 22 44
14 321 22 22 17 21 33
15 22 43 90 17 21 33
16 21 23 94 17 21 33
ADDRESS
BB bc bd be aa
17 321 33 23 12
18 123 32 22 13
20 22 23 34 14
21 22 21 22 15
22 12 34 22 16
And the result,
CUSTOMER
AA ab ac ad ae af ag
12 432 23 44 32 22 44
14 321 22 22 17 21 33
ADDRESS
BB bc bd be aa
17 321 33 23 12
18 123 32 22 12
20 22 23 34 14
21 22 21 22 14
22 12 34 22 14
How could I do with SQL?
Hello
user10681153 wrote:
...
INSERT INTO CUSTOMERS VALUES (12,432,23,44,32,22,44);INSERT INTO CUSTOMERS VALUES (13,32,33,213,32,22,44);
INSERT INTO CUSTOMERS VALUES (14,321,22,22,17,21,33);
INSERT INTO CUSTOMERS VALUES (15,22,43,90,17,21,33);
INSERT INTO CUSTOMERS VALUES (16,21,23,94,17,21,33);
INSERT INTO THE ADDRESS VALUES (17,321,33,23,12);
INSERT INTO THE ADDRESS VALUES (20,22,23,34,14);
INSERT INTO THE ADDRESS VALUES (21,22,21,22,15);
INSERT INTO THE ADDRESS VALUES (22,12,34,22,16);
In your original message, there are 5 rows in address; now, there are only 4. In light of these new data, I guess that the results you origianlly displayed for the customer are always the same, but the results that you want to start address are now:
BB BC BD BE AA
---------- ---------- ---------- ---------- ----------
17 321 33 23 12
20 22 23 34 14
21 22 21 22 14
22 12 34 22 14
I don't see anything wrong with my previous solution. Do you have?
Tags: Database
Similar Questions
-
Redirect data to another table using before insert trigger.
Dear all,
How can I redirect the data to another table in a before Insert trigger? My database is Oracle10g.
I have a table EMP (EMP_ID, LAST_NAME, SALARY).
I have another EMP_COPY table with the same structure. I also have a before Insert trigger on the EMP table.
Based on a condition that I have to redirect the data in table EMP_COPY. Let's say the condition is EMP_ID = 100.
I fire an insert on EMP table for example INSERT IN EMP(EMP_ID,LAST_NAME,SALARY) VALUES(100,'Dev',500).
On the inside of the front Insert trigger on the EMP table, I have the code
IF EMP_ID = 100 THEN
INSERT INTO EMP_COPY (EMP_ID, LAST_NAME, SALARY)
VALUES(:NEW.) EMP_ID,: NEW. LAST_NAME,: NEW. SALARY);
COMMIT;
ON THE OTHER
NULL;
END IF;
But the problem here is that data goes to EMP table of origin also although I don't want. He should do an Insert into EMP table only if EMP_ID! = 100.
One way has been to raise a user-defined exception inside the If statement and not handle it so that the original insert on table EMP fails but INSERT comes in the EMP_COPY table. But in this solution since the inside the trigger unhandled exception, it propagates to the calling environment. And I can't stand outside relaxation as the calling environment is a form of Oracle Apps standard that cannot be customized.
Any kind of help will be highly appreciated that I am fighting for more than two weeks.
Thanks in advance
DevRemove the autonomous transaction pragma... and then try again.
-
How can I insert data from another table into a table containing a timestamp column
How you insert data from another table in a table if the target table contains a timestamp column. I tried to set the default value of GETDATE() column in the target table, but it does not work.
I use MS SQLSorry, I managed to get around this by inserting null as the value
-
Reading file from the ftp server and importing data into the table
Hi experts,
Well, basically, I text with different layout files have been uploaded to an ftp server. Now, I must write a procedure to recover these files, read and insert data into a table... what to do?
your help would be greatly helpful.
Thank youuser9004152 wrote:
http://it.Toolbox.com/wiki/index.php/Load_data_from_a_flat_file_into_an_Oracle_tableSee the link, hope it will work.
It is an old method, using the utl_file_dir parameter that is now obsolete and which is frankly a waste of space when external tables can do exactly the same thing much more easily.
-
Incompatibility between the two recorded and stored data
Hi guys, I am preparing Labview codes for reocording synchronized analogy and reading. Specifically, I want to record for 6 seconds, while the sounds of output for 5 seconds. This means that the analogue output stop 1 second before the end of the recording. In addition, I want to save the second 6 check-in 3 files TDMS (2 seconds). However, I couldn't do my codes work in the required way (attached). I have identified two problems that are beyond my skills.
1. "some or all of the requested samples are not yet acquired. It's weird, because I already have the function of "DAQmx Read" provided that only when there is sample to read.
2. instead of save data to 3 TDMS files, only one file is generated.
I am grateful for your help. Thank you very much.
luojh135 wrote:
Hi guys, I am preparing Labview codes for reocording synchronized analogy and reading. Specifically, I want to record for 6 seconds, while the sounds of output for 5 seconds. This means that the analogue output stop 1 second before the end of the recording. In addition, I want to save the second 6 check-in 3 files TDMS (2 seconds). However, I couldn't do my codes work in the required way (attached). I have identified two problems that are beyond my skills.
1. "some or all of the requested samples are not yet acquired. It's weird, because I already have the function of "DAQmx Read" provided that only when there is sample to read.
2. instead of save data to 3 TDMS files, only one file is generated.
I am grateful for your help. Thank you very much.
You have a beautiful mess! (Sorry, but you do) Your little logic code.
First of all, if you want to save data to a file aDAQmx TDMS task do it! Enable logging of data it will greatly simplify your diagram to the point where some of the other problems become more obvious.
Now, let us look at this section:
In the present, I can that you used to be a programmer of text. These subsets 'replace Array' actually boggle my mind! Why replace the first element of the tables full of zeros? and why is it a picture of 5,000 items? Looks like you put 5000 zeros on the front and back of the noise AND stuffing a 0.99 in the first element of an array of 5000 zeros only to replace the range of a 0.99 and 4999 zeros with a table of 5000 zeros TWICE! (in case the first subset of the table replace did not work? WWYT?) But save a little... A high pass filter with fh = 11000 and fl = 8000?
Save the help file, we find:
Then, this constant 110000 doing here? (Other than ignored)
Save a little and you father a production 1.25 M points of noise Gaussian with a gap of 0.1, but the constant is labled rms. (Go fix it now before you confuse us no more!)
In all sincerity. I've seen worse but please correct obviously I did notice and we could be much more effective to help with the subtle substance which can always be wrong.
-
delete records that are related to another table
I want to delete records from a table (A), these recordings has a relationship with another table (B)
using a query to set these records is that I want to delete
with B as
(
f select '2', '3' l double
Union of all the
f select '2', '3' l double
Union of all the
f select '4', '4' l double
)
Select * from A, B
where B.f() > 3 and b. > 3
and A.f. = B.f()
and A.l = b.
Oracle Database 11 g Enterprise Edition Release 11.1.0.7.0 - 64 bit Production
Thanks in advance!Hello
Here's one way:
DELETE a WHERE f > 3 AND l > 3 AND (f, l) IN ( SELECT f, l FROM b ) ;
-
Before file is deleted, the record must be insert into another table
Hi friends,
I have to create tabular form to delete some record. Using this tabular form I deleted successfully.
But I want to when I delete a record before deleting record that he should go to another table.
How can I do that.
EdHello
You create before you remove the trigger table.
http://download.Oracle.com/docs/CD/B10500_01/server.920/a96524/c18trigs.htmBR, Jari
-
Select table data in another table
Hello
I want to select data from A table, which is not in table B.
Currently I am doing:
Select
smofnut,
nameA,
dobA
a.
If smofnut not in
(select A snoB, B).
where smofnut = snoB
and nameA = Name)
But above all it is very slow.
I can do something like:
Select
smofnut,
nameA,
dobA
of A, B
where
EXCLUDE (smofnut = snoB and nameA = Name)
Please note that I need the place where the condition on the two columns.
any help will be appreciated.
-HarveyWhat are approximate data to A and B?
What is 'very slow '?
What version of Oracle?
What is the query plan?Without knowing anything about your system, my first thought would be to see if a NOT EXISTS happened to be faster for your data
SELECT snoA, nameA, dobA FROM a WHERE NOT EXISTS ( SELECT 1 FROM b WHERE a.snoA = b.snoB AND a.nameA = b.nameB )
Of course, I don't know why you want to join A & B in your NOT IN subquery. It would seem that you would need just a subquery correlated, i.e.
SELECT snoA, nameA, dobA FROM a WHERE snoA NOT IN ( SELECT snoB FROM b WHERE a.snoA = b.snoB AND a.nameA = b.nameB )
This should be more efficient than the original request. The NOT EXISTS version may or may not be more effective than NOT IN according to data volumes.
Justin
-
Conversion of binary and incoming data on a table
So I try to do 2 things:
1 generate a random number, convert it to hexadecimal format and display it on a table.
2 convert the binary hexadecimal format and display on a table as well
Just started using labview so my diagram is probably completely wrong
Look at the Format function in the chain. You can set all kinds of formatting rules. %x is going to take a number and format it in a Hex string. %b is going to take a number and shaped in a binary string. You want to use the build array function to write to your table.
-
Copy and update data from one table to the new table by using the Merge command
Hello
Can someone tell me please how to do this?
I have a table: EMP (ename, sal, empno (pk), dept) another table is EMP_CLASS ((pk) empno, ename)
I want to insert corresponding lines of emp to table emp_class if this line does'nt exists in emp_class
otherwise it will be update info by corrsponding emp_class table as well as remove of emp_class according to the emp delete operation.
Thank you
Madam.
Published by: Nico on August 12, 2010 22:59Have changed. PLS, run once more...
MERGE INTO emp_class
With the HELP of emp
WE (emp.empno = emp_class.empno)
WHEN MATCHED THEN
UPDATE
SET emp_class.ename = emp.ename,
emp_class. DEPTNO = emp.deptno,
emp_class. Class = decode(emp.deptno,10,1,20,2,30,3,40,4)
DELETE
WHERE emp_class.empno = emp.empno
WHEN NOT MATCHED THEN
INSERT (emp_class.empno, emp_class.name, emp_class.deptno, emp_class.class)
VALUES (emp.empno, emp.ename, emp.deptno, decode(deptno,10,1,20,2,30,3,40,4));P.S. Not tested
Thank you
Florian...Published by: Florian on August 13, 2010 01:53
-
update of data from another table
Hi, I would like to help. I Don t know how I can start doing:
I have a table with a column with numbers (primary key) and I need to create another column with the same values,
I want to change a table that has only numeric values (PK) to another
value, so I disable the constraints of linked tables
then I create another column that I called the "d" column and copy the values
from column A to column D
For example.
TABLE XYZ
COLUMN A: COLUMN D: (NEW)
00001 00001
00002-00002
00003-00003
00004 00004
Can I change the values in column A and D of the column will be kept
TABLE XYZ
COLUMN A: COLUMN D:
00001 99901
99902 00002
99903 00003
99904-00004
As the tables that must "point" to the column, I change the values with the new numbering
TABLE ZZZZ
COLUMN B: (the values of the column before the change)
00001
00002
00003
00004
...
I want it like this:
99901
99902
99903
99903
99904
...
In other words, I find the current value in column D of the XYZ table for the new value that is in column a.
I appreciate the help! :)Try this
Here you will find a record in test1 for a record for each line of teste2 in teste2 joined the condition t1.numer_documento2 = t2.numero_documento.This is called as subquery related Co. What you were doing was under queries that and not to join the top request.
UPDATE teste2 t2 SET NUMERO_DOCUMENTO = (SELECT T1.NUMERO_DOCUMENTO FROM teste1 t1 WHERE t1.numer_documento2 = t2.numero_documento and ROWNUM = 1 ) -- "Check/Select your data before you commit "
SS
-
Save the data in another table
Hello, I would like someone to help me with a problem I have in my program.
What makes the program is, for each iteration, take the data in 'table iter' and recorded in "table of output." But in the second iteration instead of storing the results of the first iteration offer me '1' in the first five lines.How can I solve this problem?
Thank you, Jaime
Hi pescajaime,
Please make the change mentioned in the attachments.
Thank you and best regards,
srikrishnaNF
-
read in select data from another table
Hello world.
IM Oracle11GR2 database.
I m facing the following problem:
I have 2 tables.
In the first picture, I have a few articles and 3 of these items then come.
(A) point Varchar2
(B) Item Varchar2.
(C) point digital and this point is the id of a record in the other table.
If the digital point > 0 then points A and B must be read in the second table
In the second table, I have 3 Articles.
(A) the id of the record.
B & C point are also point varchar2 and must be read in the first table, point C is > 0.
I'm looking for the way that when I write a normal selection in the first picture he gives me the point B & C of the second table if C point in the first table is > 0.
I thought to solve this problem with a trigger or something similar.
Any idea is welcome.
Regards to everyone.
You don't need a trigger for this. A simple select statement should do. Something like that? I got your if condition perfectly.
SELECT CASE WHEN (T1. C > 0) THEN (SELECT T2. B OF THE T2 WHERE T1. C = T2. (A) T1 OTHERWISE. END A,
BOX WHEN (T1. C > 0) THEN (SELECT T2. C FROM T2 WHERE T1. C = T2. (A) T1 OTHERWISE. B END HAVE B,
T1. C
FROM T1;
Look at the following example. Check if it fills your scenario.
-BEGINNING OF THE SAMPLE DATA
WITH T1 AS)
SELECT 'A' A, 'B' B, 1 C OF DOUBLE UNION ALL
SELECT 'C', ', 2 DOUBLE UNION ALL
SELECT 'DF', 'G', THE DOUBLE 0),
() AS T2
SELECT 1, 'X' B 'Y' C DOUBLE UNION ALL
SELECT 2, 'Z', 'BB' OF THE DOUBLE)
-END OF THE SAMPLE DATA
SELECT CASE WHEN (T1. C > 0) THEN (SELECT T2. B OF THE T2 WHERE T1. C = T2. (A) T1 OTHERWISE. END A,
BOX WHEN (T1. C > 0) THEN (SELECT T2. C FROM T2 WHERE T1. C = T2. (A) T1 OTHERWISE. B END HAVE B,
T1. C
FROM T1;
OUTPUT:
A B C
-- -- ----------
X Y 1 - since c > 0 A and B values in table 2 are replaced
Z BB 2 - since c > 0 A and B values in table 2 are replaced
DF G 0 - since c = 0, there is even value in table 1
Post edited by: Parth272025
-
Help the query to list all the days between MIN and MAX date in a table
Hello
Sorry, this may have already responded earlier, but I really struggled to find a previous response with the new provision of the RTO.
In a DB 11 g, I date MIN and MAX in a table:
{code}
SELECT MIN (process_date) start_date, MAX (process_date) end_date FROM my_table;
{code}
I would get every day between these 2 dates. I mean even is there is no record in the table for a date.
Is this possible?
Thanks in advance,
Olivier
Hello
Do you mean something like this?
ranit@XE11GR2>> ed Wrote file c:\rb\1.sql 1 with xx as 2 ( 3 select 4 to_date('05-06-2013','dd-mm-yyyy') min_d, 5 to_date('20-06-2013','dd-mm-yyyy') max_d 6 from dual 7 ) 8 -- 9 -- end of test data 10 -- 11 select 12 min_d + level date_x 13 from xx 14* connect by level<=(max_d-min_d) ranit@XE11GR2>> / DATE_X ------------------- 06-06-2013 00:00:00 07-06-2013 00:00:00 08-06-2013 00:00:00 09-06-2013 00:00:00 10-06-2013 00:00:00 11-06-2013 00:00:00 12-06-2013 00:00:00 13-06-2013 00:00:00 14-06-2013 00:00:00 15-06-2013 00:00:00 16-06-2013 00:00:00 17-06-2013 00:00:00 18-06-2013 00:00:00 19-06-2013 00:00:00 20-06-2013 00:00:00 15 rows selected.
-
updated line and insert them into another table with trigger.
Hi guys I have a table that looks like this.
I'm going to insert the col1 and col2 values, but I need to get the value of column 3 of table 2 and then insert the complete record in table 3. I love doing that with a trigger. I get an error message and I can't for the life of me figuere out what im doing wrong.CREATE TABLE TEST ( "COL1" VARCHAR2(20 BYTE), "COL2" VARCHAR2(20 BYTE), "COL3" VARCHAR2(20 BYTE) )
So here is my nonfunctional trigger.
Here are the two table
HERE IS THE CODE OF THE TRIGGERCREATE TABLE TESTTABLE ( "COLUMN1" NUMBER(15,0), "COLUMN2" NUMBER(15,0) ) Insert into TESTTABLE (COLUMN1,COLUMN2) values (1,5);
I get an error of trigger mutation that I tried the other iterations of the above but I'm not getting anywhere. I have dumb down my problem at these 3 table.CREATE OR REPLACE TRIGGER TRIGGER1 AFTER INSERT ON TEST FOR EACH ROW BEGIN update TEST SET COL3 = (SELECT COLUMN2 FROM TEST, TESTTABLE WHERE COLUMN1 = :new.COL1); END
Can someone point me in the right direction.You'll have to do some reading, but it comes down to process the data on education instead of line level.
You may even be not at all a trigger.
See:
http://www.Oracle-base.com/articles/9i/mutating-table-exceptions.php
http://asktom.Oracle.com/pls/asktom/asktom.download_file?p_file=6551198119097816936
Maybe you are looking for
-
How do you close firefox by double clicking on the top left corner?
as you know how you can do it in other programs? When I do in firefox is just minimize the window instead of closing.
-
Screw spaces assignments app 'desktop '.
So, I love the 'spaces' in OSX, being in particular functionality to assign different applications to different workstations. I configured it in El Capitan on update of last week, with shortcut key to switch to each of the 5 '' bureaus '' Fortunately
-
How to use the Satellite P100 with MS Vista and MS Bluetooth stack?
I use my P100 Sat for more than a year. I just reinstalled Windows Vista Ultimate from zero, and because I'm really not so satisfied Bluetooth Toshiba stack, I try to use the battery Bluetooth Microsoft original, which comes with panoramas. After rei
-
"Installation of update 18 of 25" at boot
Can't get out of this so-called update via the soft start, hard start F8. Installed the anti-virus software last night, normally closed but system unable to do anything today.
-
Hello I use avast security, and he picked up this file "cryptneturlcache" as it could not scan. It appeared only recently in my system. should I worry about this? Thank you brand