Solved

Need Help-Selecting specific rows to update

Posted on 2004-09-22
3
450 Views
Last Modified: 2006-11-17
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
Comment
Question by:john1953
3 Comments
 
LVL 15

Accepted Solution

by:
jdlambert1 earned 250 total points
ID: 12129069
"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
 

Assisted Solution

by:vijayaja
vijayaja earned 250 total points
ID: 12131337
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
 

Author Comment

by:john1953
ID: 12259982
thanks.  jdlambert1 and vijayaja were a big help.
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying 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

Using SQL Scripts we can save all the SQL queries as files that we use very frequently on our database later point of time. This is one of the feature present under SQL Workshop in Oracle Application Express.
When it comes to protecting Oracle Database servers and systems, there are a ton of myths out there. Here are the most common.
Video by: Steve
Using examples as well as descriptions, step through each of the common simple join types, explaining differences in syntax, differences in expected outputs and showing how the queries run along with the actual outputs based upon a simple set of dem…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

680 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