PLS -00428-- an INTO clause is expected in the SELECT statement

I dnt know what i'm doing wrong with statement, can you help me please.
DECLARE start_date DATE:= to_date('01/09/2006' , 'DD-MON-YYYY');
end_date DATE:= to_date('30/09/2006' , 'DD-MON-YYYY');
BEGIN
SELECT t.SEC_SHORT_NAME, t.SEC_ISIN, t.SEC_NO,t.SEC_NAME, t.TRADE_DATE,
t.PAYMENT_DATE,t.COUNTERPARTY, t.PRICE , t.NOMINAL ,
                    t.TRANSACTION_NO,t.CURRENT_VALUE_PC, t.CURRENT_VALUE_SC, t.PAYMENT_AMOUNT_PC,
                    t.PAYMENT_AMOUNT_SC,
               ct.AMOUNT , ct.CURRENCY,
          sb.BUSINESS_CLASS_LEVEL_2 ,sb.BUSINESS_CLASS_LEVEL_2_NAME,
          sb.BUSINESS_CLASS_LEVEL_3 ,sb.BUSINESS_CLASS_LEVEL_3_NAME,
          sb.BUSINESS_CLASS_LEVEL_4 ,sb.BUSINESS_CLASS_LEVEL_4_NAME,
sb.BUSINESS_CLASS_LEVEL_5 ,sb.BUSINESS_CLASS_LEVEL_5_NAME
from scdat.A_TRANSACTIONS t
INNER JOIN scdat.A_COSTTAX ct     
     ON ct.TRANS_REF = t.TRANS_REF
INNER JOIN scdat.A_SECS_BUSINESS_CLASS_TS sb
ON sb.SEC_REF = t.SEC_REF           
where t.TRADE_DATE >= to_char(start_date ,'DD-MON-YYYY')
and t.TRADE_DATE < to_char(end_date ,'DD-MON-YYYY')
and ct.COST_NAME = 'Broker commission'
and sb.BUSINESS_CLASS_DEFINITION = 'FTSE';
END;

i think you should have placed your SELECT statement in a cursor variables since you
are using a date range instead of the INTO clause. this is to avoid too many rows error.
DECLARE
  Cursor c1(pStartDate Date, pEndDate Date) Is
    SELECT t.SEC_SHORT_NAME,
           t.SEC_ISIN,
           t.SEC_NO,
           t.SEC_NAME,
           t.TRADE_DATE,
           t.PAYMENT_DATE,
           t.COUNTERPARTY,
           t.PRICE,
           t.NOMINAL ,
           t.TRANSACTION_NO,
           t.CURRENT_VALUE_PC,
           t.CURRENT_VALUE_SC,
           t.PAYMENT_AMOUNT_PC,
           t.PAYMENT_AMOUNT_SC,
           ct.AMOUNT,
           ct.CURRENCY,
           sb.BUSINESS_CLASS_LEVEL_2,
           sb.BUSINESS_CLASS_LEVEL_2_NAME,
           sb.BUSINESS_CLASS_LEVEL_3,
           sb.BUSINESS_CLASS_LEVEL_3_NAME,
           sb.BUSINESS_CLASS_LEVEL_4,
           sb.BUSINESS_CLASS_LEVEL_4_NAME,
           sb.BUSINESS_CLASS_LEVEL_5,
           sb.BUSINESS_CLASS_LEVEL_5_NAME
      FROM scdat.A_TRANSACTIONS t
           INNER JOIN scdat.A_COSTTAX ct ON ct.TRANS_REF = t.TRANS_REF
           INNER JOIN scdat.A_SECS_BUSINESS_CLASS_TS sb ON sb.SEC_REF = t.SEC_REF
     WHERE t.TRADE_DATE                >= pStartDate
       AND t.TRADE_DATE                 < pEndDate
       AND ct.COST_NAME                 = 'Broker commission'
       AND sb.BUSINESS_CLASS_DEFINITION = 'FTSE';
  start_date     DATE:= to_date('01/09/2006','DD-MON-YYYY');
  end_date       DATE:= to_date('30/09/2006','DD-MON-YYYY');
BEGIN
  For c1_rec in c1(start_date, end_date) Loop
     dbms_output.put_line('t.SEC_SHORT_NAME: '||t.SEC_SHORT_NAME);
     dbms_output.put_line('t.SEC_ISIN: '||t.SEC_ISIN);
  End Loop;
END;

