Oracle FAQ | Your Portal to the Oracle Knowledge Grid |
![]() |
![]() |
Home -> Community -> Mailing Lists -> Oracle-L -> RE: Mass updates from one table to another
This message is in MIME format. Since your mail reader does not understand
this format, some or all of this message may not be legible.
------_=_NextPart_001_01BFF352.75C38E22
Content-Type: text/plain;
charset="iso-8859-1"
Not pretty but it works. Hope this is what you are looking for.
SQL> select * from test1;
NAME EXPDATE -------------------- --------- A 01-JAN-00 B 03-JAN-00 C 03-JUL-00 D 05-JUL-00 E 10-JUL-00
SQL> select * from test2;
NAME EXPDATE2 -------------------- ---------
SQL> UPDATE TEST2 A
2 SET A.EXPDATE2 =
3 (SELECT EXPDATE 4 FROM TEST1 5 WHERE NAME = A.NAME)
5 rows updated.
SQL> select * from test2;
NAME EXPDATE2 -------------------- --------- A 01-JAN-00 B 03-JAN-00 C 03-JUL-00 D 05-JUL-00 E 10-JUL-00
SQL>
-----Original Message-----
From: Yexley Robert D SSgt AFIT/SCA [mailto:Robert.Yexley_at_afit.af.mil]
Sent: Friday, July 21, 2000 4:22 PM
To: Multiple recipients of list ORACLE-L
Subject: Mass updates from one table to another
Hello everyone,
OK, I was hoping this would be a really simple update, and that I could knock it out real quick. After working on it unsuccessfully for three hours now, I'm beginning to worry about whether or not I'm prepared for my upcoming OCP test, heh. I was hoping somebody could help me with the best syntax for making this update.
OK, I have two tables in my database, that really don't need to be separate tables. I have decided to correct that problem, and combine the tables, and then update the resulting table with the data from the previous table. Here is what the two tables originally looked like:
AFITNET_USER_NAME
Name Null? Type ------------------------------- -------- ---- SSAN NOT NULL VARCHAR2(11) LOGIN_NAME NOT NULL VARCHAR2(30) INPUT_DATE NOT NULL DATE USER_NAME NOT NULL VARCHAR2(30) USER_UID NUMBER(6) HOST_ACCNT_CREATED VARCHAR2(1) UPDATE_DATE DATE UPDATE_LOGIN_NAME VARCHAR2(30) AFITNET_USER_NAME_DETAILS Name Null? Type ------------------------------- -------- ---- SSAN NOT NULL VARCHAR2(11) USER_NAME NOT NULL VARCHAR2(10) BUILDING_CODE VARCHAR2(4) ROOM_CODE VARCHAR2(5) USER_TYPE VARCHAR2(1) CLASS VARCHAR2(10) PWDEXP_CODE VARCHAR2(1) MONTH VARCHAR2(3) YEAR VARCHAR2(4) PWD_EXPIRE_DATE DATE FORM_35_SIGNED VARCHAR2(1) SIGNATURE_DATE DATE
I got rid of unused columns from AFITNET_USER_NAME_DETAILS, and put the remaining ones that are used into the AFITNET_USER_NAME table (and added a few that it didn't have before too), and we now have one table that looks like the following:
AFITNET_USER_NAME
Name Null? Type ------------------------------- -------- ---- SSAN NOT NULL VARCHAR2(11) LOGIN_NAME NOT NULL VARCHAR2(30) INPUT_DATE NOT NULL DATE USER_NAME NOT NULL VARCHAR2(30) USER_UID NUMBER(6) HOST_ACCNT_CREATED VARCHAR2(1) UPDATE_DATE DATE UPDATE_LOGIN_NAME VARCHAR2(30) BUILDING_CODE VARCHAR2(4) ROOM_CODE VARCHAR2(5) USER_TYPE VARCHAR2(1) CLASS VARCHAR2(10) PWDEXP_CODE VARCHAR2(1) PWD_EXPIRE_DATE DATE FORM_35_SIGNED VARCHAR2(1) SIGNATURE_DATE DATE SYSTEM_TYPE_CODE VARCHAR2(1) IA_DUTY_CODE VARCHAR2(1)
My problem now is this. I need to get the PWD_EXPIRE_DATE values from the AFITNET_USER_NAME_DETAILS table, into the corresponding column in the updated AFITNET_USER_NAME table, for each common SSAN in that table. I can't seem to figure out the correct syntax to make this work. Any thoughts or input would be greatly appreciated. Thanks in advance.
SSgt Robert D. Yexley
Air Force Institute of Technology
Applications Services Division (SCA)
-- Oracle Database Programmer/Administrator
<)))><
--
Author: Yexley Robert D SSgt AFIT/SCA
INET: Robert.Yexley_at_afit.af.mil
Fat City Network Services -- (858) 538-5051 FAX: (858) 538-5051 San Diego, California -- Public Internet access / Mailing Lists --------------------------------------------------------------------To REMOVE yourself from this mailing list, send an E-Mail message to: ListGuru_at_fatcity.com (note EXACT spelling of 'ListGuru') and in the message BODY, include a line containing: UNSUB ORACLE-L (or the name of mailing list you want to be removed from). You may also send the HELP command for other information (like subscribing).
------_=_NextPart_001_01BFF352.75C38E22
Content-Type: text/html;
charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN"> <HTML> <HEAD> <META HTTP-EQUIV=3D"Content-Type" CONTENT=3D"text/html; =charset=3Diso-8859-1">
<TITLE>RE: Mass updates from one table to another</TITLE> </HEAD> <BODY>
<P><FONT SIZE=3D2>Not pretty but it works. Hope this is what you =
are looking for. </FONT>
</P>
<P><FONT SIZE=3D2>SQL> select * from test1;</FONT> </P>
<P><FONT =
SIZE=3D2>NAME  =
; EXPDATE</FONT>
<BR><FONT SIZE=3D2>-------------------- ---------</FONT><BR><FONT =
<P><FONT SIZE=3D2>SQL> select * from test2;</FONT> </P>
<P><FONT =
SIZE=3D2>NAME  =
; EXPDATE2</FONT>
<BR><FONT SIZE=3D2>-------------------- ---------</FONT> <BR><FONT SIZE=3D2>A</FONT> <BR><FONT SIZE=3D2>B</FONT> <BR><FONT SIZE=3D2>C</FONT> <BR><FONT SIZE=3D2>D</FONT>
<P><FONT SIZE=3D2>SQL> UPDATE TEST2 A</FONT> <BR><FONT SIZE=3D2> 2 SET A.EXPDATE2 =3D</FONT> <BR><FONT SIZE=3D2> 3 (SELECT =EXPDATE</FONT>
<P><FONT SIZE=3D2>5 rows updated.</FONT> </P>
<P><FONT SIZE=3D2>SQL> select * from test2;</FONT> </P>
<P><FONT =
SIZE=3D2>NAME  =
; EXPDATE2</FONT>
<BR><FONT SIZE=3D2>-------------------- ---------</FONT><BR><FONT =
<P><FONT SIZE=3D2>SQL> </FONT> </P> <BR> <BR> <BR>
<P><FONT SIZE=3D2>-----Original Message-----</FONT> <BR><FONT SIZE=3D2>From: Yexley Robert D SSgt AFIT/SCA [<A = HREF=3D"mailto:Robert.Yexley_at_afit.af.mil">mailto:Robert.Yexley_at_afit.af.m= il</A>]</FONT>
<BR><FONT SIZE=3D2>Sent: Friday, July 21, 2000 4:22 PM</FONT> <BR><FONT SIZE=3D2>To: Multiple recipients of list ORACLE-L</FONT> <BR><FONT SIZE=3D2>Subject: Mass updates from one table to =another</FONT>
<P><FONT SIZE=3D2>Hello everyone,</FONT> </P>
<P><FONT SIZE=3D2>OK, I was hoping this would be a really simple =
update, and that I could</FONT>
<BR><FONT SIZE=3D2>knock it out real quick. After working on it =
unsuccessfully for three hours</FONT>
<BR><FONT SIZE=3D2>now, I'm beginning to worry about whether or not I'm =
prepared for my</FONT>
<BR><FONT SIZE=3D2>upcoming OCP test, heh. I was hoping somebody =
could help me with the best</FONT>
<BR><FONT SIZE=3D2>syntax for making this update.</FONT>
</P>
<P><FONT SIZE=3D2>OK, I have two tables in my database, that really =
don't need to be separate</FONT>
<BR><FONT SIZE=3D2>tables. I have decided to correct that =
problem, and combine the tables, and</FONT>
<BR><FONT SIZE=3D2>then update the resulting table with the data from =
the previous table. Here</FONT>
<BR><FONT SIZE=3D2>is what the two tables originally looked =
like:</FONT>
</P>
<P><FONT SIZE=3D2>AFITNET_USER_NAME</FONT> <BR><FONT =
SIZE=3D2>Name  = ;  = ; Null? Type</FONT> <BR><FONT SIZE=3D2>------------------------------- -------- ----</FONT><BR><FONT =
SIZE=3D2>SSAN  = ;  = ; NOT NULL VARCHAR2(11)</FONT><BR><FONT =
SIZE=3D2>USER_UID &= nbsp; &= nbsp; =NUMBER(6)</FONT>
SIZE=3D2>UPDATE_DATE &nbs= p; &nbs= p; DATE</FONT><BR><FONT =
<P><FONT SIZE=3D2>AFITNET_USER_NAME_DETAILS</FONT> <BR><FONT =
SIZE=3D2>Name  = ;  = ; Null? Type</FONT> <BR><FONT SIZE=3D2>------------------------------- -------- ----</FONT><BR><FONT =
SIZE=3D2>SSAN  = ;  = ; NOT NULL VARCHAR2(11)</FONT><BR><FONT =
SIZE=3D2>BUILDING_CODE &n= bsp; &n= bsp; VARCHAR2(4)</FONT><BR><FONT =
SIZE=3D2>ROOM_CODE = = =VARCHAR2(5)</FONT>
SIZE=3D2>USER_TYPE = = =VARCHAR2(1)</FONT>
SIZE=3D2>CLASS &nbs= p; &nbs= p; &nbs=p; VARCHAR2(10)</FONT>
SIZE=3D2>PWDEXP_CODE &nbs= p; &nbs= p; VARCHAR2(1)</FONT><BR><FONT =
SIZE=3D2>MONTH &nbs= p; &nbs= p; &nbs=p; VARCHAR2(3)</FONT>
SIZE=3D2>YEAR  = ;  = ;  =; VARCHAR2(4)</FONT>
SIZE=3D2>PWD_EXPIRE_DATE = = DATE</FONT><BR><FONT =
SIZE=3D2>FORM_35_SIGNED &= nbsp; &= nbsp; VARCHAR2(1)</FONT><BR><FONT =
SIZE=3D2>SIGNATURE_DATE &= nbsp; &= nbsp; DATE</FONT></P>
<P><FONT SIZE=3D2>I got rid of unused columns from =
AFITNET_USER_NAME_DETAILS, and put the</FONT>
<BR><FONT SIZE=3D2>remaining ones that are used into the =
AFITNET_USER_NAME table (and added a</FONT>
<BR><FONT SIZE=3D2>few that it didn't have before too), and we now have =
one table that looks</FONT>
<BR><FONT SIZE=3D2>like the following:</FONT>
</P>
<P><FONT SIZE=3D2>AFITNET_USER_NAME</FONT> <BR><FONT =
SIZE=3D2>Name  = ;  = ; Null? Type</FONT> <BR><FONT SIZE=3D2>------------------------------- -------- ----</FONT><BR><FONT =
SIZE=3D2>SSAN  = ;  = ; NOT NULL VARCHAR2(11)</FONT><BR><FONT =
SIZE=3D2>USER_UID &= nbsp; &= nbsp; =NUMBER(6)</FONT>
SIZE=3D2>UPDATE_DATE &nbs= p; &nbs= p; DATE</FONT><BR><FONT =
SIZE=3D2>BUILDING_CODE &n= bsp; &n= bsp; VARCHAR2(4)</FONT><BR><FONT =
SIZE=3D2>ROOM_CODE = = =VARCHAR2(5)</FONT>
SIZE=3D2>USER_TYPE = = =VARCHAR2(1)</FONT>
SIZE=3D2>CLASS &nbs= p; &nbs= p; &nbs=p; VARCHAR2(10)</FONT>
SIZE=3D2>PWDEXP_CODE &nbs= p; &nbs= p; VARCHAR2(1)</FONT><BR><FONT =
SIZE=3D2>PWD_EXPIRE_DATE = = DATE</FONT><BR><FONT =
SIZE=3D2>FORM_35_SIGNED &= nbsp; &= nbsp; VARCHAR2(1)</FONT><BR><FONT =
SIZE=3D2>SIGNATURE_DATE &= nbsp; &= nbsp; DATE</FONT><BR><FONT =
SIZE=3D2>IA_DUTY_CODE &nb= sp; &nb= sp; VARCHAR2(1)</FONT></P>
<P><FONT SIZE=3D2>My problem now is this. I need to get the =
PWD_EXPIRE_DATE values from the</FONT>
<BR><FONT SIZE=3D2>AFITNET_USER_NAME_DETAILS table, into the =
corresponding column in the</FONT>
<BR><FONT SIZE=3D2>updated AFITNET_USER_NAME table, for each common =
SSAN in that table. I</FONT>
<BR><FONT SIZE=3D2>can't seem to figure out the correct syntax to make =
this work. Any thoughts</FONT>
<BR><FONT SIZE=3D2>or input would be greatly appreciated. Thanks =
in advance.</FONT>
</P>
<P><FONT SIZE=3D2>SSgt Robert D. Yexley</FONT> <BR><FONT SIZE=3D2>Air Force Institute of Technology</FONT> <BR><FONT SIZE=3D2>Applications Services Division (SCA)</FONT> <BR><FONT SIZE=3D2>-- Oracle Database Programmer/Administrator</FONT> <BR><FONT SIZE=3D2>-- Configuration Management Officer</FONT> <BR><FONT SIZE=3D2>-- Microsoft Certified Professional</FONT> </P>
<P><FONT SIZE=3D2>* E-Mail: =
robert.yexley_at_afit.af.mil</FONT>
<BR><FONT SIZE=3D2>* Voice: DSN - 785-6565 =
x-4268</FONT>
<BR><FONT =
SIZE=3D2> &nb=
sp; Civ - =
(937) 255-6565 x-4268</FONT>
<BR><FONT =
SIZE=3D2> &nb=
sp; Fax: DSN - 986-7080</FONT>
<BR><FONT =
SIZE=3D2> &nb=
sp; Civ - =
(937) 656-7080</FONT>
<BR><FONT SIZE=3D2>* <A HREF=3D"http://sc.afit.af.mil/sca" =
TARGET=3D"_blank">http://sc.afit.af.mil/sca</A></FONT>
</P>
<P><FONT SIZE=3D2><)))><</FONT> <BR><FONT SIZE=3D2>_________________________</FONT> <BR><FONT SIZE=3D2>"God who gave us life gave us liberty. </FONT> <BR><FONT SIZE=3D2>Can the liberties of a nation be secure</FONT> <BR><FONT SIZE=3D2>when we have removed a conviction</FONT> <BR><FONT SIZE=3D2>that these liberties are a gift of God?</FONT> <BR><FONT SIZE=3D2>Indeed I tremble for my country when </FONT> <BR><FONT SIZE=3D2>I reflect that God is just, that his </FONT> <BR><FONT SIZE=3D2>justice cannot sleep forever."</FONT> <BR><FONT SIZE=3D2> - Thomas Jefferson, 3rd US =President</FONT>
<BR><FONT SIZE=3D2>______________________________</FONT></P>
<P><FONT SIZE=3D2>-- </FONT> <BR><FONT SIZE=3D2>Author: Yexley Robert D SSgt AFIT/SCA</FONT> <BR><FONT SIZE=3D2> INET: Robert.Yexley_at_afit.af.mil</FONT> </P>
<P><FONT SIZE=3D2>Fat City Network Services -- (858) =
538-5051 FAX: (858) 538-5051</FONT>
<BR><FONT SIZE=3D2>San Diego, =
California -- Public Internet =
access / Mailing Lists</FONT>
<BR><FONT =
SIZE=3D2>---------------------------------------------------------------=Received on Fri Jul 21 2000 - 15:30:07 CDT
![]() |
![]() |