Select statement in a procedure

Hi Grues,
I have written this procedure but it gives me error,
can anyone guide me what should i do.
CREATE OR REPLACE PROCEDURE FLAG_ANALYSIS IS
CURSOR CUR_FLAG IS
          SELECT SOURCE, FEAT_CODE
          FROM FLAG_ANALYSIS_SID_L3 ;
          M_SOURCE      VARCHAR2(250);
          M_FEAT_CODE      NUMBER;
          M_REL13_SID     NUMBER;
          M_REL14_SID     NUMBER;
          M_REL14_L3     NUMBER;
BEGIN
     OPEN CUR_FLAG;
LOOP
     M_SOURCE      := '-';
     M_FEAT_CODE     := 0 ;
     M_REL13_SID     := 0 ;
     M_REL14_SID     := 0 ;
     M_REL14_L3     := 0 ;
     fetch CUR_FLAG into      M_SOURCE,M_FEAT_CODE;
exit when CUR_FLAG%found = false;
     M_REL13_SID:= SELECT COUNT(*) FROM ARCHIVE_POI_14_3.REL13_3_AU_POI_INTERM A,
               POI_SHARED.SH_POI_sID B
               WHERE A.SID=B.SID AND B.FEAT_CODE=M_FEAT_CODE
               AND A.SOURCE=M_SOURCE GROUP BY A.SID;
     commit;
end loop;
     close CUR_FLAG;
commit;
end;
/

34/2 PL/SQL: SQL Statement ignored
37/41 PL/SQL: ORA-00933: SQL command not properly ended
set serveroutput on;
CREATE OR REPLACE PROCEDURE FLAG_ANALYSIS IS
CURSOR CUR_FLAG IS
          SELECT SOURCE, FEAT_CODE
          FROM FLAG_ANALYSIS_SID_L3 ;
          M_SOURCE      VARCHAR2(250);
          M_FEAT_CODE      VARCHAR2(250);
          M_REL13_SID     VARCHAR2(250);
          M_REL14_SID     VARCHAR2(250);
          M_REL14_L3     VARCHAR2(250);
BEGIN
     OPEN CUR_FLAG;
LOOP
     M_SOURCE      := '-';
     M_FEAT_CODE     := '-';
     M_REL13_SID     := '-';
     M_REL14_SID     := '-';
     M_REL14_L3     := '-';
     fetch CUR_FLAG into      M_SOURCE,M_FEAT_CODE;
exit when CUR_FLAG%found = false;
     SELECT COUNT(*) FROM ARCHIVE_POI_14_3.REL13_3_AU_POI_INTERM A,
               POI_SHARED.SH_POI_sID B
               WHERE A.SID=B.SID AND B.FEAT_CODE=M_FEAT_CODE
               AND A.SOURCE=M_SOURCE GROUP BY A.SID into M_REL13_SID;
--commit;
end loop;
     close CUR_FLAG;
commit;
end;
/

