Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 458
  • Last Modified:

Need Help-Selecting specific rows to update

Below is a Oracle 9i PL/SQL statements I am trying to run.  I am receiving an ORA-00933 error (SQL command not properly ended).  
============================================================================
These are the tables invovled:

CREATE TABLE PRISMM.DOCRELATION
(
  DOCRELATION_PK    NUMBER(10),
  DOCPARENTNAME    VARCHAR2(30 BYTE),
  DOCPARENT             NUMBER(10),
  DOCCHILDNAME       VARCHAR2(30 BYTE),
  DOCCHILD                NUMBER(10)
)


CREATE TABLE PRISMQ.RESERVATION
(
  RESERVATION_PK                          NUMBER(10),
  ROOMSTAYRESERVATION              VARCHAR2(10 BYTE),
  CONFIRMATIONID                          VARCHAR2(20 BYTE),
  RESERVATIONID                            VARCHAR2(20 BYTE),
  RESERVATIONORIGINATORCODE   VARCHAR2(10 BYTE),
  ORIGINALBOOKINGDATE                DATE,
  CANCELLATIONID                           VARCHAR2(20 BYTE),
  CANCELORIGINATORCODE             VARCHAR2(10 BYTE),
  CANCELLATIONDATE                      DATE,
  STAYDATERANGE                           DATE,
  RECTYPE                                        VARCHAR2(10 BYTE),
  WEEKNUMBER                                VARCHAR2(40 BYTE),
  ORIGINALUSERID                           VARCHAR2(10 BYTE),
  LASTCHANGEUSERID                      VARCHAR2(10 BYTE),
  LASTCHANGEDATE                         DATE,
  RESERVATION_DBDATE                 DATE,
  RESV_RESCOMMENT_FK                 NUMBER(10),
  RESV_SELECTEDMEMBERSHIP_FK  NUMBER(10),
  RESV_RESGUEST_FK                      NUMBER(10),
  RESV_SPECIALREQUEST_FK           NUMBER(10),
  RESV_SERVICE_FK                         NUMBER(10),
  RESV_ROOMSTAY_FK                    NUMBER(10),
  RESV_PROFILE_FK                         NUMBER(10),
  RESV_HOTELREFERENCE_FK         NUMBER(10),
  RESV_LEGACYPROFILE_FK             NUMBER(10),
  RESV_RESVMARKETING_FK           NUMBER(10)
)

========================================================================
What I am trying to do is to select and update specific rows in table "PRISMQ.RESERVATION" where the
" r. reservation_dbdate" equals to todays date (in mm/dd/yyyy format).  The values stored in the " r.reservation_dbdate" column is in mm/dd/yyyy.

All other rows where the " r.reservation_dbdate" does not equal to todays date I want to dropped it from further processing.

If a row does equal to todays date I then want to further qualify for updating by comparing to  table "prismm.docrelation".

This is done by:

     1.   comparing the value stored in column  "d.docparent" (prismm.docrelation) to "r.reservation_pk "   
           (prismq.reservation)
     2.   d.docparentname equals to "RESERVATION"
     3.   d.docchildname equals to "LEGACYPROFILE"

If any of the above three conditions fails I want to drop the row in "PRISMQ.RESERVATION" from any further update consideration.


Let me know if there is a better way of coding.

Here is the SQL code in question
=========================================================================
UPDATE PRISMQ.RESERVATION r
   SET resv_legacyprofile_fk =
       (SELECT r.reservation_pk  FROM PRISMM.RESERVATION r
           WHERE TRUNC(SYSDATE) = r.reservation_dbdate)
               
 SELECT d.docchild FROM prismm.docrelation d
     WHERE r.reservation_pk  = d.docparent
         AND d.docparentname = 'RESERVATION'
         AND d.DOCCHILDNAME = 'LEGACYPROFILE';
            
COMMIT;




Thanks.
0
john1953
Asked:
john1953
2 Solutions
 
jdlambert1Commented:
"Commit" isn't necessary unless this is part of a multi-transaction stored procedure. Try this:

UPDATE r SET resv_legacyprofile_fk = r.reservation_pk
FROM PRISMQ.RESERVATION r, prismm.docrelation d
WHERE r.reservation_pk  = d.docparent
 AND d.docparentname = 'RESERVATION'
 AND d.DOCCHILDNAME = 'LEGACYPROFILE'
 AND To_Date(SYSDATE, 'mm/dd/yyyy') = To_Date(r.reservation_dbdate, 'mm/dd/yyyy');
0
 
vijayajaCommented:
Hi,

The initial SQL written is in a wrong way to achieve the logic. Since there is an additional select in it without a semicolon it is throwing the error.(Anyways the logic would be wrong)

Also as later mentioned yuo cannot use the FROM clause in the Update statement as written.

Try this piece of code, which I hope it achieves the functionality you are aiming for..

UPDATE PRISMQ.RESERVATION r
   SET R.resv_legacyprofile_fk =
       (SELECT          r1.reservation_pk  
        FROM          PRISMM.RESERVATION r1,
                      prismm.docrelation d       
           WHERE   TRUNC(SYSDATE) = trunc(r1.reservation_dbdate)
             and   r1.reservation_pk  = d.docparent       
             AND   d.docparentname = 'RESERVATION'      
             AND   d.DOCCHILDNAME = 'LEGACYPROFILE'
           and   r1.reservation_pk =r.reservation_pk      )
0
 
john1953Author Commented:
thanks.  jdlambert1 and vijayaja were a big help.
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now