How to handle empty  ref cursor

when my ref cursor is empty how do i prevent null pointer exception
Thanks

What are you doing now? Do something else.

Similar Messages

  • How to handle the ref cursor which is returning "no rows"

    I have written a function which is returning the REF CURSOR. But in one situation the REF CURSOR returns "no rows selected". To handle this situation an exception is raised "when no data found". But i dont know in this situation how should NULL cursor be returned through this function. Since I want to call this function in another procedure so something should be returned through this function by means of ref cursor. But since i am not able to handle this "no rows selected" situation i am not able move further.
    Thanks in advance........

    I agree.
    You would simply process the returned ref cursor irrespective of any rows actually returned in the cursor or not. You would be able to do at least one FETCH from the cursor (even if it does not actually contain any rows) and then determine the %NOTFOUND status to do the rest of the processing.
    SQL> variable cur refcursor
    SQL> exec open :cur for select * from scott.emp where rownum = 1 ;
    PL/SQL procedure successfully completed.
    SQL> print cur
         EMPNO ENAME      JOB              MGR HIREDATE           SAL       COMM     DEPTNO
          7369 SMITH      CLERK           7902 17-DEC-1980        800                    20
    1 row selected.
    SQL>
    SQL> exec open :cur for select * from scott.emp where 1 = 2 ;
    PL/SQL procedure successfully completed.
    SQL> print cur
    no rows selected
    SQL>
    SQL> SET SERVEROUTPUT ON
    SQL> DECLARE
      2      rec scott.emp%ROWTYPE;
      3      bol BOOLEAN;
      4      cur sys_refcursor;
      5  BEGIN
      6      OPEN cur FOR
      7          SELECT * FROM scott.emp WHERE 1 = 2; /* assume this is your function call returning a ref cursor */
      8      bol := FALSE;
      9      LOOP
    10          FETCH cur
    11              INTO rec;
    12          EXIT WHEN cur%NOTFOUND;
    13          --
    14          -- process the data here
    15          --
    16          bol := TRUE;
    17      END LOOP;
    18      CLOSE cur;
    19      IF (bol)
    20      THEN
    21          dbms_output.put_line('At least one row was found');
    22      ELSE
    23          dbms_output.put_line('No rows were selected');
    24      END IF;
    25  END;
    26  /
    No rows were selected
    PL/SQL procedure successfully completed.
    SQL>

  • How to handle empty file using sftp adapter

    Hi,
    Please explain me how to handle empty files in sftp adapter.
    Thanks,
    Enivass

    Hi Enivaas,
                        I don't have the seeburger sftp adapter at hand at the moment, but asfar as I remember, this does not specifically have an empty-file handling option like the standard ftp adapter.
    So to stop emtyp files from being written, guess would need to handle this at the mapping level. For example, check for target creation criteria in the header node in mapping. If the creation criteria is not met, you can throw an error in mapping.
    You may also incorporate this condition in your Receiver determination. In this case, if the condition is not satisfied, no receiver is determined in PI.
    Regards

  • How to Handle Empty Files

    Hi Experts,
    I am doing File to File Scenario.
    If my Sender systems file is Empty , that means there is no Records in the File .
    How to Handle Empty Files ??????????
    I want to know For both Sender and As wel as Receiver Adapters
    Please Let me know..
    Regards
    Khanna

    See if u are having a sender file adapter and the file is empty u can tell the if it has to 'Process the empty file' or 'Skip the empty file processing'.
    Similarly if you have a message to going to your Receiver file adapter and the message is empty then you can decide still if you want to create a 'File with empty records' or skip creating the same.
    Regards,

  • How to return a ref cursor from this dbms_sql?

    Hi,
    Can anyone show me how to return a ref cursor from this dbms_sql based procedure? I see 11g has a dbms_sql.to_refcursor(cursor_handle). How can this be done is 10g?
    Thx.
    CREATE OR REPLACE PROCEDURE Sample_Get_t
    p_sample_id sample.sample_id%TYPE,
    p_contract_id sample.contr_id%TYPE
    IS
    cursor_handle INT;
    sql_stmnt varchar2(500);
    rows_processed NUMBER;
    BEGIN
    sql_stmnt :=
    'SELECT
    sample_id,
    contr_id,
    rcpt_id
    FROM
    sample s
    WHERE
    s.contr_id = :1
    and s.sample_id = :2
    ORDER BY
    sample_id';
    cursor_handle := dbms_sql.open_cursor;
    dbms_sql.parse(cursor_handle, sql_stmnt, dbms_sql.native);
    dbms_sql.bind_variable(cursor_handle, ':1', p_contract_id);
    dbms_sql.bind_variable(cursor_handle, ':2', p_sample_id);
    rows_processed := dbms_sql.execute(cursor_handle);
    dbms_sql.close_cursor(cursor_handle);
    END Sample_Get_t;

    In 10 this cannot be done with dbms_sql (to my knowledge). There are a couple of other options.
    1) open the ref cursor for the dynamic statement using bind variables (or SYS_CONTEXT variables, which i prefer since they are much easier to deal with when you are dynamically adding predicates).
    declare
       wRefCursor  SYS_REFCURSOR;
    begin
       open wRefCursor for 'select * from all_objects where owner = :Logged_in_user' using user;
    end;
    /or using the context (the context will bind for you)
    declare
       wRefCursor  SYS_REFCURSOR;
    begin
       open wRefCursor for 'select * from all_objects where owner = SYS_CONTEXT(''CONTEXT_NAME'', ''VARIABLE_NAME'') ';
    end;
    /Be aware that contexts ALWAYS return varchar values, so if you are comparing to a number you should wrap it in TO_NUMBER, a date, TO_DATE and so on....
    2) change the DBMS_SQL to do an insert into a global temporary table and return the ref cursor which select's * from GTT;
    3) upgrade to Oracle 11 :)

  • How to handle empty Dats field received from SAP RFC response

    Hi All,
    I am invoking a SAP RFC which gives me a Dats field in response.
    A valid dats fields is successfully received by my pipelines.
    But when an empty Dats field is received, My pipeline fails and i get error.
    How to handle the empty Dats field from SAP

    Hi Anant,
    This is because the legacy SAP adapter accepted RFC messages with date field empty. In the new version, the same call results in an error. WCF-SAP adapter doesn't allow blank XML nodes.
    You need to use the below custom pipeline component as a workaround.
    Refer:
    Pipeline component for enabling legacy behavior in WCF-SAP adapter.
    Rachit
    Please mark as answer or vote as helpful if my reply does

  • How to descrbe a ref cursor from a PL/SQL prog?

    Hi,
    here is a sample of the my problem
    let suppose a table country :
    create table country(country_code VARCHAR2(3), country_name VARCHAR2(50));
    then a package containing different procedures among them, this one :
    PL/SQL prog
    create or replace package country_pkg as
    type rec1 is ref cursor return country%rowtype;
    Procedure get_all_countries(rec in out rec1);
    blablabla ...
    END country_pkg;
    in the package body, i have the following code :
    create or replace package body country_pkg as
    procedure get_all_countries(rec IN OUT rec1) is
    begin
    if not rec%open then
    open rec for select * from country order by country_name;
    end if;
    exception
    when NO_DATA_FOUND then
    close rec;
    end get_all_countries;
    blablabla....
    end;
    Then in the C program
    (*proc)->request->command = "begin get_all_countries(:rec); end;"
    checkerr(&connect, \
         OCIStmtPrepare(connect->stmthp,\
         connect->errhp,\
         (*proc)->request->command,\
         strlen((*proc)->request->command),\
         OCI_NTV_SYNTAX, OCI_DEFAULT));
    checkerr(&connect, \
         OCIHandleAlloc((dvoid*)(connect->envhp),\
         (dvoid**) &((*proc)->stmthp), OCI_HTYPE_STMT,
    (size_t) 0,\
         (dvoid**) 0));
    bndhp = (OCIBind**) g_malloc0((*proc)->argnum*sizeof(OCIBind*));
    for(i = 0; i < (*proc)->argnum; i++)
    switch ((*proc)->desc->type)
    case 102:
    checkerr(&connect,
    OCIBindByPos(connect->stmthp, &bndhp[j],
    connect->errhp,
         i+1,&((*proc)->stmthp), (sb4) 0,
         SQLT_REF, (dvoid*) 0, (ub2*) 0, (ub2*) 0,
    (ub4) 0,
         (ub4*) 0, (ub4) OCI_DEFAULT));
    default:
    some code ....
    checkerr(&connect, \
         OCIStmtExecute(connect->svchp, connect->stmthp,\
         connect->errhp, 1, (ub4) 0, (OCISnapshot*) 0,\
         (OCISnapshot*) 0, OCI_DEFAULT));
    parm_status = OCIParamGet(connect->stmthp, OCI_HTYPE_STMT,connect->errhp, (dvoid**)&arg, 0);
    while(parm_status == OCI_SUCCESS)
    OCIAttrGet((dvoid*) arg, OCI_DTYPE_PARAM,
    (dvoid*)type,0, (ub4) OCI_ATTR_NUM_PARAMS,
    connect->errhp);
    counter++;
    parm_status = OCIParamGet(connect->stmthp,
    OCII_HTYPE_STMT,connect->errhp,
    (dvoid**)&arg, counter);
    This piece of code doesn't work as 'arg' is always NULL
    and OCIParamGet retruns OCI_SUCCESS.
    I'm certainly missing something but I don't see what. Could anyone help me to get that piece of code working?
    regards,
    Raphael

    unfortunately, not yet!
    I dropped the matter for now, I'll come back on it later.
    On your side, let me know if you find something interesting on that topic by posting a message here.

  • How to open a Ref cursor in Oracle Reports

    I have a stored procedure that returns a ref cursor as an output parameter. I want to call this stored procedure in Oracle Reports After Form trigger. I am having trouble with the syntax of the output parameter. Event_record is the name of the cursor.
    After Form Trigger
    pkg_DEAL_WHITESHEET_CONCERTS.prc_Event_Information(:p_field_6,event_record);
    Error: Event_record must be declared

    Re-Write the procedure as Package Spec and Body. Declare the REFCursor in the Package Spec. Probably that helps.

  • How to out Dynamic ref cursor from Procedure to Forms

    Hi
    I am trying to out Dynamic ref cursor from Procedure to Forms, But I am unable to do so. however cursor return the value within procedure but I am failed to capture the same in Forms
    Pl advice suggestion if any, Here I am attaching full procedure for reference
    CREATE PACKAGE winepkg
    IS
    TYPE wine IS RECORD ( mynumber number);
    /* Define the REF CURSOR type. */
    TYPE wine_type IS REF CURSOR RETURN wine;
    END winepkg;
    CREATE procedure find_wine
    (col1_in in number,
    c1 out winepkg.wine_type) as
    vsql varchar2(1000);
    cur sys_refcursor;
    x number;
    BEGIN
    vsql:='select bo_id from bo_details where bo_details.bo_id = '||col1_in ;
    open cur for vsql;
    c1:=cur;
    --fetch c1 into x;
    --dbms_output.put_line(x);
    END find_wine;
    In front end forms
    Declare
    TYPE F is REF CURSOR;
    CUR_F F;
    rec number;
    Begin
    break;
    find_wine( 1601480000011078,cur_f ) ;
    Loop
    fetch cur_f into rec ;
    Message(rec ) ;pause;
    exit when cur_f%notfound ;
    End loop ;
    exception
    when others then
    Message(sqlerrm) ;pause;
    End ;

    yo can use
    declare
    c_cursor EXEC_SQL.CursType;
    v_stmt varchar2(2000) = 'select a, b, c from mytab where cond1'; -- you can create this value dynamically
    begin
    c_cursor := Exec_SQL.Open_cursor;
    EXEC_SQL.PARSE(c_articulos, v_stmt);
    EXEC_SQL.DEFINE_COLUMN(c_articulos,1, v_colchar1, 30);
    EXEC_SQL.DEFINE_COLUMN(c_articulos,2, v_colchar2, 15);
    EXEC_SQL.DEFINE_COLUMN(c_articulos,3, v_colchar3, 30);
    v_exec := EXEC_SQL.EXECUTE(c_cursor);
    WHILE EXEC_SQL.FETCH_ROWS(c_cursor) > 0 LOOP
    EXEC_SQL.COLUMN_VALUE(c_cursor,1,v_colchar1);
    EXEC_SQL.COLUMN_VALUE(c_c_cursor,2,v_colchar2);
    EXEC_SQL.COLUMN_VALUE(c_c_cursor,3,v_colchar3);
    assign_values_to_block;
    END LOOP;
    EXEC_SQL.CLOSE_CURSOR(c_cursor);
    end;
    and WORKS IN FORMS 6

  • How to handle empty variable in BPEL Assign.

    Hello ,
    I am using SOA 11g R1
    I have created one Human task with task Details. Also i am assigning the Usercomments/task/comments to onw of my variable, but if I dont provide the comments from worklist comments section, and approves the task, My Assign is giving error as it is empty. So i want to know is there any function in BPEL which can handle Empty string.
    Thank you,
    Sandeep

    By using this type
    bpws:getVariableData('Invoke_DB_WorkOrderNumber_DB_WorkOrderNumber_OutputVariable','OutputParameters','/ns10:OutputParameters/ns10:P_Name')
    !=''
    also i cant give counts because before comparing accessing variable itself gives empty <message fault > error.
    I am still getting selection failure fault as my comments is empty (i..e I am not giving comments)
    does bpws:getVariableData() itself try to access the given parameter and populates empty error.?
    I tried
    bpws:getVariableData('AssigneeApprovalProcess_1_globalVariable','payload','/task:task/task:userComment/task:comment') !=''
    string-length(bpws:getVariableData('AssigneeApprovalProcess_1_globalVariable','payload','/task:task/task:userComment/task:comment') )>0
    but same error still.

  • How to handle empty value coming to PI

    Hi Experts,
    My scenario is ABAP proxy to File. ABAP program is sending data to PI with blank value. But in PI payload that field is not showing at all.
    Suppose customer number value is blank in ABAP internal table, in PI payload customer number xml tag is not showing at all in source structure.
    Have used one to one mapping and in content conversion we have used.
    .addHeaderLine      0
    .fieldSeparator     ;
    endSeparator     'nl'
    and also I need - if any value in the source structure is coming empty we need to replace it with semi colon.it is not for a specific field, it might be any field of source structure.
    please help on this.
    Thanks,
    Swapnashree

    Hi,
              Before you call the message mapping in interface mapping, u need a java mapping code. This code will check if the required tag is absent. In case the required XML tag is missing, the java mapping code will insert the tag under proper parent node. This is best accomplished using DOM parser. If you need any further guidance from forum members on how to achieve this, then you need to publish following information
    1. Version of PI you are working on.
    2. Source XML structure.
    3. Target XML structure.
    You may refer to various java mapping blogs in SDN for further information on the topic.
    Else try this mapping of the source field
    Source field--------Exists ------> if  ----------------- target field
    if the condition evaluates true    then  map  source field -------> target else  constant (";") ------->target.
    regards
    Anupam
    Edited by: anupamsap on Sep 20, 2011 2:42 PM

  • How to Handle Empty

    Hi,
       I have two column's Male and Female; based on category, say for ex in professional how many males and how many females like that i am displaying the values. If Females does not contain the values for specific type means it display empty; instead of empty i want to display 0; How i need to check in (IF Condition for empty cell), or another alternative ways.
    Thanks lot,
    Regards,
    -B-

    could you post more details?
    Thanks Man
    Thanks lot
    Regards,
    -B-
    Edited by: Balaji J on Aug 12, 2008 11:43 AM

  • How to handle empty string

    Hi
    i have some 4 text fields in one jsp ,and i wanted to pass some strings to the other jsp ,if i fill only 2 text field then at the other page (after submitting) it gives error as empty string ,i want to handle this error

    i am giving the part of error page ,here in this case i am not at all filling 2 text fields ,due to which i am getting the error
    type Exception report
    message
    description The server encountered an internal error () that prevented it from fulfilling this request.
    exception
    org.apache.jasper.JasperException: empty String
         at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:254)
         at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:295)
         at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:241)
         at javax.servlet.http.HttpServlet.service(HttpServlet.java(Compiled Code))
         at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java(Compiled Code))
         at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java(Compiled ................................................
    root cause
    java.lang.NumberFormatException: empty String
         at java.lang.FloatingDecimal.readJavaFormatString(FloatingDecimal.java(Compiled Code))
         at java.lang.Float.parseFloat(Float.java(Compiled Code))
         at org.apache.jsp.save_bps_jsp._jspService(save_bps_jsp.java:72)
         at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:137)
         at javax.servlet.http.HttpServlet.service(HttpServlet.java(Compiled Code))
         at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:210)
         at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:295)

  • How to handle empty field in idoc to file scenario

    some field of IDoc is empty, there occurs error. like
    <Trace level="1" type="T">com.sap.aii.utilxi.misc.api.BaseRuntimeException: RuntimeException in Message-Mapping transformation: Cannot produce target element /ns0:vendor_list/vendor[3]/company_code. Check xml instance is valid for source xsd and target-field mapping fulfills requirements of target xsd at

    Hi Shen,
    You can do this in two ways :
    1.If you are above XI3.0 SP14 then you can use the node function "mapWithDefault" in between the mapping. This will create the xml tag for the field on the target side even if you are not having those fields in the source side i.e.,  idoc.
    2.At first check your field exists or not at runtime & based on that  If exists then you map it to the target field else if you dont have then if the field is alphanumeric then map the same length spaces as constant in the target or if the target field is numeric then map with a constant having that many no. of zeros.
    Ex:
    If>Idocfield>Exists>then>Idocfield
    >else>constant(may be with spaces or zeros)
    Regards,
    Vinod.

  • How to handle empty columns

    Hi guys,
    I have a template like below
    for each
    Field1 Field2 Field3
    Field4 Field5 Field5
    end for each
    I used a if condition to hide the field when the value is null.
    The report looks like below
    Field1 Field2 Field3
    NULL NULL Field6
    Field7 NULL NULL
    Question is how to make the report look better?

    Hi
    once check this
    https://blogs.oracle.com/xmlpublisher/entry/conditional_rows_and_columns

Maybe you are looking for