Help needed in MERGE statement

Hi,
I am new to PL/SQL, I want to update a table called "final_test" based on the below query result.
1. I want to check whether that particular record is present or not in my "final_test" table.
2. If its present in the "final_test" table and the process_status got changed then I want to update that alone in my "final_test" table.
3. If its not present then I want to insert that record into my "final_test" table.
Basically I am retrieving the report and its status for a particular date.
select
b.id,
a.name,
a.t_name,
c.process_status,
c.time_process
from rep_tab_map a, j_tab_map b, proc_status c
where a.t_name=b.t_name
and b.id=c.id (+)
and trunc(c.date_start)=trunc(sysdate -1)
group by a.name,b.id,c.process_status,c.time_process,a.t_name
order by 2
I thought of using Merge statement but i am not sure what i have to use in ":USING" and "ON" clause.
Please help me with MERGE or with someother way.
Thanks

Assuming final_test has same structure as select list in your query:
merge
  into final_test a
  using (
         select  b.id,
                 a.name,
                 a.t_name,
                 c.process_status,
                 c.time_process
           from  rep_tab_map a,
                 j_tab_map b,
                 proc_status c
           where a.t_name=b.t_name
             and b.id=c.id(+)
             and trunc(c.date_start)=trunc(sysdate -1)
           group by a.name,b.id,c.process_status,c.time_process,a.t_name
        ) b
  on (b.id = a.id)
  when matched then update set a.name = case a.process_status
                                          when b.process_status then a.name
                                          else b.name
                                        end,
                               a.t_name = case a.process_status
                                            when b.process_status then a.t_name
                                            else b.t_name
                                          end,
                               a.process_status = b.process_status,
                               a.time_process = case a.process_status
                                                  when b.process_status then a.time_process
                                                  else b.time_process
                                                end
  when not matched then insert(
                               a.id,
                               a.name,
                               a.t_name,
                               a.process_status,
                               a.time_process
                        values(
                               b.id,
                               b.name,
                               b.t_name,
                               b.process_status,
                               b.time_process
/SY.

Similar Messages

  • Help needed on Merge statement

    Hi,
    I want to merge a record which has a LONG field to a table with LOB field.
    Am getting error "ORA-00932: inconsistent datatypes: expected - got LONG" at "to_lob(col2) " in the query. Please help in resolving this.
    Thanks
    RK
    MERGE INTO message_STG d
    USING (SELECT col1,to_lob(col2) col2
         FROM message jm
         WHERE modificationdate >= <some_date_value> ) f
    ON (d.MESSAGEID= f.MESSAGEID)
    WHEN matched THEN
    UPDATE SET
    col1=f.col1,
    col2=f.col2
    WHEN NOT matched THEN
    INSERT VALUES (f.col1,f.col2);

    Am getting error "ORA-00932: inconsistent datatypes: expected - got LONG" at "to_lob(col2) "If you read the documentation you will discover that to_lob() only works in an insert statement.
    What you will have is create a holding table with a CLOB column and insert all your MESSAGE records into it, doing the TO_LOB() there. Then you can drive your MERGE statement from that holding table.
    Is this a one-off data migration exercise or something you'll have to do regularly?
    Cheers, APC
    Blog : http://radiofreetooting.blogspot.com/

  • Help needed with if statement in a method

    Hi I�ve created 2 string arrays. One holds a one digit user id no. and the other holds a 4 digit pin number. I�ve then written a method which should take the userId no that has been sent to the method in the UserCode parameter find the same number in the custid array if it does it should then check the same position of the pin array and check that the pin number matches the pin no. the method has received in PINCode parameter.
    At the moment my method receives the parameters checks the userId no. but doesn�t move on and check the PIN array.
    Any help would be great as I�ve been staring at this for days now and I can�t see the wood from the trees!
    public boolean checkPinAndUserId(String pinCode, String userCode)
              boolean found = false;
              for (int i = 0; i < userId.length; i++)
                   if (userCode.equals(userId))
                        if (pinCode.equals(pin[i]))
                                  found = true;
                        return found;

    I've posted my code in full so hopefully everyone can see exactly what I have been doing.
    Note - my code uses the observer/observable model. The method I am having the problem with the if statement is in the class HSBC as are the string arrays. in the class ATM in the action performed PINInput button events section, when the pin count reaches 4 it sends the parameters over to the HSBC checkpin&userid method.
    I've used the System.out.println() statements to see what's going on and it receives the parameters checkes the userid array but does not move on to check that the pin parameter matches the pin array?
    Any help would be great - Hope this helps.
    * @(#)BankAssignment.java 1.0 03/04/06
    * This apllication l
    package myprojects.bankassignment;
    import java.awt.*; // import the component library
    import java.awt.event.*; // import the evnet library
    import javax.swing.*;
    import java.util.*;
    class Correct1v16 extends Frame // make a new application
         public Correct1v16() // this is the constructor method
              HSBC HSBCobj = new HSBC();
         public static void main(String args[]) // this invokes the constructor of the class and creates a runable object 'mainframe'
              Correct1v16 mainFrame = new Correct1v16(); // the constructor call of the class which creates an object of that class
    class HSBC implements Observer,  ActionListener
              Frame f5;
              JLabel refill, launch;
              TextField tRefill, tLaunch;
              JButton refillbut, launchbut;
              int count;
              String [] userId=new String [10];
              String [] pin=new String [10];
              public boolean authenticate = false;
              int i;
                   public HSBC()
                   drawFrame();
                   Atm Atmobj = new Atm(this);
                   System.out.println("Starting HSBC constructor");     
              public void drawFrame()
                   System.out.println("Start HSBC drawframe method...");
                   f5=new Frame("HSBC");
                   f5.setLayout(new FlowLayout());
                   f5.setSize(200, 200);
                   f5.addWindowListener(new WindowAdapter()
                        public void windowClosing(WindowEvent e)     
                             f5.dispose();
                             System.exit(0);     
                   refill=new JLabel("Refill ATM");
                   launch=new JLabel("Launch new ATM");
                   tRefill=new TextField(20);
                   tLaunch=new TextField(10);
                   refillbut=new JButton("Refill ATM");
                   refillbut.addActionListener(this);
                   launchbut=new JButton("Launch new ATM");
                   launchbut.addActionListener(this);
                   f5.add(refill);
                   f5.add(tRefill);
                   f5.add(refillbut);
                   f5.add(launch);
                   f5.add(tLaunch);
                   f5.add(launchbut);
                   f5.setVisible(true);
    //*********** POPULATE THE ARRAYS */     
                   pin[0]="1234";
                   pin[1]="2345";
                   pin[2]="3456";
                   pin[3]="4567";
                   pin[4]="5678";
                   pin[5]="6789";
                   pin[6]="7890";
                   pin[7]="8901";
                   pin[8]="9012";
                   pin[9]="0123";
                   userId[0]="0";
                   userId[1]="1";
                   userId[2]="2";
                   userId[3]="3";
                   userId[4]="4";
                   userId[5]="5";
                   userId[6]="6";
                   userId[7]="7";
                   userId[8]="8";
                   userId[9]="9";
              }// end drawframe method
              //     public Atm atmLink = (Atm)o;
                   public void update(Observable gm1, Object o)
                        Atm atmLink = (Atm)o;
                        tRefill.setText("Refill ATM ?");
                        atmLink.refill();
                   }//end update method
                   public void actionPerformed(ActionEvent ae)
                        if(ae.getSource() == refillbut)
    //                         Atm Atmobj.refill();
                        //     tRefill.setText("text area");     
                        //     atmLink.refill();
    //                         Atmobj.refill();
    //                         setChanged();
    //                         notifyObservers();
                        if(ae.getSource() == launchbut)
                             tLaunch.setText("new ATM opened");
                             Atm Atmobj1 = new Atm(this);
    //******** THIS METHOD RECEIVES THE PARAMETERS FROM THE ATM METHOD (LINE 580) (PINCODE AND USERCODE) BUT
    //******** IT ONLY THE ARRAY CALLED USERID (WHICH HOLDS THE USER CODE MATCHES ONE OF THE USERID'S)
    //******** I DO WANT IT TO DO THIS BUT I ALSO WANT IT TO MOVE ON AND CHECK THE PINCODE WITH THE PIN ARRAY)
    //******** IF THEY ARE BOTH TRUE I WANT IT TO RETURN TRUE - ELSE FALSE.     */                    
                   public boolean checkPinAndUserId(String pinCode, String userCode)
                        boolean found = false;
                        System.out.println("in checkpin method");
                        for (int i = 0; i < userId.length; i++)
                        System.out.println("in the userid array" + userId);
                             if (userCode.equals(userId[i]))
                                  System.out.println("checking user code array");
                                  if (pinCode.equals(pin[i]))
                                       System.out.println("checking the pin array" + pinCode);
                                       System.out.println("pin[i] = "+pin[i]);
                                  found = true;
                        return found;
         }// end HSBC class
    class Atm extends Observable implements ActionListener
              Frame f1;
              TextField t3, t5;
              JTextArea display = new JTextArea("Welcome to HSBC Bank. \n Please enter your User Identification number \n", 5, 40);
              JPanel p1, p2, p3,p4;
              private JButton but1, but2, but3, but4,but5,but6,but7,but8,but9,but0,enter,
              cancel,fivepounds,tenpounds,twentypounds,fiftypounds,clearbut, refillbut;
              int state = 1;                                        
              public String pinCode ="";
              public      String userCode ="";
              int userCodeCount = 0;
              int PINCount = 0;
              String withdrawAmount = "";
              int atmBalance =200;
              private HSBC HSBCobj;     
              //ATM constructor that receives the HSBCobj g1 reference to where the HSBC class
              // in in the program
              // Calls the drawATMFrame method
              // add the observer to the HSBCobj reference so that the ATM can tell HSBC that
              // something has changed
              public Atm(HSBC g1)
                   HSBCobj = g1;
                   drawATMFrame();
                   System.out.println("Starting Atm constructor");
                   addObserver(HSBCobj);     
              // this is the method that draws the ATM interface
              // also apply the Border Layout to the frame
              public void drawATMFrame()
                   f1=new Frame("ATM");
                   f1.setLayout(new BorderLayout());
                   f1.setSize(350, 250);
                   f1.addWindowListener(new WindowAdapter()
                        public void windowClosing(WindowEvent e)     
                             f1.dispose();
                             System.exit(0);     
                   // declare & instantiate all the buttons that will be used on the ATM
                   but1 =new JButton("1");
                   but1.addActionListener(this);
                   but2 =new JButton("2");
                   but2.addActionListener(this);
                   but3 =new JButton("3");
                   but3.addActionListener(this);
                   but4 =new JButton("4");
                   but4.addActionListener(this);
                   but5 =new JButton("5");
                   but5.addActionListener(this);
                   but6 =new JButton("6");
                   but6.addActionListener(this);
                   but7 =new JButton("7");
                   but7.addActionListener(this);
                   but8 =new JButton("8");
                   but8.addActionListener(this);
                   but9 =new JButton("9");
                   but9.addActionListener(this);
                   but0 =new JButton("0");
                   but0.addActionListener(this);
                   enter=new JButton("Enter");
                   enter.addActionListener(this);
                   cancel=new JButton("Cancel/ \n Restart");
                   cancel.addActionListener(this);
                   fivepounds =new JButton("?5");
                   fivepounds.addActionListener(this);
                   tenpounds = new JButton("?10");
                   tenpounds.addActionListener(this);
                   twentypounds = new JButton("?20");
                   twentypounds.addActionListener(this);
                   fiftypounds = new JButton("?50");
                   fiftypounds.addActionListener(this);
                   clearbut = new JButton("Clear");
                   clearbut.addActionListener(this);
                   refillbut = new JButton("Refill");
                   refillbut.addActionListener(this);
                   //declare & instantiate a textfield               
                   t3=new TextField(5);
                   // instantiate 4 JPanels     
                   p1=new JPanel();
                   p2=new JPanel();
                   p3=new JPanel();
                   p4=new JPanel();
                   // add some buttons to p1
                   p1.add(but1);
                   p1.add(but2);
                   p1.add(but3);
                   p1.add(but4);
                   p1.add(but5);
                   p1.add(but6);
                   p1.add(but7);
                   p1.add(but8);
                   p1.add(but9);               
                   p1.add(but0);
                   //add the text area field to p2
                   p2.add(display);
                   // apply the grid layout to p3
                   GridLayout layout3 = new GridLayout(4,1,5,5);
                   p3.setLayout(layout3);
                   p3.add(fivepounds);
                   p3.add(tenpounds);
                   p3.add(twentypounds);
                   p3.add(fiftypounds);
                   // apply grid layout to p4
                   GridLayout layout4 = new GridLayout(4,1,5, 5);
                   p4.setLayout(layout4);
                   p4.add(clearbut);
                   p4.add(enter);
                   p4.add(cancel);
                   p4.add(refillbut);
                   //add the panels to the different parts of the screen
                   f1.add("North", display);
                   f1.add("Center", p1);
                   f1.add("East", p4);
                   f1.add("West", p3);
                   f1.setVisible(true);
              }// end drawATMframe method
         public void actionPerformed(ActionEvent ae)
                   if(state == 1)
                             getUserIdNo(ae);
              else     if(state == 2)
                             doPINInput(ae);
                        else
                             withdrawCash(ae);     
         }// end action performed method               
    //******** STATE 1 events
    //******** USER ID INPUT
              public void getUserIdNo (ActionEvent ae)
                   if (ae.getSource() == but1)
                        display.append("*");
                        userCode = userCode + "1";
                        userCodeCount++;
                   if (ae.getSource() == but2)
                        display.append("*");
                        userCode = userCode + "2";
                        userCodeCount++;
                   if (ae.getSource() == but3)
                        display.append("*");
                        userCode = userCode + "3";
                        userCodeCount++;
                        System.out.println("user id ="+userCode);
                   if (ae.getSource() == but4)
                        display.append("*");
                        userCode = userCode = "4";
                        userCodeCount++;
                        System.out.println("user id ="+userCode);
                   if (ae.getSource() == but5)
                        display.append("*");
                        userCode = userCode + "5";
                        userCodeCount++;
                        System.out.println("user id ="+userCode);
                   if (ae.getSource() == but6)
                        display.append("*");
                        userCode = userCode + "6";
                        userCodeCount++;
                        System.out.println("user id ="+userCode);
                   if (ae.getSource() == but7)
                        display.append("*");
                        userCode = userCode + "7";
                        userCodeCount++;
                        System.out.println("user id ="+userCode);
                   if (ae.getSource() == but8)
                        display.append("*");
                        userCode = userCode + "8";
                        userCodeCount++;
                        System.out.println("user id ="+userCode);
                   if (ae.getSource() == but9)
                        display.append("*");
                        userCode = userCode + "9";
                        userCodeCount++;
                        System.out.println("user id ="+userCode);
                   if (ae.getSource() == but0)
                        display.append("*");
                        userCode = userCode + "0";
                        userCodeCount++;
                        System.out.println("user id ="+userCode);
                   if (ae.getSource() == cancel)
                        display.setText("Welcome to HSBC Bank.\n Please enter your User Identification number \n");
                        userCode = "";
                        state = 2;
                   if (ae.getSource() == clearbut)
                        display.setText("Please enter your user ID number again\n");
                        userCode = "";
                        userCodeCount = 0;
                   if (ae.getSource() == refillbut)
                        refill();
                   if (ae.getSource() == enter)
                        display.setText("Please enter your PIN \n");
                        state = 2;
                        System.out.println(" User id enter button = " + userCode);
                   if (userCodeCount == 1)
                        display.setText("Please enter your PIN \n");
                        userCode = "";
                        userCodeCount = 0;
                        state = 2;          
    //******** STATE 2               
    //******** PIN INPUT
                   public void doPINInput(ActionEvent ae)
                        if (ae.getSource() == but1)
                             {      pinCode = pinCode.concat("1");
                                  display.append("*");
                                  PINCount++;     
                        if (ae.getSource() == but2)
                             {      pinCode = pinCode.concat("2");
                                  display.append("*");
                                  PINCount++;     
                        if (ae.getSource() == but3)
                             {      pinCode = pinCode.concat("3");
                                  display.append("*");
                                  PINCount++;     
                        if (ae.getSource() == but4)
                             {      pinCode = pinCode.concat("4");
                                  display.append("*");
                                  PINCount++;     
                        if (ae.getSource() == but5)
                             {      pinCode = pinCode.concat("5");
                                  display.append("*");
                                  PINCount++;     
                        if (ae.getSource() == but6)
                             {      pinCode = pinCode.concat("6");
                                  display.append("*");
                                  PINCount++;     
                        if (ae.getSource() == but7)
                             {      pinCode = pinCode.concat("7");
                                  display.append("*");
                                  PINCount++;     
                        if (ae.getSource() == but8)
                             {      pinCode = pinCode.concat("8");
                                  display.append("*");
                                  PINCount++;     
                        if (ae.getSource() == but9)
                             {      pinCode = pinCode.concat("9");
                                  display.append("*");
                                  PINCount++;     
                        if (ae.getSource() == but0)
                             {      pinCode = pinCode.concat("0");
                                  display.append("*");
                                  PINCount++;     
                        if (ae.getSource() == clearbut)
                                  display.setText("Please enter your PIN number again \n");
                                  pinCode = "";     
                                  PINCount = 0;
                        if (ae.getSource() == cancel)
                                  display.setText("Welcome to HSBC Bank.\n Please enter your User Identification number \n");
                             state = 1;
                                  pinCode ="";
                                  PINCount = 0;                         
                        if (ae.getSource() == refillbut)
                                  refill();
    /// ************************ THIS BUTTON SENDS THE PIN & USER CODE OVER TO THE MAIN BANK
    /// ************************ (LINE 152)          
                        if (ae.getSource() == enter)
    //                         if(HSBCobj.checkPinAndUserId(pinCode, userCode))
    //                              display.setText("How much would you like to withdraw \n");
    //                    else
    //                         display.setText("Your UserId and Pin code do not match");
                        if(PINCount ==4)
                        if(HSBCobj.checkPinAndUserId(userCode,pinCode))
                                  display.setText("Enter the amount you \n want to withdraw \n ?");
                                  PINCount=0;
                        else
                        display.setText("Your User Identification Number \n and PIN number do not match! \n please try again\n");     
    //*********** STATE 3 events
    //*********** withdrawCash
         public void withdrawCash(ActionEvent ae)
    //               if (ae.getSource() == but1)
    //                    display.append("1");
    ///                    withdrawAmount = withdrawAmount+1;
         //               pinCode = pinCode.concat("2");
         //               System.out.println("Withdrawal Amount = "+withdrawAmount);
                   if(ae.getSource( ) == but1)
                        withdrawAmount = withdrawAmount + "1";
                        display.setText(withdrawAmount);
                   if(ae.getSource( ) == but2)
                        withdrawAmount = withdrawAmount + "2";
                        display.setText(withdrawAmount);
                   if(ae.getSource( ) == but3)
                        withdrawAmount = withdrawAmount + "3";
                        display.setText(withdrawAmount);
                   if(ae.getSource( ) == but4)
                        withdrawAmount = withdrawAmount + "4";
                        display.setText(withdrawAmount);
                   if(ae.getSource( ) == but5)
                        withdrawAmount = withdrawAmount + "5";
                        display.setText(withdrawAmount);
                   if(ae.getSource( ) == but6)
                        withdrawAmount = withdrawAmount + "6";
                        display.setText(withdrawAmount);
                   if(ae.getSource( ) == but7)
                        withdrawAmount = withdrawAmount + "7";
                        display.setText(withdrawAmount);
                   if(ae.getSource( ) == but8)
                        withdrawAmount = withdrawAmount + "8";
                        display.setText(withdrawAmount);
                   if(ae.getSource( ) == but9)
                        withdrawAmount = withdrawAmount + "9";
                        display.setText(withdrawAmount);
                   if(ae.getSource( ) == but0)
                        withdrawAmount = withdrawAmount + "0";
                        display.setText(withdrawAmount);
                   if (ae.getSource() == fivepounds)
                        withdrawAmount = withdrawAmount + "5";
                        display.setText(withdrawAmount);
                        atmBalance();
                   if (ae.getSource() == tenpounds)
                        withdrawAmount = withdrawAmount + "10";
                        display.setText(withdrawAmount);
                        atmBalance();
                   if (ae.getSource() == twentypounds)
                        withdrawAmount = withdrawAmount + "20";
                        display.setText(withdrawAmount);
                        atmBalance();
                   if (ae.getSource() == fiftypounds)
                        withdrawAmount = withdrawAmount + "50";
                        display.setText(withdrawAmount);
                        atmBalance();
         //          if (ae.getSource() == tenpounds)
         //               display.append("10");
         //               withdrawAmount = 10;
         //               pinCode = pinCode.concat("2");
         //               System.out.println("10 pound button pressed");
         //               atmBalance();
                   if (ae.getSource() == enter)
                        atmBalance();
                   if (ae.getSource() == refillbut)
                        System.out.println("refill but pressed");
                        refill();     
                   if (ae.getSource() == clearbut)
                        System.out.println("clear but pressed");
                        display.setText("Enter the amount you want to withdraw \n ?");
                        withdrawAmount="";
                   if (ae.getSource() == cancel)
                        display.setText("Welcome to HSBC Bank.\n Please enter your User Identification number \n");
                        withdrawAmount="";
                   pinCode ="";
                        PINCount = 0;
                        userCode = "";
                        userCodeCount = 0;
                        state = 1;
         }// end withdraw cash input method
         // checks balace of atm and withdraws cash. Also notifies onserver if atm balance is low     
              public void atmBalance()
                   String s = withdrawAmount;
                   int n = Integer.parseInt(s);
                   if ( atmBalance >= n)
                        atmBalance = atmBalance - n;
                        System.out.println("atm balance = "+ atmBalance);
                        display.setText("Thankyou for using HSBC. \nYou have withdrawn ?"+n);
                        if     (atmBalance<40)
                             System.out.println("atm balance is less than 40 - notify HSBC" );
                             setChanged();
                             notifyObservers(this);
                             /// note the refil should send a message to the controller
                             // advising a refil is needed. The Bank will send an engineer
                             // out who will fill the atm up
              }// end atmBalance method
              /// note the refil should send a message to the controller
              /// then th coontroller will send a message to this method to fill machine
              /// (this is simulating a clerk filling atm)
                   public void refill()
                        System.out.println("in refill method" );
                        atmBalance = 200;
                        System.out.println("Atm has been refilled. Atm balance = " + atmBalance);
                   //     setChanged();
                   //     notifyObservers(this);
                   }// end refill method
    // NOTE SURE ABOUT THIS - DO I USE THE UPDATE METHOD TO NOTIFY HSBC THAT ATM REQUIRES FILLING
    // THIS IS THE WRONG PART OF THE PROGRAM (SHOULD BE IN HSBC) - IGNORE
                   public void update(Observable gm1, Object gameObj)
                        display.setText("Congratulations");               
                   }//end update method
         }// end Atm method
    }// end Assignment2 class

  • Help needed in SQL statement

    Hi,
    From the SQL statement below, i need help in explaining what does the line "WHERE ( lims_sys.result.result_template_id = lims_sys.result_template_limit.result_template_id (+))" do?
    This statement was written by a vendor and now i have problem displaying some new data. Only a portion of what i need is displayed.
    SELECT "LIMS_SYS"."RESULT"."DESCRIPTION",
    "LIMS_SYS"."RESULT_TEMPLATE_LIMIT"."NUMERIC_LIMIT",
    "LIMS_SYS"."RESULT"."FORMATTED_RESULT",
    "LIMS_SYS"."RESULT"."CONCLUSION",
    "LIMS_SYS"."RESULT_USER"."U_RESULT_SEQUENCE" ,
    "LIMS_SYS"."RESULT"."RESULT_ID"
    FROM "LIMS_SYS"."RESULT",
    "LIMS_SYS"."RESULT_TEMPLATE_LIMIT",
    "LIMS_SYS"."RESULT_USER",
    "LIMS_SYS"."ALIQUOT",
    "LIMS_SYS"."SAMPLE",
    "LIMS_SYS"."SDG",
    "LIMS_SYS"."TEST"
    WHERE ( lims_sys.result.result_template_id = lims_sys.result_template_limit.result_template_id (+)) and
    ( "LIMS_SYS"."RESULT"."RESULT_ID" = "LIMS_SYS"."RESULT_USER"."RESULT_ID" ) and
    ( "LIMS_SYS"."SDG"."SDG_ID" = "LIMS_SYS"."SAMPLE"."SDG_ID" ) and
    ( "LIMS_SYS"."SAMPLE"."SAMPLE_ID" = "LIMS_SYS"."ALIQUOT"."SAMPLE_ID" ) and
    ( "LIMS_SYS"."ALIQUOT"."ALIQUOT_ID" = "LIMS_SYS"."TEST"."ALIQUOT_ID" ) and
    ( "LIMS_SYS"."TEST"."TEST_ID" = "LIMS_SYS"."RESULT"."TEST_ID" ) and
    ( ( LIMS_SYS."SDG"."SDG_ID" = :sdg_id ) AND
    ( LIMS_SYS."RESULT"."STATUS" <> 'X' ) AND
    ( LIMS_SYS."RESULT"."REPORTED" = 'T' ) AND
    ( LIMS_SYS."RESULT_USER"."U_RESULT_CATEGORY" in ( 'Metal' , 'Mean Metal', 'Range Metal')) )
    Thanks for all your help.

    Hi,
    After WHERE .......... is indicates an OUTER Join condition.
    In this type of join, system retrieves the data for matched and
    as well as unmatched.
    Example:
    EMP table have a column DEPTNO with the data 10, 20, 30 (total rows=14)
    DEPT table have a column DEPTNO with the data 10, 20, 30, 40, 50 (total rows=5)
    If the WHERE clause contained EMP.DEPTNO(+) = DEPT.DEPTNO
    then the output contain the data relative to 10, 20, 30, 40, 50 (total rows = 16)
    i.e. 14 rows (with matching data) and 2 rows (with unmatching data)
    Regards,
    Sailaja

  • Help needed with Update statements.

    Hello All,
    I am trying to learn Berkeley XMLDB and facing problem to query the inserted XML file. I have a small XML file with the following contents:
    &lt;?xml version="1.0" standalone="yes"?&gt;
    &lt;Bookstore&gt;
    &lt;Book&gt;
    &lt;book_ID&gt;1&lt;/book_ID&gt;
    &lt;title&gt;Harry Potter and the Order of the Phoenix&lt;/title&gt;
    &lt;subtitle&gt;A Photographic History&lt;/subtitle&gt;
    &lt;author&gt;
    &lt;author_fname&gt;J.K.&lt;/author_fname&gt;
    &lt;author_lname&gt;Rowling&lt;/author_lname&gt;
    &lt;/author&gt;
    &lt;price&gt;9.99&lt;/price&gt;
    &lt;year_published&gt;2004&lt;/year_published&gt;
    &lt;publisher&gt;Scholastic, Inc.&lt;/publisher&gt;
    &lt;genre&gt;Fiction&lt;/genre&gt;
    &lt;quantity_in_stock&gt;28997&lt;/quantity_in_stock&gt;
    &lt;popularity&gt;20564&lt;/popularity&gt;
    &lt;/Book&gt;
    &lt;/Bookstore&gt;
    When I try to update the TITLE of this node I have the following error message:
    C:\Users\Chandra\Desktop\BDB&gt;javac -classpath .;"C:\Program Files\Sleepycat Soft
    ware\Berkeley DB XML 2.1.8\jar\dbxml.jar";"C:\Program Files\Sleepycat Software\B
    erkeley DB XML 2.1.8\jar\db.jar" bdb.java
    bdb.java:75: illegal start of expression
    public static final String STATEMENT1 = "replace value of node collection("twopp
    ro.bdbxml")/Bookstore/Book/bookid/title with 'NEWBOOK'";
    ^
    bdb.java:80: ')' expected
    System.out.println("Done query: " + STATEMENT1);
    ^
    2 errors
    But when I remove the update statements and just try to display the TITLE of this node, I dont see any outputs. Please help me to catch up with my mistakes. Below is source code I am using to run this functionality.
    Thanks.
    import java.io.File;
    import java.io.FileNotFoundException;
    import com.sleepycat.db.DatabaseException;
    import com.sleepycat.db.Environment;
    import com.sleepycat.db.EnvironmentConfig;
    import com.sleepycat.dbxml.XmlContainer;
    import com.sleepycat.dbxml.XmlException;
    import com.sleepycat.dbxml.XmlInputStream;
    import com.sleepycat.dbxml.XmlManager;
    import com.sleepycat.dbxml.XmlUpdateContext;
    import com.sleepycat.dbxml.XmlDocument;
    import com.sleepycat.dbxml.XmlQueryContext;
    import com.sleepycat.dbxml.XmlQueryExpression;
    import com.sleepycat.dbxml.XmlResults;
    import com.sleepycat.dbxml.XmlValue;
    public class bdb{
    public static void main(String[] args)
    Environment myEnv = null;
    File envHome = new File("D:/xmldata");
    try {
    EnvironmentConfig envConf = new EnvironmentConfig();
    envConf.setAllowCreate(true); // If the environment does not
    // exits, create it.
    envConf.setInitializeCache(true); // Turn on the shared memory
    // region.
    envConf.setInitializeLocking(true); // Turn on the locking subsystem.
    envConf.setInitializeLogging(true); // Turn on the logging subsystem.
    envConf.setTransactional(true); // Turn on the transactional
    envConf.setRunRecovery(true);
    // subsystem.
    myEnv = new Environment(envHome, envConf);
    // Do BDB XML work here.
    } catch (DatabaseException de) {
    // Exception handling goes here
    } catch (FileNotFoundException fnfe) {
    // Exception handling goes here
    } finally {
    try {
    if (myEnv != null) {
    myEnv.close();
    } catch (DatabaseException de) {
    // Exception handling goes here
    XmlManager myManager = null;
    XmlContainer myContainer = null;
    // The document
    String docString = "D:/xmldata/test.xml";
    // The document's name.
    String docName = "cia";
    try {
    myManager = new XmlManager(); // Assumes the container currently exists.
    myContainer =
    myManager.createContainer("twoppro.bdbxml");
    myManager.setDefaultContainerType(XmlContainer.NodeContainer); // Need an update context for the put.
    XmlUpdateContext theContext = myManager.createUpdateContext(); // Get the input stream.
    XmlInputStream theStream =
    myManager.createLocalFileInputStream(docString); // Do the actual put
    myContainer.putDocument(docName, // The document's name
    theStream, // The actual document.
    theContext, // The update context
    // (required).
    null); // XmlDocumentConfig object
    theStream.delete();
    // Update the title
    public static final String STATEMENT1 = "*replace value of node collection("twoppro.bdbxml")/Bookstore/Book/[bookid=1]/title with 'NEWBOOK'";*
    XmlQueryContext context = myManager.createQueryContext();
    XmlQueryExpression queryExpression1 = myManager.prepare(STATEMENT1, context);
    System.out.println("Try to execute query: " +
    System.out.println("Done query: " + STATEMENT1);
    queryExpression1.execute(context);
    // Get a query context
    XmlQueryContext context = myManager.createQueryContext();
    // Set the evaluation type to Lazy.
    context.setEvaluationType(XmlQueryContext.Lazy);
    // Declare the query string
    String queryString =
    "for $u in collection('twoppro.dbxml')/Bookstore/Book/[bookid=1]"
    + "*return $u/title";*
    // Prepare (compile) the query
    XmlQueryExpression qe = myManager.prepare(queryString, context);
    XmlResults results = qe.execute(context);
    System.out.println("ok");
    System.out.println(results);
    } catch (XmlException e) {
    // Error handling goes here. You may want to check
    // for XmlException.UNIQUE_ERROR, which is raised
    // if a document with that name already exists in
    // the container. If this exception is thrown,
    // try the put again with a different name, or
    // use XmlModify to update the document.
    } catch (FileNotFoundException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
    } finally {
    try {
    if (myContainer != null) {
    myContainer.close();
    if (myManager != null) {
    myManager.close();
    } catch (XmlException ce) {
    // Exception handling goes here

    Thanks Rucong. The change you suggested did helped me to run the program correct. But I also have the display function to retrive the results and my program is parsed without any output.
    C:\Users\C\Desktop\BDB&gt;Clientbuild.bat
    C:\Users\C\Desktop\BDB&gt;javac -classpath .;"C:\Program Files\Sleepycat Soft
    ware\Berkeley DB XML 2.1.8\jar\dbxml.jar";"C:\Program Files\Sleepycat Software\B
    erkeley DB XML 2.1.8\jar\db.jar" bdb.java
    C:\Users\C\Desktop\BDB&gt;Client.bat
    C:\Users\C\Desktop\BDB&gt;java -classpath .;"C:\Program Files\Sleepycat Softw
    are\Berkeley DB XML 2.1.8\jar\dbxml.jar";"C:\Program Files\Sleepycat Software\Be
    rkeley DB XML 2.1.8\jar\db.jar" bdb
    See there is no OUPUT displayed. Is there somethinglike a 'print' I have to use in this java code.
    Any ideas ? Below is the code I am using now
    import java.io.File;
    import java.io.FileNotFoundException;
    import com.sleepycat.db.DatabaseException;
    import com.sleepycat.db.Environment;
    import com.sleepycat.db.EnvironmentConfig;
    import com.sleepycat.dbxml.XmlContainer;
    import com.sleepycat.dbxml.XmlException;
    import com.sleepycat.dbxml.XmlInputStream;
    import com.sleepycat.dbxml.XmlManager;
    import com.sleepycat.dbxml.XmlUpdateContext;
    import com.sleepycat.dbxml.XmlDocument;
    import com.sleepycat.dbxml.XmlQueryContext;
    import com.sleepycat.dbxml.XmlQueryExpression;
    import com.sleepycat.dbxml.XmlResults;
    import com.sleepycat.dbxml.XmlValue;
    public class bdb{
    public static void main(String[] args)
    Environment myEnv = null;
    File envHome = new File("D:/xmldata");
    try {
    EnvironmentConfig envConf = new EnvironmentConfig();
    envConf.setAllowCreate(true); // If the environment does not
    // exits, create it.
    envConf.setInitializeCache(true); // Turn on the shared memory
    // region.
    envConf.setInitializeLocking(true); // Turn on the locking subsystem.
    envConf.setInitializeLogging(true); // Turn on the logging subsystem.
    envConf.setTransactional(true); // Turn on the transactional
    envConf.setRunRecovery(true);
    // subsystem.
    myEnv = new Environment(envHome, envConf);
    // Do BDB XML work here.
    } catch (DatabaseException de) {
    // Exception handling goes here
    } catch (FileNotFoundException fnfe) {
    // Exception handling goes here
    } finally {
    try {
    if (myEnv != null) {
    myEnv.close();
    } catch (DatabaseException de) {
    // Exception handling goes here
    XmlManager myManager = null;
    XmlContainer myContainer = null;
    // The document
    String docString = "D:/xmldata/test.xml";
    // The document's name.
    String docName = "cia";
    try {
    myManager = new XmlManager(); // Assumes the container currently exists.
    myContainer =
    myManager.createContainer("twoppro.bdbxml");
    myManager.setDefaultContainerType(XmlContainer.NodeContainer); // Need an update context for the put.
    XmlUpdateContext theContext = myManager.createUpdateContext(); // Get the input stream.
    XmlInputStream theStream =
    myManager.createLocalFileInputStream(docString); // Do the actual put
    myContainer.putDocument(docName, // The document's name
    theStream, // The actual document.
    theContext, // The update context
    // (required).
    null); // XmlDocumentConfig object
    theStream.delete();
    // Update the title
    String STATEMENT1 = "for $n in collection('twoppro.bdbxml')/Bookstore/Book[book_ID=1]/title return replace value of node $n with 'NEWBOOK'";
    XmlQueryContext context = myManager.createQueryContext();
    XmlQueryExpression queryExpression1 = myManager.prepare(STATEMENT1, context);
    System.out.println("Done query: " + STATEMENT1);
    queryExpression1.execute(context);
    // Get a query context
    XmlQueryContext thiscontext = myManager.createQueryContext();
    // Set the evaluation type to Lazy.
    context.setEvaluationType(XmlQueryContext.Lazy);
    // Declare the query string
    String queryString =
    "for $u in collection('twoppro.dbxml')/Bookstore/Book/[bookid=1]"
    + "return $u/title";
    // Prepare (compile) the query
    XmlQueryExpression qe = myManager.prepare(queryString, thiscontext);
    XmlResults results = qe.execute(thiscontext);
    System.out.println("ok");
    System.out.println(results);
    } catch (XmlException e) {
    // Error handling goes here. You may want to check
    // for XmlException.UNIQUE_ERROR, which is raised
    // if a document with that name already exists in
    // the container. If this exception is thrown,
    // try the put again with a different name, or
    // use XmlModify to update the document.
    } catch (FileNotFoundException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
    } finally {
    try {
    if (myContainer != null) {
    myContainer.close();
    if (myManager != null) {
    myManager.close();
    } catch (XmlException ce) {
    // Exception handling goes here
    Thanks.

  • Help need on update statements

    Hi,
    How can i write a single update statement instead of these 2 update statements
    UPDATE ACCOUNT_TEMP SET REPO_ASSIGN_FLAG = 1
    WHERE ARR_ID_ACCT IN
    (SELECT LTRIM(ASR1.ARR_ID_ACCT)
    FROM ODS_ACCT_STAT_REL ASR1
    WHERE ASR1.ACCT_STAT_TYPE = 'SECONDARY'
    AND ASR1.ACCT_STAT_CDE IN ('RA','RV'))
    UPDATE ACCOUNT_TEMP SET LE_LI_FLAG = 1
    WHERE ARR_ID_ACCT IN
    (SELECT LTRIM(ASR1.ARR_ID_ACCT)
    FROM ODS_ACCT_STAT_REL ASR1
    WHERE ASR1.ACCT_STAT_TYPE = 'SECONDARY'
    AND ASR1.ACCT_STAT_CDE IN ( 'LI','LV'))
    Thanks for your help

    update account_temp
    set repo_assign_flag = case when
                             arr_id_action in (select ltrim(asr1.apr_id_acct)
                                                 from ods_acct_stat_relasr1
                                                where asr1.acct_stat_type = 'SECONDARY'
                                                  and asr1.acct_stat_cde in ('RA','RV') then 1
    set LE_LI_FLAG       = case when
                             arr_id_acct in (select ltrim(asr1.arr_id_acct)
                                               from ods_acct_stat_rel.asr1
                                              where asr1.acct_stat_type = 'SECONDARY'
                                                and asr1.acct_stat_cde in ('LI', 'LV') THEN 1
    ;But remember this code will have performace issues dont combine your updated statements if you dont need to.
    Code not tested . . .
    HTH
    Ghulam

  • Help needed on income statement query....

    Hello BW gurus,
    I need to make an income-statement query which gives the following output.
    The 5 Variables are                    
         Company Code          
         Plant               
         Fiscal Period     (12 months) in column     
         Value Type               
         Version               
    #ACCOUNT          0METYPE     METYPE-DESCRIPTION     COMPANYCODE PLANT SALES0RG
         Sales               
         Cost of Sales               
         Gross Margin               
         (Sales minus Cost Of Sales)               
         General &Admin               
         Other               
         Operating Income               
         (Gross margin minus G&A minus Other)               
         Interest Income               
         Interest Expense               
         Net Income before Tax               
         (Operating Income minus Interest Income - Interest expense)               
         Taxes               
         Net income               
         (Net Income before Tax minus Taxes)               
    Note: Sales,cost of sales,general and admin,other,interesat income,interest expense,taxes are under the hierarchy of ACCOUNT.
    Please make a quick response.
    100% points will be awarded.
    Thanks in advance.
    Sam Mathew

    Please read these:
    When your query takes too long
    When your query takes too long ...
    How to Post a SQL statement tuning request
    HOW TO: Post a SQL statement tuning request - template posting

  • Help needed to merge values from two tables -

    We have these three test tables shown, which have a common ID; And amount fields; I want the -------
    test1.val = test2.val + test3.val
    when they have common ids in them;
    I have shown the test data below: And the expected output;
    NOTE: In database with real table values - each of them have millions of rows in them. So effeciency is very important here;
    SQL> desc test1;
    Name Null? Type
    ID NUMBER
    VAL NUMBER
    SQL> desc test2;
    Name Null? Type
    ID NUMBER
    VAL NUMBER
    SQL> desc test3;
    Name Null? Type
    ID NUMBER
    VAL NUMBER
    SQL> select * from test1;
    ID VAL
    1 50
    2 50
    3 55
    4 60
    5 20
    5 rows selected.
    SQL> select * from test2;
    ID VAL
    1 25
    1 25
    2 5
    2 5
    4 75
    5 rows selected.
    SQL> select * from test3;
    ID VAL
    1 25
    1 25
    2 5
    2 25
    2 25
    5 10
    6 rows selected.
    I EXPECT the output to be:
    SQL> select * from test1;
    ID VAL
    1 100
    2 65
    3 20
    4 75
    3 20
    5 10
    6 rows selected.

    Need help with the update queries - joining three tables -

  • Help needed to  merge calenders

    iphone ios5 calender question-I only have 1 phone and 1 laptop.I need just 1 calender on the phone but somehow I have two slightly different ones that need to be merged on the phone so that the repeated items are eliminated and the different items stay. How do I do that? I don't have (or care to have) a calender on my laptop.

    I should mention that my laptop is using Vista 7 (not MAC).Thanks.

  • Help need in select statement?

    Hi experts...
    I have an internal table with 2 records...i_mara with fields matnr and ersda
    matnr   ersda
    2345    01/26/2007
    3445    02/05/2007
    i need to write a select statement to collect all MBLNR from MKPF table where BUDAT is in between 01/26/2007 and 02/05/2007..
    Thanx
    Giri

    HI vasanth and rich...
    thanks for replies...
    vasanth i am getting error with the statement.. so i assigned 6 points to u..
    DATA: RA_BUDAT RANGE OF BUDAT WITH HEADER LINE.
    Unable to interpret range.... Possible error with spelling or comma
    Rich: ur solution worked good....
    is there any possible simplest way... or this is the best way includes performance?
    Regards
    Giri

  • Help needed to merge catalogs

    I have LR4 on an old pc on which I have done lots of editing with photos that I keep on an external hard drive.  I recently went abroad and bought a new laptop and installed LR4 on it.  I have already edited some photos in it, and so now I have 2 lr4 catalogs.  I now want to copy the catalog I have on my old pc to my new one, but because they have the same name my pc asks if I want to replace the existing lrcat file, which obviously I don't!!!

    Do you want to have two separate Catalogs, or do you want to merge both these into one Catalog?
    To merge, you can (after ensuring that your external drive will appear under the same drive letter / name on both computers) copy your old catalog onto the external drive. For purposes of merging, you do not need to include the related previews, just the single .lrcat file. You can rename this copy if you want, just to keep everything clear. This catalog can be opened directly on the external drive as you wish, and will refer to the images that are also in the same place - as I say, provided the drive is not named/lettered any different than before.
    Then after connecting the external drive to your new laptop you can open your current LR catalog there. Import from Catalog allows you to point to the old catalog on the external drive and add all its contents in (the picture thumbnails, complete with all their metadata, develop edits, collections etc). If you want the images to move to the laptop's internal drive or to some other place, you can do that afterwards inside that same (merged) full catalog of everything.
    I believe the previews will need to be re-made for these added images, once they appear inside the combined catalog.
    If instead you just want the two catalogs side by side, separate, you can simply rename or move/copy around as needed (when Lightroom does not have them open). If you also move/copy and rename the previews folder identically, that remains active IIRC and does not need to be itself re-generated when that same catalog is opened in its new home. However the previews are complex and slow to copy over, and it may not be worth the trouble.

  • Help needed restoring factory state on X220!

    Hi there,
    I just bought a 2nd hand X220. The seller advertised it as having its recovery partition intact (when I remove the battery there is a license/COA sticker for Windows 7 Pro), unfortunately the previous owner installed a copy of Windows 7 Ultimate on it (which I believe might actually be a non-genuine copy).
    However, I can see the Lenovo_Recovery drive in Windows Explorer, it shows up as drive E: and has the following files (all hidden): LenovoQDrive application along with the FactoryRecovery partition containing bcdinfo.txt, cdrivebackup.wim, RECOVERY.INI and sdrivebackup.wim.
    Previously when I pressed the ThinkVantage button on startup, it would show me the menu to go to BIOS setup (F1) or choose different boot device (F12), but no F11 option.
    I read about the Recovery Repair Diskette, but also found a page saying that this doesn't apply to Windows 7 machines anymore, and that I should just install the latest Lenovo Rescue and Recovery. So I have now downloaded and installed Lenovo Rescue and Recovery 4.50, but now when I press the ThinkVantage button or F11 upon boot-up, it briefly says something like "launching recovery application..." but then proceeds to boot into WIndows 7...
    Can someone please help me restore the factory state?
    Many thanks in advance!!
    Solved!
    Go to Solution.

    Well, after 2 full days, I finally got it all sorted out, but what a way to spend your christmas holidays!! :-)
    Basically I followed the instructions from phil5 in this thread, particularly messages 3 and 6.
    So here's what I did:
    Recreated the Q: partition: copied contents of the Lenovo_Recovery partition to temporary storage.
    Reformatted entire hard disk.
    Recreated Q: partition using GParted by placing an NTFS partition, roughly 10GB, at the end of the disk.
    Copied all the Lenovo_Recovery files back there.
    Created WinPE USB disk with Imagex using Win AIK (thanks to phil5's post mentioned above).
    Booted using this disk, manually restored S: and C: partitions, again according to instructions in phil5's post.
    This resulted in a working factory state. However, when I tried to restore to a factory state from this condition, it resulted in a problem on bootup (corrupt winload.exe(?)). This is likely due to the fact that my recreated Q: drive didn't have the various files required for booting (bootmgr and whatnot). I fixed the situation by repeating the last steps from phil5's post: fixboot, fixmbr.
    From this state, now I *created* recovery media to USB! Unfortunately it wouldn't fit onto my 8GB USB key (initially), so...
    I create the recovery media to a 500GB USB hard disk.
    Used GParted to resize the partition down to smallest possible size (+/- 8GB).
    Used Clonezilla to save the disk image.
    Used Clonezilla to restore the disk image to the 8GB USB key (which I was initially informed wouldn't fit, but turns out it does!)
    End result, I am in possession of a shiny 8GB USB key with a working set of recovery media. Phew!
    Thanks all, and hope this might help someone in the future. 

  • Help needed in select statement

    Hi gurus,
    I have a table with orderentry and ordertype
    case 1 :
    i want to get the set of records when ordertype =1 repeats
    case2:
    i want to get the set of records when there is no ordertype =1
    CREATE TABLE test
    orderentry NUMBER,
    ordertype NUMBER
    INSERT into test
    values ( 10,1);
    INSERT INTO test
    VALUES (10, 2);
    INSERT INTO test
    VALUES (10, 1);
    INSERT INTO test
    VALUES (10, 2);
    INSERT INTO test
    VALUES (11, 1);
    INSERT INTO test
    VALUES (11, 2);
    INSERT INTO test
    VALUES (11, 2);
    INSERT INTO test
    VALUES (11, 2);
    INSERT INTO test
    VALUES (12, 1);
    INSERT INTO test
    VALUES (12, 1);
    INSERT INTO test
    VALUES (12, 2);
    INSERT INTO test
    VALUES (12, 2);
    INSERT INTO test
    VALUES (13, 2);
    INSERT INTO test
    VALUES (13, 2);
    INSERT INTO test
    VALUES (13, 2);
    COMMIT;
    I want the set of records when the ordertype 1 repeats
    my result should be:
    case 1:
    orderentry ordertype
    10 1
    10 2
    10 1
    10 2
    12 1
    12 1
    12 2
    12 2
    case 2:
    orderentry ordertype
    13 2
    13 2
    13 2
    Thanks in advance

    Hello
    Thank yuo for posting the create table statements and sample data. I think these do what you are looking for
    --case 1
    SELECT
        orderentry,
        ordertype
    FROM
            SELECT
                orderentry,
                ordertype,
                COUNT(CASE WHEN ordertype=1 THEN 1 END) OVER(PARTITION BY orderentry) ct
            FROM
                t_test
    WHERE
        ct > 1
    --case 2
    SELECT
        orderentry,
        ordertype
    FROM
            SELECT
                orderentry,
                ordertype,
                COUNT(CASE WHEN ordertype=1 THEN 1 END) OVER(PARTITION BY orderentry) ct
            FROM
                t_test
    WHERE
        ct = 0
    DTYLER_APP@pssdev2> select * from t_test;
    ORDERENTRY  ORDERTYPE
            10          1
            10          2
            10          1
            10          2
            11          1
            11          2
            11          2
            11          2
            12          1
            12          1
            12          2
            12          2
            13          2
            13          2
            13          2
    15 rows selected.
    DTYLER_APP@pssdev2> SELECT
      2      orderentry,
      3      ordertype
      4  FROM
      5      (
      6          SELECT
      7              orderentry,
      8              ordertype,
      9              COUNT(CASE WHEN ordertype=1 THEN 1 END) OVER(PARTITION BY orderentry) ct
    10          FROM
    11              t_test
    12      )
    13  WHERE
    14      ct > 1
    15  /
    ORDERENTRY  ORDERTYPE
            10          1
            10          2
            10          1
            10          2
            12          1
            12          1
            12          2
            12          2
    8 rows selected.
    DTYLER_APP@pssdev2> SELECT
      2      orderentry,
      3      ordertype
      4  FROM
      5      (
      6          SELECT
      7              orderentry,
      8              ordertype,
      9              COUNT(CASE WHEN ordertype=1 THEN 1 END) OVER(PARTITION BY orderentry) ct
    10          FROM
    11              t_test
    12      )
    13  WHERE
    14      ct = 0
    15  /
    ORDERENTRY  ORDERTYPE
            13          2
            13          2
            13          2
    3 rows selected.

  • Help need with Update statement -Two date columns

    I have two tables rate_change and load ,i want to update the next_rate_change_date and next_rate_change_date columns ,load table has rate_change_effe_term column has value (12) that represents months for each loan,
    i want to take that rate_change_effe_term from load table and add it to min values of rate_chng_effective_date and then update the next_rate_change_date and then continue to do for all the rows of that loan_numer.
    Please see the below sample data.
    Current_data:::
    Loan_number rate_chng_effective_date next_rate_change_date
    111111 02/01/2012 02/01/2014
    111111 03/01/2012 02/01/2014
    111111 06/01/2012 02/01/2014
    111111 07/01/2012 02/01/2014
    111111 08/01/2012 02/01/2014
    Requrired format
    Loan_number rate_chng_effective_date next_rate_change_date
    111111 02/01/2012 02/01/2014
    111111 02/01/2014 02/01/2016
    111111 02/01/2016 02/01/2018
    111111 02/01/2018 02/01/2020
    111111 02/01/2020 02/01/2022
    /* Formatted on 10/24/2012 9:34:23 PM (QP5 v5.227.12220.39724) */
    CREATE TABLE rate_change
       loan_number                NUMBER (10),
       rate_chng_effective_date   VARCHAR2 (20),
       next_rate_change_date      VARCHAR2 (20)
    INSERT INTO rate_change
         VALUES (111111, '02/01/2012', '02/01/2014');
    INSERT INTO rate_change
         VALUES (111111, '03/01/2012', '02/01/2014');
    INSERT INTO rate_change
         VALUES (111111, '06/01/2012', '02/01/2014');
    INSERT INTO rate_change
         VALUES (111111, '07/01/2012', '02/01/2014');
    INSERT INTO rate_change
         VALUES (111111, '08/01/2012', '02/01/2014');
    COMMIT;
    CREATE TABLE Load
       loan_number             NUMBER (10),
       Correct_day             VARCHAR2 (20),
       rate_change_effe_term   VARCHAR2 (20)
    INSERT INTO Load
         VALUES (111111, '02/20/2012', '24');
    INSERT INTO Load
         VALUES (222222, '02/15/2010', '96');
    COMMIT;
    Current_data:::
    Loan_number   rate_chng_effective_date        next_rate_change_date
    111111            02/01/2012                             02/01/2014
    111111            03/01/2012                              02/01/2014
    111111            06/01/2012                             02/01/2014
    111111            07/01/2012                            02/01/2014
    111111            08/01/2012                            02/01/2014
    Requrired format
    Loan_number   rate_chng_effective_date        next_rate_change_date
    111111            02/01/2012                             02/01/2014
    111111            02/01/2014                            02/01/2016
    111111            02/01/2016                             02/01/2018
    111111            02/01/2018                            02/01/2020
    111111            02/01/2020                            02/01/2022
    Any ideas ,suggestion greatly helps . Thank you  very much.

    try with below query.
    update rate_change
    SET rate_chng_effective_date   = To_CHAR(ADD_MONTHS((select MIN(TO_DATE(rate_chng_effective_date,'MM/DD/YYYY'))
                                                          FROM rate_change
                                                          WHERE loan_number = 111111)
                                                          (rownum -1)*(select rate_change_effe_term 
                                                          FROM Load
                                                          WHERE loan_number  =111111) ),'MM/DD/YYYY'  )          
         ,next_rate_change_date      = To_CHAR(ADD_MONTHS((select MIN(TO_DATE(next_rate_change_date,'MM/DD/YYYY'))
                                                          FROM rate_change
                                                          WHERE loan_number = 111111)
                                                          (rownum -1)*(select rate_change_effe_term 
                                                          FROM Load
                                                          WHERE loan_number  =111111) ),'MM/DD/YYYY'  )
    WHERE  loan_number = 111111 ;Thanks,ram

  • Help needed in the Merge Statement

    Hi All,
    I am using MERGE statement in my program. I want to maintain the log for the duplicate reords mean maintain the log for those reocrds which are updated in the merge statement.
    Can any one help me in this that how can i maintain the log?
    Thanks for your help in advance.
    kind Regards,

    http://asktom.oracle.com/pls/asktom/f?p=100:11:0::::P11_QUESTION_ID:35615502072484

Maybe you are looking for