Similar Messages

  • SELECT statement in stored procedure

    I want to be able to execute a simple SELECT statement from within a stored procedure and return a stream of data which consists of all the rows from the SELECT statement.
    Ultimately, I want to ouput this stream of data to a Crystal Report.
    Apparently, Oracle will not allow you to execute a simple SELECT statement from within a stored procedure. It will only allow execution of a SELECT INTO statment, which requires that you define a cursor, etc. etc.
    Any way around this?
    Thanks
    Bill

    Look into REF CURSORs. Still not sure about whether APEX uses them though.... Good luck.

  • How to convert simple SQL Select statements into Stored Procedures?

    Hi,
    How can I convert following SELECT statement into a Stored Procedure?
    SELECT a.empno, b.deptno
    FROM emp a, dept b
    WHERE a.deptno=b.deptno;
    Thanking in advance.
    Wajid

    stored procedure is nothing but a named PL/SQL block
    so you can do it like this see below example
    SQL> create or replace procedure emp_details is
      2  cursor c1 is SELECT a.empno, b.deptno
      3  FROM scott.emp a, scott.dept b
      4  WHERE a.deptno=b.deptno;
      5  begin for c2 in c1
      6  LOOP
      7  dbms_output.put_line('name is '||c2.empno);
      8  dbms_output.put_line('deptno is ' ||c2.deptno);
      9  END LOOP;
    10  END;
    11  /
    Procedure created.and to call it use like below
    SQL> begin
      2  emp_details;
      3  end;
      4  /
    PL/SQL procedure successfully completed.
    SQL> set serveroutput on;
    SQL> /
    empno is 7839
    deptno is 10
    empno is 7698
    deptno is 30
    empno is 7782
    deptno is 10
    empno is 7566
    deptno is 20
    empno is 7654
    deptno is 30
    empno is 7499
    deptno is 30
    empno is 7844
    deptno is 30
    empno is 7900
    deptno is 30
    empno is 7521
    deptno is 30
    empno is 7902
    deptno is 20
    empno is 7369
    deptno is 20
    empno is 7788
    deptno is 20
    empno is 7876
    deptno is 20
    empno is 7934
    deptno is 10Edited by: Qwerty on Sep 17, 2009 8:37 PM

  • Re-use SELECT statement in several procedures (other than copy-and-paste)

    Our site uses a procedure of the following procedure construct to generate Excel spreadsheets:
    TYPE retCur is REF CURSOR;
    PROCEDURE get_data_for_excel (
      p_filter1 VARCHAR2
      ,p_filter2 VARCHAR2
      ,c_OutCursor out retCur
    IS
      retCursor retcur
    BEGIN
      BEGIN
      OPEN c_OutCursor FOR
        SELECT XMLELEMENT("TR", XMLFOREST(
           "col1" AS "TD"
           ,"col2" AS "TD"
           ,"col3" AS "TD"
          )).getstringval()DATA FROM (SELECT * FROM
       SELECT col1, col2, col3
       FROM sometable
       WHERE somecolumn = p_filter1
        AND someothercolumn = p_filter2
       ) x);
      END;
    END get_data_for_excel
    My question is, the subselect:
    SELECT col1, col2, col3
    FROM sometable
    is used in another procedure. Is there a way to reuse the select from the other procedure into this procedure so we don't copy-and-paste each time the other procedure is changed?
    Thanks a lot.

    This is a design decision you need to make BEFORE it goes into production.
    Right now you have
    procedure get_data_for_excel (
       p_filter1 VARCHAR2
      ,p_filter2 VARCHAR2
      ,c_OutCursor out retCur );
    What, I think jihuyao is trying to say is:  convert it to a pipelined function.
    I agree with jihuyao as I have ran into to this problem before.
    create type d4e_t as object ( DATA xmltype);
    create type d4e_table is table of d4e_t;
    create or replace function get_data_for_excel (
       p_filter1 VARCHAR2
      ,p_filter2 VARCHAR2 )
      return d4e_table pipelined;
    as
    begin
      for curr in ( --start of SELECT statement
    SELECT XMLELEMENT("TR", XMLFOREST(
           "col1" AS "TD"
           ,"col2" AS "TD"
           ,"col3" AS "TD"
          )).getstringval()DATA FROM (SELECT * FROM
       SELECT col1, col2, col3
       FROM sometable
       WHERE somecolumn = p_filter1
        AND someothercolumn = p_filter2
       ) x) )
    LOOP
      pipe row( d4e_t( curr.data ) );
    end loop;
    return;
    end;
    From there, you use it elsewhere as if it were a table.
    insert into t
    select X.data from table( get_data_for_excel( l_var1, l_var2 ) ) X;
    MK

  • Select statement or a procedure or a function required for this requirement

    i have 2 tables t1 and t2.
    t1 contains 1 column,named as c_id
    t2 contains 2 columns, named as tc_id and preceeding_c_id.
    select * from t1;
    c_id
    100
    200
    300
    400
    select * from t2;
    tc_id preceeding_c_id
    150 100
    180 150
    100
    190 180
    210 200
    250 210
    260 250
    Now my requirement is:
    I need to send a parameter as :c_id = 100
    the ouput should be as follows
    100
    150
    180
    190
    :c_id = 200
    the output should be as follows:
    200
    210
    250
    260
    Thanks & Regards

    SQL> variable c_id number
    SQL> exec :c_id := 100
    PL/SQL procedure successfully completed.
    SQL> with t as (
      2             select 150 tc_id, 100 preceeding_c_id from dual union all
      3             select 180, 150 from dual union all
      4             select 100, null from dual union all
      5             select 190, 180 from dual union all
      6             select 210, 200 from dual union all
      7             select 250, 210 from dual union all
      8             select 260, 250 from dual
      9            )
    10   select  tc_id
    11     from  t
    12     start with preceeding_c_id = :c_id
    13     connect by preceeding_c_id = prior tc_id
    14  union all
    15   select  :c_id
    16     from  dual
    17  order by 1
    18  /
         TC_ID
           100
           150
           180
           190
    SQL> exec :c_id := 200
    PL/SQL procedure successfully completed.
    SQL> /
         TC_ID
           200
           210
           250
           260
    SQL> SY.

  • Creating multiple datasets using mulitple select statements as part of one macro / stored procedure

    Hi,
    I am working on a report what has 10 datasets derived from 10 different select statements.
    Is it possilbe to save those 10 select statements as a macro / stored procedure and then use that macro to generate those dataset in the ssrs report builder ?
    AshishSinghal

    Hi AshishSinghal84,
    According to your description, you want to write multiple select statements in a procedure, then use the procedure as dataset in the report, right?
    According to my knowledge, when we write multiple select statements in a procedure, we have to create relationship between these select statements, otherwise it will only return the first one query's fields. If you are using SSRS 2008 R2, you can use Lookup
    function to display these fields from different datasets on one data region control, but the prerequisite is that you must have one common field. For more information about lookup function, please see:
    http://msdn.microsoft.com/en-us/library/ee210531.aspx
    If all these solution you cannot achieve due to your special condition, the last workaround is to use subreport to display all the fields together.
    If you have any more questions, please feel free to ask.
    Thanks,
    Wendy Fu
    Wendy Fu
    TechNet Community Support

  • Select statement or procedure

    Hi experts,
    I have to run the report every week
    In my sample data endreportafter column determines how many times the report runs
    run_sunday.... determines which day of the week the reportshould run (1 means reports runs on that day)
    startreportdate is the day the report should run.
    can any one help me to get the result by using select statement or using procedure
    thanks in advance

    846773 wrote:
    My first query is regular base table and my second query is the my expected result with just two columns(i excluded all the columns from first query )
    second query is nothing but for each id what is my report expiredateI think I may have understood something your requirement but WTF, make an effort to be clear!!!
    Let's suppose:
    * for ID=1*
    Your query is starting on '06/14/2012 10:41:40' (which is thursday).
    It has to run 4 times and it runs only on Mon, Tue and Fri.
    Then it will run on 06/15/2012, 06/18/2012, 06/19/2012 and 06/22/2012 (4 times). Expire date = 06/22/2012. Got it!! :-)
    * for ID=2*
    Your query is starting on '06/15/2012 10:41:40' (which is friday).
    It has to run 1 time and it runs only on Mon, Tue and Fri.
    Then it will run on 06/15/2012 and it's finished (1 time). Expire date = 06/15/2012. Got it!! :-)
    * for ID=3*
    Your query is starting on '06/16/2012 10:41:40' (which is saturday).
    It has to run 2 times and it runs only on Mon, Tue and Fri.
    Then it will run on 06/18/2012 and 06/19/2012 and it's finished (2 times). Expire date = 06/19/2012. Got it!! :-)
    Please confirm the logic.
    Regards.
    Al
    Edited by: Alberto Faenza on Jun 14, 2012 5:35 PM
    Understood the logic
    Edited by: Alberto Faenza on Jun 14, 2012 5:36 PM

  • SELECT QUERY USING STORED PROCEDURE

    Hi,
    I am using stored procedure in package, i need to execute select statement using
    stored procedure.
    regards,
    p.kumaran

    ? not framed properly i think so if u dnt mind plz check it out once
    if u wnt to invoke a proc from package 2 ways r there
    1) execute pac_name.proc_name[(arg_list)];
    2) pl/sql
    [declare]
    begin
    pac_name.proc_name[(arg_list)];
    end;
    /

  • Call the Function against a select query in 500 procedures...

    Hello Gurus,
    I have a scenario, where i had made one function(UDF Function) to calculate something and in every procedure i call that function and calculate my requirement.
    Yesterday, i made a select query using reg exp for the same calculation..
    So my question is, what should be the proper approach..
    I need to implement this on 500 procedures...
    And the UDF function is
    CREATE OR REPLACE FUNCTION "UDF_TEXTSPLIT" (
    p_list VARCHAR2,
    p_del VARCHAR2 := ','
    ) RETURN split_tbl pipelined
    IS
    l_idx PLS_INTEGER;
    l_list VARCHAR2(7999) ;
    l_value VARCHAR2(7999);
    BEGIN
    l_list := p_list;
    LOOP
    l_idx := INSTR(l_list,p_del);
    IF l_idx > 0 THEN
    pipe ROW(SUBSTR(l_list,1,l_idx-1));
    l_list := SUBSTR(l_list,l_idx+LENGTH(p_del));
    ELSE
    pipe ROW(l_list);
    EXIT;
    END IF;
    END LOOP;
    RETURN;
    END Udf_Textsplit;
    I have made this query:
    SELECT a.b,z. b1 FROM
    (SELECT ROWNUM d,REGEXP_SUBSTR(str1, '[^> ]+', 1, LEVEL) b
    FROM (SELECT 'xxx>zzz>gg' str1 FROM dual)
    CONNECT BY REGEXP_SUBSTR(str1, '[^> ]+', 1, LEVEL) IS NOT NULL)a,
    (SELECT ROWNUM d,REGEXP_SUBSTR(str1, '[^> ]+', 1, LEVEL) b1
    FROM (SELECT '100>500>20' str1 FROM dual)
    CONNECT BY REGEXP_SUBSTR(str1, '[^> ]+', 1, LEVEL) IS NOT NULL)z
    WHERE a.d=z.d
    Do i use the same select query in all 500 procedures or call the (UDF Function) in every procedure..
    So which will be faster...
    Your approach would be very much appreciated...
    Thanks,
    Haraprasad...

    Hmm, do I edit 500 procedures to replace a function call with a SQL statement, or edit 1 function to use a sql statement instead of the current algorithm?
    This is why we use code modules that do one thing and do it well. As long as the new version of the function takes the same arguments and returns the same results as the old, then the callers will never know that the way the function works has changed.
    Whenther you put the select statement in 500 procedures, or 1 function, there will still be a context switch every time you use it. The tiny additional overhead of calling a function before the context switch would be unnoticeable.
    John

  • Use of a stored procedure in a select statement submitted to cx_oracle

    Hi,
    I am developping under python and I'm using the cx_oracle interface.
    I've written a stored procedure that I've tested directly under sqlplus session : it's ok. I've also tested this stored procedure from python by using callproc routine : its also ok.
    Now I need to use this procedure within a select statement that I submit to the execute statement of cx_oracle as :
    s = "select a.airport_name,gmlpos.ExpLatLong(a.point_name) from airport"
    self.db = oracledb('ops/opeope00@ACE2008B')
    dbmsg = self.db.execute(s)
    IF (dbmsg == "") :
    An error occurs :
    Message = request = select a.AIRPORT_NAME, gmlpos.ExpLatLong(a.point_name) from airport, errmsg = ORA-00904: "GMLPOS"."EXPLATLONG": invalid identifier
    Noting that the execution of any other select (without stored procedure) order from python works fine.
    Is anybody has a solution or workaround ?
    thanks a lot for your help

    The result gives what is expected :
    AIRP
    GMLPOS.EXPLATLONG(A.POINT_NAME)
    LFLL
    -45.71666666666667 -5.08333333333333
    As I said the stored procedure works fine.
    Thanks for your expertise
    PS : why change the login password until nobody says which machine or database is concerned ?

  • Executing a stored procedure containing multiple Select statements

    Post Author: Beverly
    CA Forum: General
    I am using Crystal  10.0 against a MS SQL 2000 server.
    I am trying to create a report based on a stored procedure that contains multiple select statements.  The sp requires a single parameter (Claim number) and contains 17 Select statements that produce results.
    I am able to use the Add command and execute the sp with the parameter, but I am only getting the results of the first select statement in the sp back in my data set.  Is there a way to have the data from each Select statement returned to my report?
    I have used Crystal for a while, but pretty much for straight-forward reporting.  I am familiar with the basics of SQL.
    I would appreciate any help anyone can offer.
    Thanks.

    Post Author: BISoftware
    CA Forum: General
    I believe Crystal Reports can only handle one recordset at a time, which means it can only handle a single select statement.  The only way I can see around this would be to break up your stored procedure into multiple stored procedures, so that each only contains a single select statement.  Then, use subreports to report on each individual sp. Hope this helps. - Davewww.BusinessSoftwareResource.com

  • JDBC Sender MSSQL Stored Procedure - Multiple Select Statements

    Hello all,
    I will proceed to tell you my problem, for which solution I request your kind advice:
    Im working in a project for a retailer, which consists in sending the information from erp and sql server to pos thru XI interfaces.
    One of the interfaces is about sending items from sql server to a file so the pos can load it into the system. For doing so I have devloped an stored procedure which function is to return several select statements as many stores the retailer might have, so they can have a different file per store along with its corresponding items in it. 
    The thing is that XI just gets the first select statement and creates the corresponding file, but it seems to ignore the remaining responses as I'm neither getting any file nor an error afterwards.
    So, my question is: is XI capable of handling multiple select responses from an Stored Procedure in graphical mapping??? Or am I just wasting my time trying?
    Thanks in advice for your help.
    Regards.

    Hello Ramkumar,
    After 5 days trying, I finally made it work out applying your advice. Below the short explanation of what I did:
    My Source structure is: Main Node->Row->Records (Material Number, StoreNum, Price, Status)
    My Target structure is: Main Node->File Node->Record Node->Records ( Material Number, Price, Status)
    The key was to make all the occurrences happen against StoreNum node. So, based on what you adviced these two where the key mappings:
    1) The Mapping that will create a new file for each different store that comes in the query (In my case, query was already sort by store using an sql "order by" function, if not you can also use xi node function "sort" as Ramkumar suggested)
    StoreNum->RemoveContext->SplitbyValue (Value Changed)->Collapse Contexts->File Node
    2) The Mapping that will create each record in its corresponding store file:
    StoreNum->RemoveContext->SplitbyValue (Value Changed)->Record Node
    And Voilá !!! It worked.
    Thanks very much Ramkumar.
    Regards.

  • Using procedure in SELECT statement

    I have a select statement that currently uses 4 functions to receive necessary values. All the functions are recursive and returns values from the same row.
    What I would like to do is replace these for function calls with 1 procedure. Does anybody know if it possible to use a procedure in this way inside a select statement?
    If so, do you have the syntax for doing this?
    E.g
    SELECT
    Mdbrd_Pkg.calculate_fixed_charge_fn(in_rc_id, ap.CONFIGSET_ID) AS FIXED_CHARGE,
    Mdbrd_Pkg.calculate_charge_rate_fn(in_rc_id, ap.CONFIGSET_ID) AS CHARGE_RATE,
    Mdbrd_Pkg.tax_liable_fn(in_rc_id, ap.CONFIGSET_ID) AS TAX_LIABLE,
    Mdbrd_Pkg.charge_unit_fn( in_rc_id, ap.CONFIGSET_ID) AS CHARGEUNIT_ID
    FROM .....

    This cannot be done. The part of the function used in the SELECT statement is the return value: procedures don't have return values (that's what makes tham procedures and not functions).
    Obviously I don't know what your code does, but you should consider putting them into a single function that returns a TYPE with four attributes and then using the TABLE() function to cast them into something you could reference in the FROM clause of a correlated sub-query. Sounds a bit messy though.
    Do these functions actually select data? Where does the recursion fit in?
    Cheers, APC

  • Can we call a procedure in select statement?

    Can we call a procedure in select statement?

    Hi,
    Raghu_appsdba wrote:
    Can we call a procedure in select statement?No. You can call functions, but not procedures.
    If the procedure does not change the database state (for example, it doesn't update any tables), then you can wrap it in a function, or re-write it as a function.
    Here's an example of wrapping.
    CREATE OR REPLACE FUNCTION fun_x (in_txt IN VARCHAR2)
    RETURN  VARCHAR2
    IS
    BEGIN
            proc_y (in_txt);
            RETURN  in_txt
    END     fun_x;

  • Can we call a stored procedure in a select statement

    Hi All
    I want to call a stored procedure inside a select statement is this possible.
    Regards
    Sravz

    You can create a pipelined function which gathers the data from your stored procedure and then use that in a select statement or directly write your script in any function or pipelined function. ;)
    There is no way you can call any stored procedure in a SELECT statement directly - i guess.
    Regards.
    Satyaki De.