Similar Messages

  • Error PLS-00428: an INTO clause is expected in this SELECT statement

    Dear Experts,
    I am new PL/SQL Programming
    I am trying to run the following query i am getting Error.
    Please help me to solve the error.
    declare
        var_cd number(20);
    begin
    if :P1_TYP_CAT is not null  then
       select max(CAT_cd + 1) as var_cd from IM_AST_CAT order by CAT_cd;
       insert into IM_AST_CAT (CAT_NM, CAT_CD) values ((upper(:P1_TYP_CAT)),(:var_cd));
    else
       RAISE_APPLICATION_ERROR (-20001,'Both department and location must be provided');
    end if;   
    end;

    Others have already explained you the cause of the error. You can simplify your code like this.
    begin
      if :p1_typ_cat is not null then
         insert into im_ast_cat
              cat_nm
            , cat_cd
         select upper(:p1_type_cat)
              , max(cat_cd + 1)
           from im_ast_cat;
      else
         raise_application_error (-20001,'Both department and location must be provided');
      end if;
    end;

  • Problem with a stored procedure (Error(4,1): PLS-00428: an INTO clause..)

    Dear Oracle Experts,
    I try to use the stored procedure below but get this error :
    "Error(4,1): PLS-00428: an INTO clause is expected in this SELECT statement"
    I don't have any clue what could be wrong with my syntax. INTO wouldn't make any sense at this task.
    Does someone of you know what's wrong with my Procedure ?
    Hope someone can help,
    best regards,
    Daniel Wetzler
    create or replace PROCEDURE AnalysisCompatibility (DATEBEGIN timestamp, DATEEND timestamp)
    AS
    BEGIN
    select Fs.*,Vs.Analysispriority,Vs.Compatibility Compatibility from SigFacts Fs
    inner Join Variables Vs On
    (Fs.Var_Ref=Vs.Var_Ref and Fs.Machines_Ref=Vs.Machines_Ref )
    where Fs.DT between DATEBEGIN and DATEEND
    and
    Vs.AnalysisPriority > 0
    or
    VS.Compatibility in (6,7,8,9,10,11,13,21,22)
    order by Fs.DT,Fs.Machines_Ref desc, Vs.AnalysisPriority;
    END AnalysisCompatibility;

    I have created a table (ATREPORT.TEST) that has has got the same column name and type of the query output and i still get error message
    PLS-00403 -- statement ATreport.TESt cannot be used as an into target, pls help
    DECLARE start_date DATE := to_date('01/09/2006' , 'DD-MON-YYYY');
    end_date DATE := to_date('30/09/2006' , 'DD-MON-YYYY');
    BEGIN
    SELECT t.SEC_SHORT_NAME, t.SEC_ISIN, t.SEC_NO,t.SEC_NAME, t.TRADE_DATE,
    t.PAYMENT_DATE,t.COUNTERPARTY, t.PRICE , t.NOMINAL ,
                        t.TRANSACTION_NO,t.CURRENT_VALUE_PC, t.CURRENT_VALUE_SC, t.PAYMENT_AMOUNT_PC,
                        t.PAYMENT_AMOUNT_SC,
                   ct.AMOUNT , ct.CURRENCY,
              sb.BUSINESS_CLASS_LEVEL_2 ,sb.BUSINESS_CLASS_LEVEL_2_NAME,
              sb.BUSINESS_CLASS_LEVEL_3 ,sb.BUSINESS_CLASS_LEVEL_3_NAME,
              sb.BUSINESS_CLASS_LEVEL_4 ,sb.BUSINESS_CLASS_LEVEL_4_NAME,
    sb.BUSINESS_CLASS_LEVEL_5 ,sb.BUSINESS_CLASS_LEVEL_5_NAME
    INTO ATREPORT.TEST
    from scdat.A_TRANSACTIONS t
    INNER JOIN scdat.A_COSTTAX ct     
         ON ct.TRANS_REF = t.TRANS_REF
    INNER JOIN scdat.A_SECS_BUSINESS_CLASS_TS sb
    ON sb.SEC_REF = t.SEC_REF           
    where t.TRADE_DATE >= to_char(start_date ,'DD-MON-YYYY')
    and t.TRADE_DATE < to_char(end_date ,'DD-MON-YYYY')
    and ct.COST_NAME = 'Broker commission'
    and sb.BUSINESS_CLASS_DEFINITION = 'FTSE';
    END;

  • ERROR INTO clause is expected in SELECT

    Hi experts,
    on executing the following code on Application Express 4.0.2.00.09. I had the error like below.
    declare
    xml_Base_No_Gra_Iva number;
    xml_Base_Imponible NUMBER;
    xml_Base_Imp_Grav NUMBER;
    xml_Monto_Iva NUMBER;
    xml_Valor_Ret_Iva NUMBER;
    xml_Valor_Ret_Renta NUMBER;
    xml_Tpld_Cliente VARCHAR2(2);
    xml_Id_Cliente VARCHAR2(13);
    xml_Tipo_Comprobante VARCHAR2(2);
    xml_Numero_Comprobantes NUMBER;
    xml_Id_Informante VARCHAR2(19);
    begin
    select c."Tpld_Cliente" as xml_Tpld_Cliente,
    c."Id_Cliente" as xml_Id_Cliente,
    c."Tipo_Comprobante" as xml_Tipo_Comprobante,
    sum(c."Numero_Comprobantes") as xml_Numero_Comprobantes,
    sum(c."Base_No_Gra_Iva") as xml_Base_No_Gra_Iva,
    sum(c."Base_Imponible") as xml_Base_Imponible,
    sum(c."Base_Imp_Grav") as xml_Base_Imp_Grav,
    sum(c."Monto_Iva") as xml_Monto_Iva,
    sum(c."Valor_Ret_Iva") as xml_Valor_Ret_Iva,
    sum(c."Valor_Ret_Renta") as xml_Valor_Ret_Renta,
    c."Id_Informante" as xml_Id_Informante
    from "xml_VentasD" b
    INNER JOIN "xml_Informante" a ON (b."Id_Informante" = a."Id_Informante")
    INNER JOIN "xml_VentasD" c ON (c."Id_Informante" = b."Id_Informante"
    and c."Id_VentasD" = b."Id_VentasD"
    and c."Tpld_Cliente" = b."Tpld_Cliente"
    and c."Id_Cliente" = b."Id_Cliente")
    where a."Ruc" =:P12_RUC
    and a."Anio" =:P12_ANIO
    and a."Mes" =:P12_MES
    group by c."Tpld_Cliente", c."Id_Cliente", c."Tipo_Comprobante", c."Id_Informante"
    order by c."Tpld_Cliente", c."Id_Cliente";
    end;
    ORA-06550: line 17, column 8: PLS-00428: an INTO clause is expected in this SELECT statement
    Please can you help me?

    you declared INTO variables but not using it ...
    /* Formatted on 5/2/2013 6:58:55 PM (QP5 v5.185.11230.41888) */
    DECLARE
       xml_Base_No_Gra_Iva       NUMBER;
       xml_Base_Imponible        NUMBER;
       xml_Base_Imp_Grav         NUMBER;
       xml_Monto_Iva             NUMBER;
       xml_Valor_Ret_Iva         NUMBER;
       xml_Valor_Ret_Renta       NUMBER;
       xml_Tpld_Cliente          VARCHAR2 (2);
       xml_Id_Cliente            VARCHAR2 (13);
       xml_Tipo_Comprobante      VARCHAR2 (2);
       xml_Numero_Comprobantes   NUMBER;
       xml_Id_Informante         VARCHAR2 (19);
    BEGIN
         SELECT c."Tpld_Cliente",
                c."Id_Cliente",
                c."Tipo_Comprobante",
                SUM (c."Numero_Comprobantes"),
                SUM (c."Base_No_Gra_Iva"),
                SUM (c."Base_Imponible"),
                SUM (c."Base_Imp_Grav"),
                SUM (c."Monto_Iva"),
                SUM (c."Valor_Ret_Iva"),
                SUM (c."Valor_Ret_Renta"),
                c."Id_Informante"
           INTO xml_Tpld_Cliente,
                xml_Id_Cliente,
                xml_Tipo_Comprobante,
                xml_Numero_Comprobantes,
                xml_Base_No_Gra_Iva,
                xml_Base_Imponible,
                xml_Base_Imp_Grav,
                xml_Monto_Iva,
                xml_Valor_Ret_Iva,
                xml_Valor_Ret_Renta,
                xml_Id_Informante
           FROM "xml_VentasD" b
                INNER JOIN "xml_Informante" a
                   ON (b."Id_Informante" = a."Id_Informante")
                INNER JOIN "xml_VentasD" c
                   ON (    c."Id_Informante" = b."Id_Informante"
                       AND c."Id_VentasD" = b."Id_VentasD"
                       AND c."Tpld_Cliente" = b."Tpld_Cliente"
                       AND c."Id_Cliente" = b."Id_Cliente")
          WHERE a."Ruc" = :P12_RUC AND a."Anio" = :P12_ANIO AND a."Mes" = :P12_MES
       GROUP BY c."Tpld_Cliente",
                c."Id_Cliente",
                c."Tipo_Comprobante",
                c."Id_Informante"
       ORDER BY c."Tpld_Cliente", c."Id_Cliente";
    END;http://docs.oracle.com/cd/B19306_01/appdev.102/b14261/selectinto_statement.htm

  • How to find the select statement has written all selected values into text

    Hi,
    I am using form6i. i am selecting a set of values from database tables based upon some user parameters and writing into the text file using Text_io.put_line . In this case how we can make sure that the text fille contains all the data what we are selected from selected statement. somebody told that there might be chances of aborting of data while writing into the text file. is there any way to fild out the selected statements has written all the selected fields and corresponding output into the .txt file.
    Please suggest me.

    somebody told that there might be chances of aborting of data while writing into the text fileWhat kind of "chance" does that somebody refer to?
    If you want to verify if the number of records (lines) in the file matches the number of records from the cursor, you could re-open the written file in read-mode and count the number of lines by reading one by one, then compare the number of lines with the number of records from the cursor.

  • How to pass the parameter in the where clause of the select statement

    Hi All,
    Iam getting one of the value from the Input otd and using this value i need to query one of the tables in oracle database and selected the table using the oracle eway otd like shown below .
    otdRISKBLOCK_1.getRISKBLOCK().select() .
    where clause in side the select takes a string parameter as Iam getting the string parameter from the input otd and passing this to where clause by creating a string literal after deployment it is giving an error saying "ORA-00920: invalid relational operator".
    can any one throw some input on this .
    Thanks in Advance
    Srikanth

    You will see this error if the search condition was entered with an invalid or missing relational operator.
    You need to include a valid relational operator such as
      =, !=, ^=, <>, >, <, >=, <=, ALL, ANY, [NOT] BETWEEN, EXISTS, [NOT] IN, IS [NOT] NULL, or [NOT] LIKE in the condition. in the sql statement.
    Can you throw some more light on how are you designing your project?

  • PLS-00382 Type error in the select statement in the Cursor.

    Hi,
    I am trying to combine several different sql statements to form one large cursor for my java layer. I have attached the PL/SQL procedure that I am using and when I am trying to compile it is giving PLS-00382 error. Please help me.
    PL/SQL Code.
    CREATE OR REPLACE PROCEDURE test IS
    tmpVar NUMBER;
    TYPE checkRecord is RECORD (
    name1 APPS.EMCSV_R25_DIST_PROF_TBL.distmgrfname%TYPE,
         name2 APPS.EMCSV_R25_DIST_PROF_TBL.distmgrfname%TYPE,
         name3 APPS.EMCSV_R25_DIST_PROF_TBL.distmgrfname%TYPE,
         name4 APPS.EMCSV_R25_DIST_PROF_TBL.distmgrfname%TYPE,
         oppstatus1 APPS.EMCSV_R25_DIST_PROF_TBL.oppstatus%TYPE,
         oppcount1 APPS.EMCSV_R25_DIST_PROF_TBL.oppcount%TYPE,
         oppamount1 APPS.EMCSV_R25_DIST_PROF_TBL.oppamount%TYPE,
    oppstatus2 APPS.EMCSV_R25_DIST_PROF_TBL.oppstatus%TYPE,
         oppcount2 APPS.EMCSV_R25_DIST_PROF_TBL.oppcount%TYPE,
         oppamount2 APPS.EMCSV_R25_DIST_PROF_TBL.oppamount%TYPE,
         oppstatus3 APPS.EMCSV_R25_DIST_PROF_TBL.oppstatus%TYPE,
         oppcount3 APPS.EMCSV_R25_DIST_PROF_TBL.oppcount%TYPE,
         oppamount3 APPS.EMCSV_R25_DIST_PROF_TBL.oppamount%TYPE,
         oppstatus4 APPS.EMCSV_R25_DIST_PROF_TBL.oppstatus%TYPE,
         oppcount4 APPS.EMCSV_R25_DIST_PROF_TBL.oppcount%TYPE,
         oppamount4 APPS.EMCSV_R25_DIST_PROF_TBL.oppamount%TYPE);
    TYPE checkCur IS REF CURSOR RETURN checkRecord;
    checkCurVal checkCur;
    checkCurRec checkRecord;
    chechcurVal checkCur;
    NAME: test
    PURPOSE:
    REVISIONS:
    Ver Date Author Description
    1.0 3/8/2006 1. Created this procedure.
    NOTES:
    Automatically available Auto Replace Keywords:
    Object Name: test
    Sysdate: 3/8/2006
    Date and Time: 3/8/2006, 10:01:59 AM, and 3/8/2006 10:01:59 AM
    Username: (set in TOAD Options, Procedure Editor)
    Table Name: (set in the "New PL/SQL Object" dialog)
    BEGIN
    tmpVar := 0;
    OPEN checkCurVal FOR
    SELECT
         a.distmgrfname,
    a.distmgrlname,
         a.salesrepfname,
         a.salesreplname,
         cursor (
         SELECT b.oppstatus,
         b.oppcount,
         b.oppamount
         from APPS.EMCSV_R25_DIST_PROF_TBL b
         where b.userid = '100000001' AND
         b.reportid = 'ISARPTR25' AND
                   b.oppstatus = 'Open' AND
                   b.isoppstatusselected = 'Y'),
         cursor (
         SELECT c.oppstatus,
         c.oppcount,
         c.oppamount
         from APPS.EMCSV_R25_DIST_PROF_TBL c
         where c.userid = '100000001' AND
         c.reportid = 'ISARPTR25' AND
                   c.oppstatus = 'Commit' AND
                   c.isoppstatusselected = 'Y'),
         cursor (
         SELECT
         d.oppstatus,
         d.oppcount,
         d.oppamount
         from APPS.EMCSV_R25_DIST_PROF_TBL d
         where d.userid = '100000001' AND
         d.reportid = 'ISARPTR25' AND
                   d.oppstatus = 'Closed-Won' AND
                   d.isoppstatusselected = 'Y'),
         cursor (
         SELECT
         e.oppstatus,
         e.oppcount,
         e.oppamount
         from APPS.EMCSV_R25_DIST_PROF_TBL e
         where e.userid = '100000001' AND
         e.reportid = 'ISARPTR25' AND
                   e.oppstatus = 'Closed-Lost' AND
                   e.isoppstatusselected = 'Y')               
                   from APPS.EMCSV_R25_DIST_PROF_TBL a
         where a.userid = '100000001' AND
         a.reportid = 'ISARPTR25' AND
                   a.isoppstatusselected = 'Y' ;
         LOOP
         FETCH checkCurVal INTO checkCurRec;
              EXIT WHEN checkCurVal%NOTFOUND;
              DBMS_OUTPUT.PUT_LINE (checkCurRec.name1 ||
              checkCurRec.name2 ||
                                            checkCurRec.name3 ||
                                            checkCurRec.name4 ||
                                            checkCurRec.oppstatus1 ||
                                            checkCurRec.oppcount1 ||
                                            checkCurRec.oppamount1 ||
                                            checkCurRec.oppstatus2 ||
                                            checkCurRec.oppcount2 ||
                                            checkCurRec.oppamount2 ||
                                            checkCurRec.oppstatus3 ||
                                            checkCurRec.oppcount3 ||
                                            checkCurRec.oppamount3 ||
                                            checkCurRec.oppstatus4 ||
                                            checkCurRec.oppcount4 ||
                                            checkCurRec.oppamount4);                                        
         END LOOP;     
    END test;
    /

    Thanks for Replying.
    I am trying to build a cursor to fetch the records from the table. Table structure is something like this.
    reportid VARCHAR2(10) NOT NULL,
    distmgrid NUMBER DEFAULT 0,
    salesrepid NUMBER DEFAULT 0,
    distmgrfname VARCHAR2(40 CHAR) DEFAULT 'rfname',
    distmgrlname VARCHAR2(40 CHAR) DEFAULT 'rlname',
    salesrepfname VARCHAR2(40 CHAR) DEFAULT 'afname',
    salesreplname VARCHAR2(40 CHAR) DEFAULT 'aname',
    issalesrepselected CHAR(1 CHAR) DEFAULT 'Y',
    oppstatus VARCHAR2(40 CHAR) DEFAULT 'oppstatus',
    isoppstatusselected CHAR(1 CHAR) DEFAULT 'Y',
    oppcount NUMBER DEFAULT 0,
    oppamount NUMBER DEFAULT 0,
    oppquote NUMBER DEFAULT 0,
    Attribute1 VARCHAR2(10 CHAR),
    Attribute2 VARCHAR2(15 CHAR),
    Attribute3 NUMBER,
    Attribute4 NUMBER
    But from the above table, I am trying to build a report for which I need a cursor which I listed in the proc. Is it not possible to build a cursor within a cursor?
    Yes each individual cursor return only one row.

  • Problem with showing a group of records in dynamic page (PLS-00428  error)

    Hi
    I have problems with viewing a group of records from db. I've created Page, which "Page Type" attribute is "PL/SQL". In "PL/SQL Code" field, I've written very simple SQL query: "SELECT * FROM PORTAL_DEMO.EMP ;"
    I'd like to generate HTML table with it's result. Unfortunately, every time I get the same Exception:
    Error 30584: DBMS_SQL has raised an unhandled exception. ORA-06550: line 1, column 7: PLS-00428: an INTO clause is expected in this SELECT statement
    Is it necessary to write a COURSOR (and use HTP function) to realize this functionality? I succeed, trying this way - but it is very uncomfortable ( a lot of code ).
    What I have done in wrong way?
    Please help me.
    Best regards
    Mario

    How do I handle this?

  • Getting pls-00428 error.

    Hi all,
    I'm trying to fix some invalid objects in our 11g database and i'm getting a pls-00428 error. Not sure where the issue is originating at (keep in mind, my IT team and I are not thoroughly experienced with 11g, so I apologize if this sounds a little too newbie-ish)
    Here's the plsql:
    create or replace
    FUNCTION detail_cogs (
         sSKU varchar2
         --,dtFrom date := sysdate
    return number
    is
         nRetval number;
    begin
    select *
    --SUM(cost * ieqty) into nRetval
    from (
    select
    ie.qty ieqty
    ,ie.part
    ,ic.validdate
    ,ic.cost
    ,LAG(validdate) OVER (partition by ic.part order by validdate desc) prev_entry_time
    from
    oracle2_partexplosion_mv ie
    ,oracle2_itemcogs_mv ic
    where
    ie.sku = sSKU
    and ic.part = ie.part
    and ic.validdate <= sysdate
    order by part, validdate desc
    where
    prev_entry_time is null;
         return nRetval;
    exception
         when others then
              return null;
    end;

    Welcome to the forum.
    Reading the documentation will save you:
    PLS-00428: an INTO clause is expected in this SELECT statement
    Cause: The INTO clause of a SELECT INTO statement was omitted. For example, the code might look like SELECT deptno, dname, loc FROM dept WHERE ... instead of SELECT deptno, dname, loc INTO dept_rec FROM dept WHERE ... In PL/SQL, only a subquery is written without an INTO clause.
    http://download.oracle.com/docs/cd/E11882_01/server.112/e10880/pcmus.htm#sthref17855
    http://www.oracle.com/pls/db112/search?word=select+into&partno=e10472
    Doc home: http://www.oracle.com/pls/db112/homepage
    And please change or remove this part from your code anyway, since it's nothing but a bug:
    exception
    when others then
    return null;11g compiler warned you already about that, I may hope...

  • PLS-00428 Why SELECT must be adorned with REF CURSOR to work?

    hello
    *"PLS-00428: an INTO clause is expected in this SELECT statement"* - This problem has been resolved. I just want to understand WHY SELECT statements need to be paired with REF CURSOR.
              To reproduce this,
                   DECLARE
                        Id1 numeric(19,0);
                        Id2 numeric(19,0);
                        CreateTimestamp date;
                   BEGIN
                   -- ATTN: You'd either need to select into variable or open cursor!
                   select * from SystemUser left join Person on Person.Id = SystemUser.PersonId WHERE Person.PrimaryEmail in ('[email protected]','[email protected]');
                   END;
              Solution?
                   * In install script:
                        CREATE OR REPLACE PACKAGE types
                        AS
                             TYPE cursorType IS REF CURSOR;
                        END;
                   * Then in your query:
                        DECLARE
                             Id1 numeric(19,0);
                             Id2 numeric(19,0);
                             Result_cursor types.cursorType;
                        BEGIN
                        OPEN Result_cursor FOR select * from SystemUser left join Person on Person.Id = SystemUser.PersonId WHERE Person.PrimaryEmail in ('[email protected]','[email protected]');
                        END;
    I Googled for reasonable explaination - closest is: http://www.tek-tips.com/viewthread.cfm?qid=1338078&page=34
    That in oracle block or procedures are expected to do something and a simple SELECT is not!! (Very counter intuitive). What needs to be done is therefore to put the select output into a ref-cursor to fool oracle so that it thinks the procedure/block is actually doing something. Is this explanation right? Sounds more like an assertion than actually explaining...
    Any suggestion please? Thanks!

    Opening a cursor (ref cursor or otherwise) is not the same as executing a select statement.
    A select statement returns data, so if you are using it inside PL/SQL code it has to return that data into something i.e. a local variable or structure. You can't just select without a place for the data to go.
    Opening a cursor issues the query against the database and provides a pointer (the ref cursor), but at that point, no data has been retrieved. The pointer can then be used or passed to some other procedure or code etc. so that it may then fetch the data into a variable or structure as required.
    It's not counter-intuitive at all. It's very intuitive.

  • PL/SQL cursor loop...error  INTO clause needed...but multiple rows

    Oracle 11gR2 Linux x86_64
    Hi all,
    I am running the below PL/SQL block but getting the below error. From what I know, the INTO clause can only be used when a single row will be returned. In this case, I know it returns multiple rows, so why is it asking to use the INTO clause?
    DECLARE
      v_object VARCHAR2(10) := 'TABLE';
      v_schema VARCHAR2(30) := 'TEST';
    CURSOR tblsze_cur IS
        SELECT table_name
        FROM dba_tables
        WHERE owner='TEST'
        AND table_name IN (
        'T1',
        'T2',
        'T3');
    BEGIN
    FOR tbl_rec IN tblsze_cur
        LOOP
            select * from
            table(dbms_space.OBJECT_GROWTH_TREND
            (v_schema,tbl_rec.table_name,v_object));
        END LOOP;
    END;
    select * from table(dbms_space.OBJECT_GROWTH_TREND
    ERROR at line 21:
    ORA-06550: line 21, column 3:
    PLS-00428: an INTO clause is expected in this SELECT statement

    Ok, I think I have the TYPES correct...taken from the documentation.
    DECLARE
      v_object VARCHAR2(10) := 'TABLE';
      v_schema VARCHAR2(30) := 'TEST';
      TYPE object_growth_trend_row IS RECORD(
        timepoint      TIMESTAMP,
        space_usage    NUMBER,
        space_alloc    NUMBER,
        quality        VARCHAR(20));
      TYPE object_growth_trend_table IS TABLE OF object_growth_trend_row;
      TYPE nmtbl IS TABLE OF dba_tables.table_name%TYPE;
      tname nmtbl;
    CURSOR c1 IS
        SELECT table_name
        FROM dba_tables
        WHERE owner='TEST'
        AND table_name IN (
        'T1',
        'T2',
        'T3');
    BEGIN
    OPEN c1;
    FETCH c1 BULK COLLECT INTO tname;
    FOR i IN tname.FIRST .. tname.LAST
        LOOP
             select * from (dbms_space.OBJECT_GROWTH_TREND (v_schema, tname, v_object)) INTO object_growth_trend_table;
             DBMS_OUTPUT.PUT_LINE (object_growth_trend_table);
        END LOOP;
    CLOSE c1;
    END;
    select * from (dbms_space.OBJECT_GROWTH_TREND (v_schema,tname,v_object) INTO object_growth_trend_table);
    ERROR at line 33:
    ORA-06550: line 33, column 55:
    PL/SQL: ORA-00907: missing right parenthesis
    ORA-06550: line 33, column 9:
    PL/SQL: SQL Statement ignored

  • INTO clause expected in SELECT statement

    Hi all,
    I have this pl sql code that errors out:an INTO clause is expected in this SELECT statement.
    Code
    Declare
    prev_col1 FLOAT(10) := 0;
    temp3 temp2%rowtype;
    Begin
    select * from
    select col1, col2, col3,
    lag(col1,1,0) over(order by rownum) prev_col1
    from temp2 where <conditions here> order by col2
    where col1- prev_col1 > 10000 and col1>0 and prev_col1>0;
    End;
    I have tried in vain to use select into, with both the select statements(separately). Please advise.
    Basically, I am comparing a field with the previous field and identifying faulty fields. Then I want to replace the faulty field with the previous field.

    I have tried this in vain:
    Declare
    prev_col1 FLOAT(10) := 0;
    v_col1 temp2.col1%type;
    v_col2 temp2.col2%type;
    v_col3 temp2.col3%type;
    Begin
    select col1, col2, col3, prev_col1 into v_col1, v_col2, v_col3, prev_col1 from
    select col1, col2, col3,
    lag(col1,1,0) over(order by rownum) prev_col1
    from temp2 order by col3
    where col1- prev_col1 > 10000 and prev_col1 > 0;
    UPDATE temp2 SET col1= prev_col1 WHERE (col1- prev_col1 > 10000 and prev_col1 > 0);
    End;
    I am only able to update the declared variable:v_col1. How do I update the original value in table temp2?

  • Is it not possible to give the select single field without an into clause

    Hi,
    i have to check whether my input value( only one filed) is available in the table.
    for eg i need to check whether company code is available in the table t001.
    then i will give .
    data lv_bukrs type t001-bukrs.
    lv_bukrs = 1010.
    select single bukrs from t001 where bukrs = lv_bukrs.
    here its asking for me to give a vaible to store the bukrs that is
    select single bukrs into dummyvalue from t001 where bukrs = lv_bukrs.
    Is it not possible to give the select single fieldname without an into clause

    Its Possible by declaring the tables statement
    <b>tables : AFKO.
    select single * from AFKO where <condition>.</b>
    If SINGLE is specified, the resulting set has a single line. If the remaining additions to the SELECT command select more than one line from the database, the first line that is found is entered into the resulting set. The data objects specified after INTO may not be internal tables, and the APPENDING addition may not be used. The addition ORDER BY can also not be used.
    An exclusive lock can be set for this line using the FOR UPDATE addition when a single line is being read with SINGLE. The SELECT command is used in this case only if all primary key fields in logical expressions linked by AND are checked to make sure they are the same in the WHERE condition. Otherwise, the resulting set is empty and sy-subrc is set to 8. If the lock causes a deadlock, an exception occurs. If the FOR UPDATE addition is used, the SELECT command circumvents SAP buffering.
    Notes
    When SINGLE is being specified, the lines to be read should be clearly specified in the WHERE condition, for the sake of efficiency. When the data is read from a database table, the system does this by specifying comparison values for the primary key.
    If accessing tables for which SAP buffering is planned for single records, the SAP buffer is bypassed if the addition SINGLE is not specified. This behavior depends on the current implementation of the database interface and may change in future releases. In particular, it should not be used to bypass the SAP buffer. You should use the explicit addition BYPASSING BUFFER for this instead.
    The addition SINLGE is not permitted in a subquery.
    Regards
    - Gopi

  • Tuning Select Statement . field sequence and where clause

    Hi All
    Are there any general guidelines how to write select < field sequence >where clause < field sequence ? Is that shuld be in order of the field sequence in tables?
    And how to use this when we have a view or a inner - join . Is that separate from normal select statement that is using FOR ALL ENTRIES.
    Please let me know any general guidelines available on this,
    Amol

    Hello Amol,
    I have another hint:
    The statement FOR ALL ENTRIES will package the select statements for every five entries in the internal table. So in comparison to the following code sequence...
    LOOP AT itab.
       SELECT * FROM table WHERE key = itab-key.
    ENDLOOP
    the number of select statements is reduced to 20% with
    SELECT * FROM table INTO TABLE ...
         FOR ALL ENTRIES IN itab
         WHERE key = itab-key
    If I'm expecting a <i>huge</i>  amount of data a go a step further and create my own packages by building a range table with around 100-500 entries and execute a select there...
    LOOP AT itab.
       IF counter < 500.
          APPEND itab-key TO range-tab.   " just code example
       ENDIF.
       IF count >= 500.
          SELECT * FROM table APPENDING TABLE ...
             WHERE key IN range_tab
       ENDIF.
       " adjust and calculate counter
    ENDLOOP.
    * Don't forget last select statement after loop
    Best wishes,
    Florin

  • Using if logic in the where clause of a select statement

    I have a select clause. And in the select clause there is a variable all_off_trt that can be 'Y' or 'N'.
    In the where clause I want to make it so that if a form variable is checked and all_off_trt is 'Y' then
    exclude it else if the form variable isn't checked then select it no matter what all_off_trt is.
    Is there any way to include either and if statement or a case statement within the where clause to acheive this? If not is there another way of doing it?
    Basically I am looking for a case statement like this
    case
    when all_off_trt = 'Y' and mail_para.code = 'Y' then false
    else true
    end
    Message was edited by:
    Tugnutt7

    Ok, so that really doesn't solve my problem. I have 3 different fields that I need to do that with. Each combining in a select statement to print an email list, as well as other thing limiting the where clause.
    This is currently what I have, tested and working 100%.
    cursor email_cur is
         select unique p.email,s.all_off_trt,s.all_deceased,s.no_enroll
    from participant p, trialcom t, ethics s
    where p.status='A'
    and p.surname=t.surname
    and p.initials=t.initials
    and s.trial_cd = t.tricom
    and s.centre = t.centre
    and p.email is not null
    and (t.centre in (select code from mail_parameters where user_name=user and mail_para='CENTRE')
    or 'XX' in (select code from mail_parameters where user_name=user and mail_para='CENTRE'))
    and (t.tricom in (select code from mail_parameters where user_name=user and mail_para='TRIAL')
    or 'XX' in (select code from mail_parameters where user_name=user and mail_para='TRIAL'))
    and (t.role in (select code from mail_parameters where user_name=user and mail_para='ROLE')
    or 'XX' in (select code from mail_parameters where user_name=user and mail_para='ROLE'))
    and (p.country in (select code from mail_parameters where user_name=user and mail_para='COUNTRY')
    or 'XX' in (select code from mail_parameters where user_name=user and mail_para='COUNTRY'))
    and (t.represent in (select code from mail_parameters where user_name=user and mail_para='REPRESENT')
    or 'XX' in (select code from mail_parameters where user_name=user and mail_para='REPRESENT'));
    This is in a program unit that runs when a button is clicked. At the end of that I need to add on the 3 case statements that help further narrow down the selection of emails to be printed. Then it prints the emails selected from this statement into a file. So it has to be done right in the select statement. The three table variables are the all_off_trt, all_deceased, and no_enroll. The form has 3 checkboxes. One for each, that when checked (giving the variable associated with the checkboxes a value of 'Y') excludes all emails that have a 'Y' in the coresponding table variable.

Maybe you are looking for

  • Magnetic charging port and loss of mobile data

    I finally decided to switch to Android once I felt the iPhone update was not worth the high price tag. I decided on an Xperia Z3, and so far I have had to replace 2 devices and I am considering returning this one also. The first phone had a dead pixe

  • Powerbook G4 won't start up either in normal mode or safe mode

    Hi everybody, my fiance has a PB G4. Yesterday he wasn't able to boot his computer anymore. It got stuck w/ the gray screen and the spinning wheel. I started it in verbose mode as well as in single user mode to do the fsck but with no avail. The syst

  • Premier Pro CC does not show up in CC Desktop app

    Hello, I have recently subscribed to Creative Cloud and have had success downloading all of the available applications that show on the Creative Cloud Desktop manager.  There have been some issues with the installations stalling out, but they were ro

  • PhotoShop CS2 installer issues...

    CS2 version 9.0.2 photoshop, cant get rid of this every time I open PS... any ideas? "The Adobe Updater could not be started.  Please reinstall the application and components."

  • AIF Input Parameters - How to access the form interface?

    Hi Experts, i am trying to integrate Adobe Interactive Forms in SAP Records Management, which is working quite good so far. We implemented a Service Provider which uses an Interactive Form as a document template and uses the KPro document attributes