Evaluation of expressions in cursor declaration.

Hi, all,
If I have in an on-demand application process:
DECLARE
CURSOR c1 IS SELECT DUMMY FROM DUAL WHERE 'FOO' = V('MY_ITEM')
BEGIN
FOR c IN c1
LOOP
-- do stuff with c
END LOOP;
END
when is V('MY_ITEM') evaluated?

V('MY_ITEM') will be evaluated when the cursor is opened on (every) execution of the on-demand process.
Toon

Similar Messages

  • Cursor Declaration

    I am trying to declare a cursor in a stored procedure using the following sql:
         CURSOR conversionCursor is select customer_number, company_id , buyer_id
         from hpsiuser.conversion_master natural join
         (select distinct mfg_code, customer_number
                                                 from hpsiuser.vendor_info, invoice_h
                                                 where vendor_id = vendorID);
    I get the following errors:
    Line # = 6 Column # = 29 Error Text = PL/SQL: SQL Statement ignored
    Line # = 6 Column # = 9 Error Text = PLS-00341: declaration of cursor 'CONVERSIONCURSOR' is incomplete or malformed
    Line # = 7 Column # = 43 Error Text = PL/SQL: ORA-06552: PL/SQL: Compilation unit analysis terminated ORA-06553: PLS-320: the declaration of the type of this expression is incomplete or malformed
    My assumption is that it is having a problem with the join yet it works as a stand alone select statement.
    Any insight would be appreciated.
    Jon King

    CURSOR Expressions
    A CURSOR expression returns a nested cursor. This form of expression is equivalent to the PL/SQL REF CURSOR and can be passed as a REF CURSOR argument to a function.
    cursor_expression::=
    Text description of cursor_expression
    A nested cursor is implicitly opened when the cursor expression is evaluated. For example, if the cursor expression appears in a SELECT list, a nested cursor will be opened for each row fetched by the query. The nested cursor is closed only when:
    The nested cursor is explicitly closed by the user
    The parent cursor is reexecuted
    The parent cursor is closed
    The parent cursor is cancelled
    An error arises during fetch on one of its parent cursors (it is closed as part of the clean-up)
    Restrictions on CURSOR Expressions
    If the enclosing statement is not a SELECT statement, nested cursors can appear only as REF CURSOR arguments of a procedure.
    If the enclosing statement is a SELECT statement, nested cursors can also appear in the outermost SELECT list of the query specification, or in the outermost SELECT list of another nested cursor.
    Nested cursors cannot appear in views.
    You cannot perform BIND and EXECUTE operations on nested cursors.
    http://download-west.oracle.com/docs/cd/B10501_01/server.920/a96540/expressions6a.htm#1035109
    Joel P�rez

  • Performance: Cursor declaration versus explicit query in BEGIN/END block

    Hi guys!
    Anyone knows if declare an explicit cursor inside a pl/sql block is faster than using a cursor declaration, and how fast it its?
    Which block runs faster? And how fast? ( once, twice, once and a half ? )
    Block1:
    DECLARE
    CURSOR cur_test (p1 NUMBER) IS
    SELECT field1, field2 FROM table WHERE field0 = p1;
    vf1 VARCHAR2(1)
    vf2 NUMBER;
    n NUMBER := 0;
    BEGIN
    OPEN cur_test ( n );
    FETCH cur_test INTO vf1, vf2;
    CLOSE cur_test;
    END;
    Block2:
    DECLARE
    vf1 VARCHAR2(1)
    vf2 NUMBER;
    n NUMBER := 0;
    BEGIN
    BEGIN
    SELECT field1, field2
    INTO vf1, vf2
    FROM table WHERE field0 = n;
    EXCEPTION
    WHEN others THEN
    null;
    END;
    END;
    I have LOOP in a cursor and may open/fetch/closes in this loop. I´m wondering how fast would it be if I change the open/fetch/closes to explicit query blocks...
    Thanks!
    Murilo

    If you expect your qurey to return a single row, you would generally want to use a SELECT ... INTO. You'd only want to use a cursor if you expect to return multiple rows of data.
    If you are doing this in a loop, I would strongly suspect that you should be letting Oracle join the tables in SQL rather than doing your own pseudo-join logic in PL/SQL. Letting SQL do the work of joining tables is going to generally be a sustantial performance difference. The difference between the two blocks you posted will be marginal at best.
    Justin
    Distributed Database Consulting, Inc.
    http://www.ddbcinc.com/askDDBC

  • ORAMED-01101 :[Filter Expression Error]Error evaluating filter expression.

    I am a newbie with oracle soa suite 11g. I am trying to use file adapter to upload the csv file contents to database.
    My csv file looks like:
    employeeid,employeename,designation,managerempid
    1121,abc,mts,211
    1122,def,mts,232
    1123,xyz,abc,133
    The generated xml file during the xsd test is
    <?xml version = '1.0' encoding = 'UTF-8'?>
    <Root-Element xmlns="http://TargetNamespace.com/EmpAdaptor">
    <emp>
    <employeeid>1121</employeeid>
    <employeename>suneetha</employeename>
    <designation>mts</designation>
    <managerempid>211</managerempid>
    </emp>
    <emp>
    <employeeid>1122</employeeid>
    <employeename>challa</employeename>
    <designation>mts</designation>
    <managerempid>232</managerempid>
    </emp>
    <emp>
    <employeeid>1123</employeeid>
    <employeename>xyz</employeename>
    <designation>abc</designation>
    <managerempid>133</managerempid>
    </emp>
    </Root-Element>
    and in the mediator, I have the filter expression as shown:
    $in.body/ns1:EmpDetails/ns1:Emp
    the d/b table i created is
    CREATE TABLE empdtls (EMPID NUMBER(5) PRIMARY KEY,ENAME VARCHAR2(15) NOT NULL,DESIG VARCHAR2(10),MGREMPID NUMBER(5));
    When I deployed it, the application throws the below fault
    Non Recoverable System Fault :
    ORAMED-01101:[Filter Expression Error]Error evaluating filter expression.Possible Fix:Please make sure filter expression is valid, otherwise contact oracle for support. Cause:ORAMED-01102:[Filter Expression Metadata Error]Error evaluating filter expression, "$in.body/ns1:EmpDetails/ns1:Emp"Possible Fix:Please make sure filter expression metadata is valid, otherwise contact oracle for support.
    I have been trying to fix this error for almost three days..
    Somebody please help me..

    Sorry the generated xml during test is
    <?xml version = '1.0' encoding = 'UTF-8'?>
    <EmpDetails xmlns="http://TargetNamespace.com/ServiceName">
    <Emp>
    <employeeid>1121</employeeid>
    <employeename>suneetha</employeename>
    <designation>mts</designation>
    <managerempid>211</managerempid>
    </Emp>
    <Emp>
    <employeeid>1122</employeeid>
    <employeename>challa</employeename>
    <designation>mts</designation>
    <managerempid>232</managerempid>
    </Emp>
    <Emp>
    <employeeid>1123</employeeid>
    <employeename>xyz</employeename>
    <designation>abc</designation>
    <managerempid>133</managerempid>
    </Emp>
    </EmpDetails>

  • OSB insert in not evaluating the expression

    I am using insert in the proxy service of OSB and and my expression is like this:
    Expression : <fcs:appId>$body/*/appId/node()</fcs:appId>
    My problem is that it's not evaluating the expression. It's inserting this as text ($body/*/appId/node()).
    Any idea, why?

    I assume you want to get the value of the tag appid, then the correct expression is <fcs:appId>{$body/*/appId/text()}</fcs:appId>
    In case there is namespace defined with your xml tag then you should be using it as <fcs:appId>{$body/*/*:appId/text()}</fcs:appId>
    Thanks,
    Patrick
    Edited by: Patrick Taylor on May 25, 2011 8:15 PM

  • How to pass dynamically table name in my cursor declaration

    Hi:
    I am new. could you please let me know how to pass a table name dynamically in my cursor declaration? for instance I am declaring the following cursor in my pl/sql procedure:
    CURSOR crs_validate IS
    select * FROM <ACT_JUN_2006_LOB>;
    this ACT_JUN_2006_LOB table name, I should able to pass it when I open the cursor ... any help appreciated. thanks.
    srini

    Thanks all for the response. REFCURSOR does work: here is an example ... which I found on-line
    procedure emp_test(
    month varchar2,
    year varchar2)
    is
    type cur_typ is ref cursor;
    c cur_typ;
    query_str varchar2(200);
    emp_number number := 7900;
    salary number;
    name varchar2(30);
    Begin
    query_str := 'Select empno, ename, sal from emp_' || month ||'_'||year
    || ' where empno = :id';
    open c for query_str using emp_number;
    loop
    fetch c into emp_number, name, salary;
    exit when c%notfound;
    dbms_output.put_line(emp_number);
    end loop;
    close c;
    end;

  • Binding assignment is not available:Error in the evaluation of expression

    Hi All,
    I have created Workflow to send an Email using Requested Start date concept of a Task.This is for sending a E-mail to the customer when contract end date-60 Days.
    I have done all Bindings and I am getting The date and time from BOR which I am using to triger an Event.
    I am getting these type of Errors:
    Source (expression '&BUS2000137.TIME&') of binding assignment is not available
    Source (expression '&BUS2000137.DATE&') of binding assignment is not available
    Error in the evaluation of expression '<???>&BUS2000137.DATE&' for item '1'
    Unable to determine the value of component ''
    Error in the evaluation of expression '<???>&BUS2000137.TIME&' for item '1'
    Unable to determine the value of component ''
    Looking for Inputs.
    Regard's,
    Lokesh

    Hi Adrash/Rick,
    Object type  ZBS2000137
    Attributes
    ZBS2000137.Time    Time to send mail --> Is nothing but OBJECT-TIME = SY-UZEIT
    ZBS2000137.Date    60 days before contract end date  --> Is nothing but  OBJECT-DATE =  LS_APPOINTMENT-DATE_FROM - 60.
    Methods
    ZBS2000137.Method1       Sending Mail
    Events
    ZBS2000137.Released      Contract Line Item Released
    ie I want to excute the task with same DATE and TIME, the same I have mentioned in "
    Requested Strat Tab with Expression as below
    Refer.date/time EXP Expression
    Date &BUS2000137.DATE&     60 days before contract end date
    Time &BUS2000137.TIME&      Time to send mail
    Note: If I am testing the Workflow from T-code: SWUS it is working fine.
    Regard's,
    Lokesh.

  • SQL Expression Field - Combine Declared Variable With Case Statement

    Hello All, I have been using Crystal & Business Objects for a few months now and have figured out quite a bit on my own. This is the first real time I have struggled with something and while I could do this as a Formula Field I would like to know how to do this as a SQL Expression. Basically I want to create a SQL Expression that uses a CASE statement but I wanted to make the code a little more efficient and employ a variable to hold a string and then use the variable in the CASE statement. The expression editor accepts the CASE statement OK but I don't know how to declare the variable. Please assist with the syntax?
    This is what I have:
    CASE
       WHEN u201CDatabaseu201D.u201DFieldu201D = u2018Hu2019 THEN u2018Hedgeu2019
       WHEN u201CDatabaseu201D.u201DFieldu201D = u2018Pu2019 THEN u2018PVIu2019
       ELSE u2018Noneu2019
    END
    This is what I want:
    DECLARE strVar AS VARCHAR(25)
    strVar =  u201CDatabaseu201D.u201DFieldu201D
    CASE
       WHEN strVar = u2018Hu2019 THEN u2018Hedgeu2019
       WHEN strVar = u2018Pu2019 THEN u2018PVIu2019
       ELSE u2018Noneu2019
    END

    Hi Todd,
    Please use the following for loop; your problem will be solved.
    Local StringVar str := "";
    Local NumberVar strLen := Length ({Database.Field});
    Local NumberVar i;
    For i := 1 To strLen Do
           if {Database.Field} <i> = "H" then str := "Hedge"
            else if {Database.Field} <i> = "P" then str := "PVI"
            else str := "None"; exit for
    str
    Let me know once done!
    Thank you,
    Ashok

  • Package Procedure cursor declaration

    Hi am facing this issues , I am too close the problem to figure. Pl help
    procedure addRox(p_reg_type_id in  number, p_offender_id in  number,p_sentence_end_date in  date,
                                p_registration_date in  date,p_end_registration_date in  date,
                                p_aggravated in  varchar2,p_habitual in  varchar2, p_comments  in varchar2, p_status  in varchar2 DEFAULT null  , p_OFFENSE_CODE in number) is
      cursor tierNum is
        select max(c.tier) from sor_offense o, sor_offense_code c
        where o.offender_id = p_offender_id
        and o.offense_code = c.CODE_ID
        and o.state = 30658
        and upper(o.status) = 'ACTIVE';
      tier number;
      vEndRegDate registration_offender_xref.END_REGISTRATION_DATE%type default null;
    begin
         open tierNum;
         Fetch tierNum into tier;
          if tierNum%NotFound then
            tier := Null;
          end if;
        Close tierNum;
        if tier is not null then
          if(p_sentence_end_date is null) then -- sentenceEndDate is null
              if tier = 1 then
              vEndRegDate := add_months(p_registration_date - 1,180);
              end if;
            if tier = 2 then
              vEndRegDate := add_months(p_registration_date - 1,300);
            end if;
            if tier = 3 then
                vEndRegDate := Null;
            end if;
          else -- sentence_end_date is not null
            if tier = 1 then
              vEndRegDate := add_months(p_sentence_end_date - 1,180);
            end if;
            if tier = 2 then
              vEndRegDate := add_months(p_sentence_end_date - 1,300);
            end if;
            if tier = 3 then
              vEndRegDate := Null;
            end if;
          end if;
        end if;
              insert into registration_offender_xref (reg_type_id, offender_id, status,sentence_end_date,
                                registration_date,end_registration_date,aggravated,habitual,status_date, comments)
                         values (p_reg_type_id, p_offender_id, 'Active',p_sentence_end_date,
                                p_registration_date,vEndRegDate,p_aggravated,p_habitual,sysdate, p_comments);
            -- commit;
    exception
      when others then
            DBMS_OUTPUT.PUT_LINE('ERR in  '||sqlerrm);
    end addRox;\
    error:Error(4,12): PLS-00323: subprogram or cursor 'ADD_ABC' is declared in a package specification and must be defined in the package body

    >
    Hi am facing this issues , I am too close the problem to figure. Pl help
    error:Error(4,12): PLS-00323: subprogram or cursor 'ADD_ABC' is declared in a package specification and must be defined in the package body
    >
    You aren't getting that exception from the code you posted. There is nothing with 'ABC' in any of that code.
    If you want help you need to post the code that you need help with.

  • BUG?: unexpected token in connection pane for cursor declaration

    If I declare a cursor with an order clause in the declaration part of a procedure in a package I will get the unexpected token. The code compiles without errors.
    SQL Developer 15.57.
    Windows XP SP2
    Oracle 10g
    example:
    declare procedure test( param in integer ) as
    cursor cur( nVal in integer ) is
    select * from tab where col1 = nVal
    order by col2;
    begin
    NULL;
    end test;
    If I comment out the order by line and proper end the line before all is OK in connection pane.

    There are a few issues logged for these unexpected tokens. We will be reviewing this section for 1.1.
    Regards
    Sue Harper

  • Evaluating an expression in a string

    I need to evaluate an expression in a string, and return 0 or 1 for true or false.
    Here is a version I tried:
    06:25:26  > CREATE OR REPLACE FUNCTION MJT_EVALUATE_EXPR (in_expr_to_evaluate VARCHAR2)
    06:26:00   2     RETURN NUMBER
    06:26:00   3  IS
    06:26:00   4     l_dual_record   DUAL%ROWTYPE;
    06:26:00   5     csr_dual        SYS_REFCURSOR;
    06:26:00   6     l_this_result   NUMBER;
    06:26:00   7  BEGIN
    06:26:00   8     OPEN csr_dual FOR 'SELECT * FROM DUAL WHERE ' || in_expr_to_evaluate;
    06:26:00   9 
    06:26:00  10     FETCH csr_dual INTO l_dual_record;
    06:26:00  11 
    06:26:00  12     IF csr_dual%FOUND
    06:26:00  13     THEN
    06:26:00  14        l_this_result := 1;
    06:26:00  15     ELSE
    06:26:00  16        l_this_result := 0;
    06:26:00  17     END IF;
    06:26:00  18 
    06:26:00  19     CLOSE csr_dual;
    06:26:00  20 
    06:26:00  21     RETURN l_this_result;
    06:26:00  22  END;
    06:26:00  23  /
    Function created.
    06:26:11> select mjt_evaluate_expr('((1=1) OR (1=0))') from dual;
    MJT_EVALUATE_EXPR('((1=1)OR(1=0))')
                                      1
    1 row selected.
    Elapsed: 00:00:00.02
    06:26:22 > Due to the high number of executions, I would like to avoid dynamic SQL or cursor operations such as this. Does anyone have a suggestion for another approach?
    The expressions can get more complex than this, possibly with dozens of terms.

    Does anyone have a suggestion for another approach?I don't think you'll gain any performance but for the records:
    SQL> select * from v$version where rownum = 1
    BANNER                                                                         
    Oracle Database 11g Enterprise Edition Release 11.2.0.2.0 - Production         
    1 row selected.
    SQL> var bool varchar2(40)
    SQL> exec :bool := '1=1 and 1=0'
    PL/SQL procedure successfully completed.
    SQL> select decode(column_value, 'true', 1, 0) bool from xmltable (:bool)
          BOOL
             0
    1 row selected.

  • Evaluating xpath expressions

    Hi all,
    I have an xml document as
    <?xml version="1.0" encoding="UTF-8"?>
    <purchaseReport xmlns="http://www.example.com/Report" >
    <regions>
    <zip code="95819">
    <part number="872-AA" quantity="1"/>
    <part number="926-AA" quantity="1"/>
    <part number="833-AA" quantity="1"/>
    <part number="455-BX" quantity="1"/>
    </zip>
    <zip code="63143">
    <part number="455-BX" quantity="4"/>
    </zip>
    </regions>
    <parts>
    <part number="872-AA">Lawnmower</part>
    </parts>
    </purchaseReport>
    when I evaluate the for an expression xpath_object.evaluate(f,"/purchaseReport/parts/part/@number",NODE)
    I am getting null as return value.
    I have set the namespace context for xpath_object as
    xpath_object.setNameSpaceContext(new name_space_context());
    class name_space_context implements NamespaceContext{
    public String getNamespaceURI(String prefix){
    //System.out.println("A call was made here");
    if(prefix.equals(XMLConstants.DEFAULT_NS_PREFIX)){
    System.out.println("A call was made here");
    return "http://www.example.com/Report";
    else if(prefix.equals(XMLConstants.XML_NS_PREFIX)) {
    System.out.println("A call was made here");
    return XMLConstants.XML_NS_URI;
    else if (prefix.equals(XMLConstants.XMLNS_ATTRIBUTE)){
    System.out.println("A call was made here");
    return XMLConstants.XMLNS_ATTRIBUTE_NS_URI;
    else if(prefix.equals("def")){
    System.out.println("A call was made here def");
    return "http://www.example.com/Report";
    else if(prefix.equals("si")){
    System.out.println("A call was made here si");
    return "http://www.example.com/Report/si";
    else if(prefix.equals("")){
    System.out.println("A call was made here empty");
    return "http://www.example.com/Report";
    else {
    return "There is no matching prefix with the given input" + prefix;
    please explain why me I am getting null when I evalute the expression.

    Hi tsuji,
    I am trying to update the element value in my xml , by getting input the xml and the xpath.
    My code is as below.
    InputSource is;
    is = new InputSource(new StringReader(input.toString()));
    Node node = (Node)xPath.evaluate(XPATH, is, XPathConstants.NODE);
    node.setTextContent(newValue);
    I succeeded in evaluating the namespace prefix also.
    After updating the value of the node, I tried to display the updated xml. But i couldnt succeed.
    i tried,
    Making 'Document' out of the 'is' - but failed throws NullPointerException in Document doc=dBuilder.parser(is)
    Please help me in displaying the updated XMLdocument.
    I have a doubt here, in this case like mere changing the value of the node, will it change the original InputSource 'is'
    But , when i used
    NodeIterator nl = XPathAPI.selectNodeIterator(doc, xpath); //here doc is the Document object, xpath is String object
    n=nl.nextNode();
    n.setTextContent(newValue);
    Then when i tried displaying the doc again, it gave me the updated document.
    I couldnt proceed with NodeIterator , i couldnt apply the setNamespaceContext.
    Kindly help me in this regard.
    Thanks,
    Sabarisri. N

  • Evaluating an expression stored as varchar

    Hi,
    I've declared a varchar variable and the data stored in that variable is an expression.
    I need to evaluate the expression.
    Is there any option to do so.
    For example
    v_s_expression:='10+5';
    i need to evaluate and get the value into another variable.
    i should get the result 15 in the variable v_n_result.
    any methods?
    Thanks in advance
    Prasanth

    first of all why?....
    execute immediate 'select '||v_s_expression||' from dual' into res;like in
    SQL> declare
      2     v_s_expression varchar2(10);
      3     res number;
      4  begin
      5     v_s_expression:='10+5';
      6     execute immediate 'select '||v_s_expression||' from dual' into res;
      7     dbms_output.put_line(res);
      8  end;
      9  /
    15
    PL/SQL procedure successfully completed.

  • Cursor declaration in packages.

    Hi,
    Our company is decided to use stored procedures for all database access from Java Servlets/JSP. We have to use lot of ref cursors. In a package there will be lots of procedures using cursor. So is it enough to declare only one cursor in the package head of a package and use it in all packages and procedures. Is there any sharing problem in doing it.
    Anto Paul.

    No, The purpose when you declare a cursosr in a package is that the resource can be shared for a lot of sessions maintain each sessions its private values. When a package is invoked the first time is loaded into the SGA and it makes faster the accesses to it.
    Joel P�rez

  • Xmltable in cursor declaration - error!

    Hi, I am using the following SQL:
    select l.description
    from XMLTABLE(XMLNAMESPACES('PostcodeAnywhere2' as "e"), '/e:InterimResults/e:Results/e:InterimResult' PASSING
    XMLTYPE.createxml(ws_postcode_aw.getByPostcodeXML('WR2 6NJ','1', 'XML'))
    COLUMNS description varchar2(400) PATH '//e:Description'
    ) l
    which returns data OK.
    However, when I incorporate it into a cursor, I get a "no more data to read from socket" error. When I replace the cursor with a simple "SELECT 'dasda' description FROM dual" the code complies OK. Can anyone assist with this? I have no idea what could be causing this. Code is included below:
    CREATE OR REPLACE
    PACKAGE BODY "GET_PC_DATA" AS
    PROCEDURE disp_pc_data IS
    v_str clob;
    v_post_code varchar2(10) := 'WR2 6NJ';
    v_fast_add_ret_xml xmltype;
    v_pc_lookup_ret_xml xmltype;
    TYPE c_get_addresses_t IS REF CURSOR;
    c_get_addresses c_get_addresses_t;
    TYPE r_get_addresses_t IS RECORD ( description varchar2(400));
    r_get_addresses r_get_addresses_t;
    FUNCTION getHouseNumber(p_desc IN varchar2) RETURN varchar2
    IS
    BEGIN
    return substr(p_desc,1,instr(p_desc,v_1_line_add));
    END;
    BEGIN
    OPEN c_get_addresses FOR
    SELECT l.description
    FROM XMLTABLE(XMLNAMESPACES('PostcodeAnywhere2' as "e"), '/e:InterimResults/e:Results/e:InterimResult' PASSING
    XMLTYPE.createxml(ws_postcode_aw.getByPostcodeXML('WR2 6NJ','1', 'XML'))
    COLUMNS description varchar2(400) PATH '//e:Description'
    ) l;
    LOOP
    FETCH c_get_addresses INTO r_get_addresses;
    EXIT WHEN c_get_addresses%NOTFOUND;
    v_str := v_str || getHouseNumber(r_get_addresses.description);
    END LOOP;
    CLOSE c_get_addresses;
    END;
    END;
    Message was edited by:
    steve_macleod

    V('MY_ITEM') will be evaluated when the cursor is opened on (every) execution of the on-demand process.
    Toon

Maybe you are looking for