Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

oracle update statement

Posted on 2011-03-15
3
Medium Priority
?
665 Views
Last Modified: 2013-12-19
experts... I have this update statement.

update
(select REP.a,REP.SCOR_NUM_A,REP.SCOR_NUM_B,
REP.SCOR_NUM_C,REP.TYPE_CODE,REP.RQST_TMS,
REP.SBMT_USER_ID,
 CDMAI.MGR_OID, cdmai.SCOR_NUM_A,
 cdmai.SCOR_NUM_C,
 cdmai.SCOR_NUM_C,
 CASE WHEN
 GREATEST (NVL (RQST_TMS_A, TO_DATE ('01/01/1900', 'MM/DD/YYYY')),NVL (
      RQST_TMS_B, TO_DATE ('01/01/1900', 'MM/DD/YYYY')), NVL (RQST_TMS_C,
      TO_DATE
      ('01/01/1900', 'MM/DD/YYYY'))) = to_date('1/1/1900','MM-DD-YYYY')
      THEN NULL
      ELSE
      GREATEST (NVL (RQST_TMS_A, TO_DATE ('01/01/1900', 'MM/DD/YYYY')),NVL (
      RQST_TMS_B, TO_DATE ('01/01/1900', 'MM/DD/YYYY')), NVL (RQST_TMS_C,
      TO_DATE
      ('01/01/1900', 'MM/DD/YYYY')))
      END as greatest_date,
 cdmai.SBMT_USER_ID,
 CDM.TYPE_CODE
from c_d_m_a_i cdmai,T_C_C_M_R_D rep,
c_d_m cdm
where  REP.APLCN_OID = CDMAI.APLCN_OID
and  CDMAI.D_M_OID = CDM.D_M_OID
and CDM.ACTVTY_TMS >= sysdate - 60)
set rep.SCOR_NUM_A = cdmai.SCOR_NUM_A,
rep.SCOR_NUM_B = cdmai.SCOR_NUM_B,
rep.SCOR_NUM_C = cdmai.SCOR_NUM_C,
rep.RQST_TMS=  greatest_date,
rep.SBMT_USER_ID= cdmai.SBMT_USER_ID,
rep.TYPE_CODE= cdm.TYPE_CODE;


It gives me an error saying that cdm.type_code is an invalid identifier. Is the update statement wrongly written? I am not that familiar with oracle update statements. Please Help!!!!
0
Comment
Question by:chickanna
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 74

Accepted Solution

by:
sdstuber earned 1200 total points
ID: 35140402
when you put your select in ()  the entities lose their identity

the enclosed query becomes its own entity

you must give it a name and each column a distinct name then you can reference them in the SET clause
0
 

Author Comment

by:chickanna
ID: 35140820
thanks for the reply. This is what I want to do in Oracle (I am new to Oracle)


update T_C_C_M_R_D
set SCOR_NUM_A = CDMAI.SCOR_NUM_A ,
SCOR_NUM_B = CDMAI.SCOR_NUM_B,
SCOR_NUM_C  = CDMAI.SCOR_NUM_C ,
RQST_TMS =  CASE WHEN
 GREATEST (NVL (RQST_TMS_A, TO_DATE ('01/01/1900', 'MM/DD/YYYY')),NVL (
      RQST_TMS_B, TO_DATE ('01/01/1900', 'MM/DD/YYYY')), NVL (RQST_TMS_C,
      TO_DATE
      ('01/01/1900', 'MM/DD/YYYY'))) = to_date('1/1/1900','MM-DD-YYYY')
      THEN NULL
      ELSE
      GREATEST (NVL (RQST_TMS_A, TO_DATE ('01/01/1900', 'MM/DD/YYYY')),NVL (
      RQST_TMS_B, TO_DATE ('01/01/1900', 'MM/DD/YYYY')), NVL (RQST_TMS_C,
      TO_DATE
      ('01/01/1900', 'MM/DD/YYYY')))
      END,
USER_ID = CDMAI.USER_ID,
TYPE_CODE = CDM.TYPE_CODE
from c_d_m_a_i cdmai, T_C_C_M_R_D rep,
c_d_m cdm
where  REP.APLCN_OID = CDMAI.APLCN_OID
and  CDMAI.APLCN_OID = CDM.APLCN_OID
and CDM.ACTVTY_TMS >= sysdate - 60)

obivously this will not work in Oracle. How do I re-formulate this query to run in Oracle 9i.
0
 
LVL 15

Assisted Solution

by:Devinder Singh Virdi
Devinder Singh Virdi earned 800 total points
ID: 35141580
try this,

UPDATE T_C_C_M_R_D rep
SET
(SCOR_NUM_A, SCOR_NUM_B, SCOR_NUM_C, RQST_TMS, USER_ID, TYPE_CODE )
= (SELECT SCOR_NUM_A, SCOR_NUM_B, SCOR_NUM_C,
    CASE WHEN
      GREATEST (NVL (RQST_TMS_A, TO_DATE ('01/01/1900', 'MM/DD/YYYY')),NVL (
      RQST_TMS_B, TO_DATE ('01/01/1900', 'MM/DD/YYYY')), NVL (RQST_TMS_C,
      TO_DATE
      ('01/01/1900', 'MM/DD/YYYY'))) = to_date('1/1/1900','MM-DD-YYYY')
      THEN NULL
      ELSE
      GREATEST (NVL (RQST_TMS_A, TO_DATE ('01/01/1900', 'MM/DD/YYYY')),NVL (
      RQST_TMS_B, TO_DATE ('01/01/1900', 'MM/DD/YYYY')), NVL (RQST_TMS_C,
      TO_DATE
      ('01/01/1900', 'MM/DD/YYYY')))
    END, USER_ID, TYPE_CODE
   FROM c_d_m_a_i cdmai, c_d_m cdm
   where  REP.APLCN_OID = CDMAI.APLCN_OID
   and  CDMAI.APLCN_OID = CDM.APLCN_OID
   and CDM.ACTVTY_TMS >= sysdate - 60)

I have not tested above query, but it should look like this  
   
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Working with Network Access Control Lists in Oracle 11g (part 1) Part 2: http://www.e-e.com/A_9074.html So, you upgraded to a shiny new 11g database and all of a sudden every program that used UTL_MAIL, UTL_SMTP, UTL_TCP, UTL_HTTP or any oth…
Introduction A previously published article on Experts Exchange ("Joins in Oracle", http://www.experts-exchange.com/Database/Oracle/A_8249-Joins-in-Oracle.html) makes a statement about "Oracle proprietary" joins and mixes the join syntax with gen…
This video shows how to Export data from an Oracle database using the Datapump Export Utility.  The corresponding Datapump Import utility is also discussed and demonstrated.
This video shows how to recover a database from a user managed backup

604 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question