Copy a column of data in another table?
Hello worldI am a beginner SQL who spent ridiculous amounts of time trying to find a solution to a problem no doubt very simple.
I have two tables composed of 162000 lines each. A table has the following format:
table T1
PID NUMBER
NUMBER OF PG
NUMBER OF PCS
PS NUMBER
NUMBER OF PL
NUMBER OF DRIFTWOOD
(coercion, but a simple data)
The DRIFTWOOD column is empty, all the others are completely filled.
The other table is filled only one column:
table T2
NUMBER OF CALCULATEDCHANCE
My intention is to copy all the rows in the column T2 CALCULATEDCHANCE in the column CYBERJER from T1.
Insert will not work because it adds records. I tried to use the update, but maybe I don't get the syntax right. All I got is to copy the first value of DRIFTWOOD in all lines of CALCULATEDCHANCE.
Thanks in advance for your answers!
Try
update T2
set calculatedchance = dbms_random.value(0,100);
Tags: Database
Similar Questions
-
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
-
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.
-
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
-
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
-
Hello world
I have two tables, table 1 and table 2
Table1Columns: Name, phone number, address, JoinTime
Table2Columns: SeqNo, name, phone number, address, JoinTime
JoinTime is of type TimeStamp (0) sample data: 4 May 09 10.00.05.000000000 PM
I want to copy data from Table1 to Table2, SeqNo must be empty. How can I do it.
Any suggestions are appreciated.
Thank you
KasiYou can
insert into table2(SeqNo, LastName, Phone No, Address, JoinTime) select rownum AS SeqNo, LastName, Phone No, Address, JoinTime from table1 / -- // OR if you want to start from a particular number insert into table2(SeqNo, LastName, Phone No, Address, JoinTime) select 1000+ rownum AS SeqNo, LastName, Phone No, Address, JoinTime from table1 --// Sequence will start from 1001
SS
-
update of column based on the sum of the data from another table
I have two tables:
Table1 (col1, col2, col3, col4, val1, status) Table2 (col1, col2, col3, col4, val2)
For Table1 and Table2, column (col1, col2, col3, col4) are the primary key of composit.
Table2 could have duplicated lines, that's why I want to group by (col1, col2, col3, col4) and sum (val2)
After that, I want to update Table1.val1 with the value of sum (Table1.val2) where Table1.col1 = Table2.col1 and Table1.col2 = Table2.col2 and Table1.col3 = Table2.col3 and Table1.col4 = Table2.col4 and status = 'V '.
I did something like this:
UPDATE Table1 SET val1 = (
WHERE Table1.col1 = t_sommevbrute.col1 and Table1.col2 = t_sommevbrute.col2 and Table1.col3 = t_sommevbrute.col3 and Table1.col4 = t_sommevbrute.col4)
Could someone help me please? Thank you
merge into table1 t1
using (select col1, col2, col3, col4, sum (val2) val2
from table2
Group
by col1, col2, col3, col4) t2
on (t1.col1 = t2.col1 t1.col2 = t2.col2 and t1.col3 = t2.col3 and t1.col4 = t2.col4 and)
When matched then
update set t1.val1 = t2.val2;
-
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?
-
update of several columns of values in another table
Hello
I have two tables in a database of 11 GR 2 that contain similar data. There is no FK relationship between the two tables, and for now, I need the data in MASTER to match what is in the SECONDARY. Table data types are the same with the same length.
Table 1 is called MASTER and columns are:
MTID
ADDRESS1
ADDRESS2
CITY
Table 2 is called SECONDARY and columns are:
SDID
ADDRESS1
ADDRESS2
CITY
MID and SID are the same on both, but the rest of the columns may be the same or in some cases are different.
I ran the following query that lets me know there are 20 k odd rows that have different data in these lines (I'm not at work at the mo so do not have the exact query I ran or table column names, but it's close enough).
I need to update the rows in the master of secondary school where these values are different. I tried a few different queries updated with no luck.select m.address1 as maddress1, s.address1 as saddress1, m.address2 as maddress2, s.address2 as saddress2, m.city as mcity, s.city as scity from master m, secondary s where m.mtid = s.sdid and m.address1 != s.address1 or m.address2 != s.address2 or m.city != s.city /
I want to do something like
But I want to update columns address1 and address2, city of master.update m.address1 set m.address1=s.address1 where m.address1 != s.address1 and m.mtid = s.stid;
Any ideas on how I can do this? After you run the update results of my select query should return no rows.
Thanks in advance and I hope that the question made sense.1008991 wrote:
I got a similar error as well:update master m set (sm_user_addr_1, sm_user_addr_2, sm_user_city, sm_user_postal_cde) = (select sm_user_addr_1, sm_user_addr_2, sm_user_city, sm_user_postal_cde from secondary s where s.sd_key = m.sm_key ) where exists ( select 1 from secondary s where s.sd_key = m.sm_key and (s.sm_user_addr_1 != m.sm_user_addr_1 or s.sm_user_addr_2 != m.sm_user_addr_2 or s.sm_user_city != m.sm_user_city or s.sm_user_postal_cde != m.sm_user_postal_cde)); ERROR at line 3: ORA-01427: single-row subquery returns more than one row
It simply means that you have several lines with the same sd_key for a given sm_key.
Is that you have secondaries for one master. You must choose only one line
If you need additional terms in your where clauseselect sm_user_addr_1, sm_user_addr_2, sm_user_city, sm_user_postal_cde from secondary s where s.sd_key = m.sm_key
-
transfer data to another table
I'm using Oracle 10.2.04. I have a table table1 that has about half a million records. At the end of the year 90% of these files are only needed for purposes of archiving during 1 year.
We are planing to create archive table table2 to say is similar to table1 so that we can insert data redundant from table1 to table2 and delete the records from table1. In this way table1 is be much smaller and faster to work with.
I want to know experts in the forums, what they think of our approach and insert and delete. Is there a better way to do it. I was consider adding a flag column, maybe partitioning etc. I would like to know what you think. All the tips and suggestions is greatly appreciated.I'll get exactly the records that would be redundant. I only meant those recordset is 90% of the total number of records.
If you say so.
unique post SQL SELECT that produces the result set of records to be (re) moved.
-
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
-
on average + get data from another table
Hello..
I have two tables:
user_table: contains (user_id, username)
rating_table: contains (rating_id, side, user_id)
I am trying to create a view of the note for users...
the notice must contain:
the id, user_name, the average of the coast
I created the following script:
Select a.user_id, b.username, AVG (a.rate_value)
rating_bookstore a, user_bookstore b
where a.user_id = b.user_id
A.user_id group;
but I got the following error message:
ORA-00979: not a GROUP BY expression
any help is appreciated...
Kind regards...10 x 2 wrote:
Hello..I have two tables:
user_table: contains (user_id, username)
rating_table: contains (rating_id, side, user_id)I am trying to create a view of the note for users...
the notice must contain:
the id, user_name, the average of the coastI created the following script:
Select a.user_id, b.username, AVG (a.rate_value)
rating_bookstore a, user_bookstore b
where a.user_id = b.user_id
A.user_id group;but I got the following error message:
ORA-00979: not a GROUP BY expressionany help is appreciated...
Kind regards...Select a.user_id, b.username, AVG (a.rate_value)
rating_bookstore a, user_bookstore b
where a.user_id = b.user_id
A.user_id group, b.username; -
Update of table as select another table
Hi all
How can I update column with data from another table.
UPDATE PAR6. C CUENT
SET C.LIMIT = 0
WHERE
T.EMISA = C.EMISA
AND T.SUCUR = C.SUCUR
AND T.PRODUCT = C.PRODUCT
AND T.NUMER = C.NUMER
AND T.EMISA = 8
and T.product = 23
AND IN t.ESTA (2, 3)
ERROR: ora-00904 "T". "" ESTADO ": invalid identifier
SELECT * FROM PAR6. TRE T
WHERE T.EMISA = 8
AND T.PRODUCT = 23
AND T.ESTADO TO (2,3)
Returns 26 lines.
SELECT * FROM PAR6. C CUENT
WHERE C.EMISA = 8
AND C.PRODUCT = 23
AND C.ESTADO TO (2,3)
Returns 0 rows.
My goal is to update the 26 lines to PAR6. Table CUENT. Is it possible or I do soometing evil in general. Any help would be appreciated.
Thank you very much.
Kind regards
Robert>
UPDATE PAR6. C CUENT
SET C.LIMIT = 0
WHERE
T.EMISA = C.EMISA
AND T.SUCUR = C.SUCUR
AND T.PRODUCT = C.PRODUCT
AND T.NUMER = C.NUMER
AND T.EMISA = 8
and T.product = 23
AND IN t.ESTA (2, 3)
>Something like that.
UPDATE PAR6.CUENT C SET C.LIMIT=0 WHERE exists (select null from PAR6.TAR T where T.EMISA=C.EMISA AND T.SUCUR=C.SUCUR AND T.PRODUCT=C.PRODUCT AND T.NUMER=C.NUMER AND T.EMISA = 8 and T.product = 23 AND t.ESTA IN (2, 3) )
Visit this link for more information about correlated subqueries.
http://download.Oracle.com/docs/CD/B19306_01/server.102/b14200/queries007.htm
Thank you
REDA
@Sybrand: my apologies, I didn't see your post when I posted. However, I like the way you approach.
Published by: Raj on May 27, 2011 02:11
@Sybrand: my apologies, I didn't see your post when I posted. However, I like the way you approach. -
How to insert data into the table of plain text stored as a CLOB in another table
Hi people,
Maybe it's an easy question for someone who is more frequently used files and CLOB.
I have a table that stores text files in the CLOB column. Files text includes some basic data that I want to load in the other - a text line = a new insert for me. Is there a "trick" how to do it effectively?
Here is my model:
Table OS_IMPORT_DOCS, stores the complete files as CLOB
Sample data from OS_IMPORT_DOCSSQL> desc OS_IMPORT_DOCS Name Type Nullable Default Comments ------------- -------------- -------- ------- -------- OBJECT_ID NUMBER DATUM_ZMENY DATE sysdate FILE_PATH VARCHAR2(4000) Y FILE_NAME VARCHAR2(4000) Y FILE_SIZE NUMBER Y LAST_MODIFIED DATE Y DOCUMENT CLOB Y STATUS VARCHAR2(15) Y 'NEW'
Example of file CLOB - stored text data (select d.document from os_import_docs d where d.object_id = 1815042 ;)SQL> select * 2 from os_import_docs d 3 order by d.last_modified desc 4 ; OBJECT_ID DATUM_ZMENY FILE_PATH FILE_NAME FILE_SIZE LAST_MODIFIED DOCUMENT STATUS ---------- ----------- ------------------------------ --------------- ---------- ------------- ----------- --------------- 1815043 13.8.2012 1 d:\data\C120813.DAT C120813.DAT 16800 13.8.2012 16: <<CLOB>> NEW 1815042 13.8.2012 1 d:\data\C120812.DAT C120812.DAT 3600 12.8.2012 22: <<CLOB>> NEW 1815041 13.8.2012 1 d:\data\C120811.DAT C120811.DAT 1800 11.8.2012 13: <<CLOB>> NEW
Above the example text includes "columns" in plain text:061053120820120000AGT000002Osoby 0000000042301000000017210632 062322120820120000AGT000002Osoby 0000000012301000000017197566 063526120820120001AGT000002Osoby 0000000012301000000017197566 064234120820120001AGT000002Osoby 0000000103301000000162218777
timestamp - 1-14, SSMIHH24DDMMYYYY position format
flag - post 15-18
company code - position 19-27
etc...
How can I query data stored within the OS_IMPORT_DOCS. The DOCUMENT column, divide it into columns and insert into another table?
I have to read this method of 'online' file?
Thank you very much
TomasFor the first three columns:
SQL> create type TRecord is object ( 2 ts timestamp 3 , flag varchar2(4) 4 , company_code varchar2(9) 5 ); 6 / Type created SQL> SQL> create type TRecordTable is table of TRecord; 2 / Type created SQL> SQL> create or replace function parse_clob (p_doc in clob) 2 return TRecordTable pipelined 3 is 4 lf number; 5 eol varchar2(2) := chr(10); 6 eollen number := length(eol); 7 line varchar2(32767); 8 offs number := 1; 9 begin 10 loop 11 lf := dbms_lob.instr(p_doc, eol, offs); 12 if lf != 0 then 13 line := dbms_lob.substr(p_doc, lf - offs + 1 - eollen, offs); 14 offs := lf + eollen; 15 else 16 line := dbms_lob.substr(p_doc, dbms_lob.getlength(p_doc) - offs + 1, offs); 17 end if; 18 pipe row ( 19 TRecord( 20 to_timestamp(substr(line, 1, 14), 'HH24MISSDDMMYYYY') 21 , substr(line, 15, 4) 22 , substr(line, 19, 9) 23 ) 24 ); 25 exit when lf = 0; 26 end loop; 27 end; 28 / Function created SQL> SQL> select t.* 2 from os_import_docs d 3 , table(parse_clob(d.document)) t 4 where d.object_id = 1815042; TS FLAG COMPANY_CODE -------------------------------------- ---- ------------ 12/08/12 06:10:53,000000 0000 AGT000002 12/08/12 06:23:22,000000 0000 AGT000002 12/08/12 06:35:26,000000 0001 AGT000002 12/08/12 06:42:34,000000 0001 AGT000002
Maybe you are looking for
-
Connect via WiFi to a Surface 3 PC
I want to send files to my Surface 3 Win 10 of my iMac. In the finder, I see the surface3 in the sidebar, I click it and it says just plug and then goes down, don't demand not for any login or anything like that. Is there a way to connect, the iMac m
-
My hard drive was a mistake and it should be replaced. Model 15r 5521 and I want to know if sata 3 and 7200 RPM is compatible for this or not?
-
Upgrade to Win 10 Pro of Win 7 Home Premium, Win Pro 8 & Win Pro 8.1
Old PC died after the last update important victory 10 Pro. Bought a new PC. Installed my Win 7 Home Premium retail version. Trying to move up to Win 8 Pro in detail, followed by Win 8.1 Pro then the free win 10 Pro. Now I'm stuck to Win 8 Pro. The i
-
BlackBerry Smartphones Gmail not syncing after change of BIS
Hi all, I changed my Gmail signature via the Blackberry.com BIS mail site and now my Gmail's sync is no longer on my phone. I can always send emails via my Gmail account, but incoming e-mails are not sent to my phone. If you make changes through the
-
authentication dot1x some problom
Hello helleo WO have a problom to dot1x authentication, When I enter the configuration of configuration of dot1x in the interface, interface to authenticate user in State of err - disable Here is the configuration of the interfaceinterface FastEthern