3 Replies Latest reply: Nov 2, 2012 1:13 AM by kikolus RSS

    IF-ELSE issue in Select Statement

    TrojanSpirit
      Hello,

      I have following query in SQL Server which I am trying to convert to Oracle 11g.

      IF '[Param.1]' = 'S' OR '[Param.1]' = 'T' THEN
      select * from ULQUEUE
      END IF

      But when I write the same query in Oracle, it gives error stating Invalid SQL Statement. So how do I incorporate IF-ELSE in Select Statement in Oracle?

      Edited by: 967327 on Oct 31, 2012 2:01 PM
        • 1. Re: IF-ELSE issue in Select Statement
          AlexAnd
          >
          IF '[Param.1]' = 'S' OR '[Param.1]' = 'T' THEN
          select * from ULQUEUE
          END IF
          >
          because it's not sql statement. it's plsql statement

          for your case
          first read documentation then try smth like
          begin
          IF '[Param.1]' = 'S' OR '[Param.1]' = 'T' THEN
          select * from ULQUEUE;
          END IF;
          end;
          • 2. Re: IF-ELSE issue in Select Statement
            TrojanSpirit
            Hi,

            I tried to run the query,

            begin
            IF '[Param.1]' = 'S' OR '[Param.1]' = 'T' THEN
            select * from ULQUEUE;*
            END IF;
            end;

            But it gave me this error: ORA-06550: line 3, column 1: PLS-00428: an INTO clause is expected in this SELECT statement

            :(

            Edited by: 967327 on Nov 1, 2012 10:57 AM
            • 3. Re: IF-ELSE issue in Select Statement
              kikolus
              Hi,
              First of all, remove asterisk sign from the end of line
               
              select * from ULQUEUE;* 
              Second: where you try to put this code? This is not SQL, but PL\SQL so you have to have some variable where you want to put query result like this:
               
              declare 
              x ULQUEUE%Rowtype; 
              begin 
              select * 
              into    x 
              from ULQUEUE 
              end; 
              This of course works when your query returns only one row. Otherwise process data in the loop or put result into array.