Maybe you are looking for

  • UD ICCO SPCO STUP- unable to clear the stock in Quality View.

    Hi!                 In a QM -Module for a particular material status is showing as "UD ICCO SPCO STUP" in QA32. Usage Decision is done for this particular item. But it is showing the stock in MMBE Tcode. Its unable to clear in QA32. I tried QA12 and

  • Asset Sub number skipped

    Dear Experts, I have an Asset 1250000 in which 1 to 131 sub numbers have been created but i observed sub numbers from 61 to 65 do not exist so i doubt them to have been deleted. 1. How can track if these sub numbers have been deleted? 2. Is there any

  • How to load document from url to blob

    How I can load html file from web to clob column in database table?

  • Error code 1962: on Lenovo ideacentre b-series--​-NEED HELP---

    I recently purchased, (when I mean recently it  is 1 1/2 month ago) and I get frustrated b/c of this error (1962). I just don't understand why brand new comp. is doing this.  When I purchased the desktop it was pre-loaded with OS Windows7 and I was t

  • Export asynchron

    Hey, folgendes Problem: Wenn ich meine Sequenz exportiere sind manche clips asynchron - in der Vorschau werden sie synchron angezeigt. Sequenz: Dslr Preset - 48000 HZ - Full HD 1920x1080 25fps - quadratische pixel - progressiv - H.264 GPU = K5000 - g