refcursor or object?

Working on a stored procedure that is called by the java application.

I do not know which of the following option is better and in which case:

1 stored procedure return/accepting a SYS_REFCURSOR parameter
or
2. at the level of schema:

TYPE AS OBJECT emp_attrb_obj (attribute_type_id NUMBER (10),)
attribute_val VARCHAR2 (50)
);
create or replace
TYPE emp_attrb_type AS THE emp_attrb_obj TABLE;

and then have a stored procedure accepts or returns a parameter of type emp_attrb_type

Thank you
RN

RN says:
Working on a stored procedure that is called by the java application.

I do not know which of the following option is better and in which case:

1 stored procedure return/accepting a SYS_REFCURSOR parameter
or
2. at the level of schema:

TYPE AS OBJECT emp_attrb_obj (attribute_type_id NUMBER (10),)
attribute_val VARCHAR2 (50)
);
create or replace
TYPE emp_attrb_type AS THE emp_attrb_obj TABLE;

and then have a stored procedure accepts or returns a parameter of type emp_attrb_type

Thank you
RN

Well, a java application is unlikely to be able to pass a ref cursor, your procedure will therefore not need to accept a. Other than that, it really depends on how the data that you expect to get past back.

I have a number of stored procs called by java applications that return a single row in a table. In these cases, I often return an object, since it saves a step for Java guys who can use it more or less directly. Is there is not a limit on the number of rows returned exlplicit, then I would always return a refcursor.

If the java app must pass a set of values in the stored procedure (for example get this list of employees), then I would have java pass an array of objects (an array of records) to the stored procedure. It keeps me from having to parse a delimited string of values.

John

Tags: Database

Similar Questions

  • DDL lock on the object in a SELECT statement?

    Environment:

    Oracle 11.2.0.4 EE on Solaris

    My client called me when she was trying to create a new index on a table and the process was just hanging.  Also, she was not able to DELETE an existing index on the same table, which deal with hang them as well.

    After reviewing the advice DBA_DDL_LOCKS, I found a DDL lock on the target of the index table.

    The DDL lock is held by a process doing a SELECT on the table and this process worked for several hours.

    There was no entry in V$ LOCKED_OBJECTS for the table.

    I don't know, yet, what other operations prior to the SELECT statement in the offending process, I have not heard of the user yet.

    I realize a DDL lock is placed on objects to prevent changes while specific operations are directed against this object, i.e. the DROP, UPDATE, compile the PACKAGE, etc.

    Question: Is a select also place a DDL lock on a table at a level that would avoid a new index is created or an existing index having fallen?

    Thank you very much for your comments!

    Any reference to the resolution is greatly appreciated.

    I searched some Concepts Developers Guide, SQL, even Google reference Guide.

    -gary

    > My question is now, this lock persists for the duration of the running query?

    Easy enough to show that it is not.

    Session1:

    SQL> create table foo(bar number);     
    
    Table created.                         
    
    SQL> insert into foo values(1);       
    
    1 row created.                         
    
    SQL> commit;                           
    
    Commit complete.                       
    
    SQL> variable x refcursor
    SQL> variable a number
    SQL> begin
      2  open :X for select bar from foo;
      3  end;
      4  /                                 
    
    PL/SQL procedure successfully completed.
    

    Session 2:

    SQL> drop table foo;
    
    Table dropped.     
    

    Note that I was able to remove the table even if select is still 'in progress' - the cursor is open.

    If you really want to blow your mind, go back to the session 1:

    SQL> begin
      2  fetch :X into :a;
      3  end;
      4  /                                
    
    PL/SQL procedure successfully completed.
    
    SQL> print a                          
    
             A
    ----------
             1       
    

    The picture has gone, but I can always look for him. However, try again:

    SQL> /
    begin
    *
    ERROR at line 1:
    ORA-00604: error occurred at recursive SQL level 1
    ORA-00942: table or view does not exist          
    

    Note that the forum software is stupid. is: followed by x. seems it's really important to have a smiley to lovey eyes in a technical forum.

    Edit - and when you format the SQL code, it is removed completely and render invisible... silly.

    I edited my code to use: X and the problem disappeared...

  • Refcursor in the procedure

    Hi all

    There will be no effect in performance if we declare refcurosr with suspicion NOCOPY parameter in a Stored procedure procedure/package?

    AFAIK variable refcursor who will make reference to the calling environment will hold just pointer not data and so avoid a NOCOPY effect.

    Thank you!!

    DS says:

    One of my senior team members asked me to NOCOPY in all existing procedures where refcursor is returned as a parameter in my output project.

    I told him that this will not add any performance improvement and has no effect.

    I did it, because I was forced to do so.

    Want to just check and take the advice from here in this forum.

    I still have the document (in e-mails and in the procedure itself at the top) all these changes so that the future code-reviewers know EXACTLY why this change has been made and who authorized it. Probably you are asking your "senior" you say the reasons to support the change that they requested; You should document those as well.

    Sounds like your "senior" team member is not so superior after all. You can use this as a topic of discussion in your dev group.

    See the doc of the PL/SQL language.

    http://docs.Oracle.com/CD/B28359_01/AppDev.111/b28370/tuning.htm#i48500

    Calls to PL/SQL Tuning subprogramme with NOCOPY hint

    By default, OUT and IN OUT parameters are passed by value. The values of a IN OUT settings are copied before the delivery of the subprogramme. During the execution of the subprogramme, temporary variables to maintain the output parameter values. If the subprogram exits normally, these values are copied to the actual parameters. If the subprogram exits with an unhandled exception, the original settings are unchanged.

    When the parameters represent structures of large data such as collections, records and instances of object types, this reproduction slows down execution and uses memory. In particular, this overload applies to each call to a method of the object: temporary copies are made of all attributes, so that any changes made by the method are only apply if the method ends normally.

    To avoid this overload, you can specify the NOCOPY trick, which allows the PL/SQL compiler to pass OUT and IN OUT parameters by reference. If the subprogram exits normally, the action is the same as usual. If the subprogramme leaves at the beginning with an exception, the values of OUT and IN OUT parameters (or the attributes of the object) can still change. To use this technique, check that the subroutine handles all exceptions.

    Note the reference to the "large data structures. As you already know a REFCURSOR isn't a large data structure, so will not use NOCOPY.

    The most important side effect is that, as noted in the last paragraph above, the characteristics of the 'exit' are modified if you use NOCOPY.

    Point out that the last clause in your "senior": ENSURE THAT THE subprogram MANAGES all THE EXCEPTIONS.

    Normally (i.e. without using NOCOPY) a REFCURSOR lucifera is a parameter OUT will NOT have a value if the procedure stops with an exception if the caller is unable to use it eventually. Maybe this isn't the case if you use NOCOPY.

    Generally however, the use of NOCOPY would simply be an amendment unnecessary, but harmless.

  • Insert the output of a refcursor procedure into a table

    Hello

    I met a scenario in which I need to put the insert records returned by a procedure using refcursor, at a table.

    I followed the instructions in PL/SQL 101: understanding Refcursor (PL/SQL 101: understanding Ref Cursor am unfortunately still not able to do so.)

    Here is my sample codes. (Copied here as advised by the new Member)
    create or replace PROCEDURE TEST_PROCEDURE1 ( p_cursor OUT SYS_REFCURSOR)
    AS
    BEGIN
    OPEN p_cursor FOR
    SELECT C1,C2
    FROM TEST_USER.test_table4procedure;
    END;
    I check the result using the following statement, which gives results.
    variable rc refcursor;
    exec TEST_USER.TEST_PROCEDURE1 (:rc)
    print rc;
    Now, I want to be able to use the output and insert the data into a table. That's how I came across this thread.

    I created the types and function...
    create or replace type test_user.type_table1 as object(var1 varchar2(50),var2 varchar2(50));
    create or replace type test_user.type_table2 as table of test_user.type_table1;
    
    create or replace function test_user.test_function1 (rc in sys_refcursor )
    return test_user.type_table2 is
    v_emptype test_user.type_table2 := test_user.type_table2(); -- Declare a local table structure and initialize it
    v_cnt number := 0;
    v_rc sys_refcursor;
    v_var1 varchar2(20);
    v_var2 varchar2(20);
    begin
    v_rc := rc;
    loop
    fetch v_rc into v_var1, v_var2;
    exit when v_rc%NOTFOUND;
    v_emptype.extend;
    v_cnt := v_cnt + 1;
    v_emptype(v_cnt) := test_user.type_table1(v_var1, v_var2);
    end loop;
    close v_rc;
    return v_emptype;
    end;
    After that, I want to be able to view the records by using the function... so I used the instructions below...
    variable rc refcursor;
    exec TEST_USER.TEST_PROCEDURE1 (:rc)
    SELECT * FROM TABLE(test_user.test_function1(:rc));   
    However, it fails with the error

    Error from line 3 in order:
    SELECT * FROM TABLE (test_user.test_function1 (:rc))
    Error report:
    SQL error: Missing a setting IN or OUT to index: 1

    Help, please...

    Your code does not work for a simple reason. SYS_REFCURSOR parameters must be in IN OUT mode. Check if the RC is open when he switched mode:

    create or replace type type_table1 as object(var1 varchar2(50),var2 varchar2(50))
    /
    create or replace type type_table2 as table of type_table1
    /
    create or replace PROCEDURE TEST_PROCEDURE1 (p_cursor IN OUT SYS_REFCURSOR)
    AS
    BEGIN
    OPEN p_cursor FOR
    SELECT ENAME,JOB FROM EMP;
    END;
    /
    create or replace function test_function1 (rc in sys_refcursor )
    return type_table2 is
    v_emptype type_table2 := type_table2(); -- Declare a local table structure and initialize it
    v_cnt number := 0;
    v_var1 varchar2(20);
    v_var2 varchar2(20);
    begin
    if rc%isopen
      then
        dbms_output.put_line('rc is open');
      else
        dbms_output.put_line('rc is not open');
     end if;
    loop
    fetch rc into v_var1, v_var2;
    exit when rc%NOTFOUND;
    v_emptype.extend;
    v_cnt := v_cnt + 1;
    v_emptype(v_cnt) := type_table1(v_var1, v_var2);
    end loop;
    close rc;
    return v_emptype;
    end;
    /
    variable rc refcursor
    exec TEST_PROCEDURE1(:rc)
    set serveroutput on
    SELECT * FROM TABLE(test_function1(:rc))
    /
    SELECT * FROM TABLE(test_function1(:rc))
                        *
    ERROR at line 1:
    ORA-01001: invalid cursor
    ORA-06512: at "SCOTT.TEST_FUNCTION1", line 15
    
    rc is not open
    SQL> 
    

    Now IN OUT parameter edit mode:

    set serveroutput off
    create or replace function test_function1 (rc in out sys_refcursor )
    return type_table2 is
    v_emptype type_table2 := type_table2(); -- Declare a local table structure and initialize it
    v_cnt number := 0;
    v_var1 varchar2(20);
    v_var2 varchar2(20);
    begin
    if rc%isopen
      then
        dbms_output.put_line('rc is open');
      else
        dbms_output.put_line('rc is not open');
     end if;
    loop
    fetch rc into v_var1, v_var2;
    exit when rc%NOTFOUND;
    v_emptype.extend;
    v_cnt := v_cnt + 1;
    v_emptype(v_cnt) := type_table1(v_var1, v_var2);
    end loop;
    close rc;
    return v_emptype;
    end;
    /
    variable rc refcursor
    exec TEST_PROCEDURE1(:rc)
    set serveroutput on
    declare
    v_emptype type_table2 := type_table2();
    begin
    v_emptype := test_function1(:rc);
    end;
    /
    rc is open
    
    PL/SQL procedure successfully completed.
    
    SQL> 
    

    Problem is that you can't call the procedure/function with parameters in/out OUT of SQL.

    SY.

  • How to store refcursor in collection

    Hello


    Storing refcursor values in the collection, I get this error
    The game results or the query variables return types do not match.


    Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - 64bi

    {code
    -drop type patdetail_tab;
    -drop type patdetail_obj;
    -drop pat table;
    -drop table t_pat;

    CREATE or REPLACE TYPE patdetail_obj
    AS
    OBJECT (patid varchar2 (20), supplierid number)
    /

    CREATE or REPLACE TYPE patdetail_tab AS TABLE OF THE patdetail_obj;
    /

    (Pat) CREATE TABLE
    patid varchar2 (25).
    Vendor number
    );

    /

    INSERT INTO pat
    (
    patid, provider
    )
    VALUES ('A1', 1);

    INSERT INTO pat
    (
    patid, provider
    )
    VALUES ('A2', 2);

    COMMIT;

    CREATE TABLE t_pat)
    patid varchar2 (25).
    Vendor number
    );

    /

    DECLARE
    vpatdetail patdetail_tab;
    emp_cv sys_refcursor;
    BEGIN
    OPEN FOR Emp_cv
    SELECT patid, provider
    PAT;

    Get the emp_cv COLLECT in BULK IN vpatdetail;

    INSERT INTO t_pat
    (
    patid, provider
    )
    SELECT *.
    TABLE (vpatdetail);

    COMMIT;
    END;
    ORA-06504: PL/SQL: Return types of Result Set variables or query do not match
    ORA-06512: at line 9
    
    
    
    Please assist me 
    
    Thanks
    
    Alen                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                    

    Well, I hope this is something much more complex than what you mentioned (or you do not want to use a SINGLE SQL statement to insert in...) Select * from...), but assuming that you that boiled down to make a test case easy for us (thanks!), here's a solution.

    You must inform the database that you are using the object type you'll be mining block, the

             patdetail_obj(patid, supplier)
    

    in the code below

    DECLARE
       vpatdetail patdetail_tab;
       emp_cv sys_refcursor;
    BEGIN
       OPEN emp_cv FOR
          SELECT
             patdetail_obj(patid, supplier)
          FROM pat;
       FETCH emp_cv BULK COLLECT INTO vpatdetail;
    
       INSERT INTO t_pat
       (
       patid, supplier
       )
       SELECT *
       FROM table (vpatdetail);
       CLOSE emp_cv;
       COMMIT;
    END;
    
  • Call a procedure that returns a refcursor, use it in an another proc sql?

    I have a procedure that returns a refcursor; How can I include this refcursor in a sql statement that is inside another procedure, or view etc.?

    This is the kind of foolery, I tried so far (myproc1 returns a ref cursor):

    create or replace procedure myproc2
    (
    slider ref RC
    )
    AS
    RC1 of ref cursor;
    Start
    EXECUTE myproc1 (rc1).
    Open rc for
    Select rc1.* in the rc1;
    end myproc2;

    If you want to use the result set in an SQL Ref Cursor won't be of any help. Can be read all nested Table Type. You can declare an object type and store your result in them and use them in SQL.

    Thank you
    Knani.

  • Should I use OracleCallableStatement to treat a REFCURSOR?

    Oracle 10g 2 Rel using last Oracle thin driver on a Java 1.5 application.

    I'm porting of our existing application to Oracle, but for the next few months, I do need to support several databases (SQL Server, DB2) with the same line of code. Our db access layer is stored procs wrapped in CallableStatements according to which a large majority returns a set of results. I so need to continue to use the ResultSet objects and existing java.sql.CallableStatements.

    A typical stored proc looks like this:

    CREATE OR REPLACE PROCEDURE getMeData
    (
    v_c_columnname IN VARCHAR2 DEFAULT NULL,
    v_intSort IN the DEFAULT NUMBER 0.
    cv_1 IN OUT SYS_REFCURSOR
    )
    AS
    BEGIN
    OPEN FOR Cv_1
    SELECT col1,
    col2,
    COL3
    FROM someTable
    WHERE somecolumn = v_c_columnname;

    END;
    /

    We have summarized currently calls stored procedure by doing a check on which db platform, then wrapping with either EXEC or dial the CALL and the construction of the proc for the target RDBMS.

    My first question is: is it possible for me to handle/process the REFCURSOR back in java.sql.Callable vanilla games/statement of results, or if I have to use oracle.jdbc.CallableStatment (and save the output cursor type (IE, cStmt.registerOutParameter (3, OracleTypes.CURSOR)?))

    Second question - I'm currently testing with the OracleCallableStatement, but my cStmt.execute will simply ignore the call of execute - I know its built correctly, and when I call via pl/sql with the dregs, it returns correctly, so am I missing something in the way of treating the REFCURSOR? It is not fails with an Oracle error, it's just not executing.

    It's the call:
    begin getMeData(?,?,?); end;

    Last question - must use a REFCURSOR to return a result set via PL/SQL stored procs, or is there another way?

    TIA

    right. She must be from an Oracle driver to work
    with JDBC Oracle oracle-specific characteristic examples.

  • Closing refcursors - is implied - example - refcursor OUT param in SP

    Hello
    I wanted to know if it is necessary to close the refcursors which are the parameters of stored procedures. They are closed implicitly or do we have to explicitly close?

    If the slider's handle is passed back to a Java application, there is no way to close the cursor of the rear part. Only the side Java could close the cursor handle.

    You must simply ensure that the client application is closing the game of results even in case there is a thrown exception (i.e. a finally block when you close the ResultSet object, close the investigation, close the connection).

    Justin

  • iPhone 7 - camera can not focus/blur distant objects

    Recently got my iPhone 7 two weeks ago, when he was released. My camera was working fine but for the last two days, when I try to focus on a person/object far away, it remains unclear. It is not just sharpen or focus on the person/object. It's only focus on something that is very close to the camera. You're not sure if it is a new problem...? Someone knows how to fix this? Thank you.

    Hey jdcn204,

    Thank you for using communities Support from Apple. I can see from your post that you are having problems with your iPhone 7 camera being fuzzy or blurry when you try to take pictures. I understand how it is important for the camera to work as expected and want to do all that we can to remedy to this. I have included a link below which has a section focused on the ways to solve this class under your photos are blurry or out of focus:

    Get help with the camera on your iPhone, iPad or iPod touch

    Let us know if that helps.

    See you soon.

  • Smooth against a move sharp objects on the screen

    Hello

    I have a number of applications that show the following behavior: when I click on an object on the display on the screen, the object moves * gently * to its position to another, predetermined by the application, position.

    I see this problem on my iMac.

    When I run the same applications on my MacBook Air the moving of objects from home position in the end still happens but in a * sudden * way - i.e. the object jumps abruptly starting position for the finals. The sweetness of the movement I see on the iMac is no longer exists.

    I love soft travel.

    Applications do not provide any parameter to control the way objects move (gently or brutally), I guess it is somehow controlled by the operating system. A parameter is defined differently on the iMac and the MacBook Air.

    (Both machines run El Capitan 10.11.6)

    Someone has an idea of what could be this setting? Or in any other way, I can have a good moving objects on the MacBook Air?

    Thanks in advance.

    FWIW, I do not know why your etrecheck report has been deleted, but you try to run applications on a 4 GB machine too. You should limit the number of objects, connect, and the number of programs you are running at the same time.

  • Trimming of a fast moving in a video object.

    Hello. I hope that my question is not too complicated, but I want to shoot video of a small, fast moving object (a RC plane) on my iPhone of 6 to 4K, then "reframe" video for an enlarged image of the object. A plane RC zooms in on a camcorder recording can be extremely difficult, that's why I want to try cropping. I tried cropping videos in iMovie, but it does not reach the desired effect that the plane did not stay always in the same place, even on video with zoom out.

    Is it possible to crop a video, and then move the 'culture' smoothly to track an object, so it don't go out of the frame? I've always had problems saving objects moving quickly zoomed in I always loose track of them so I hope someone here has done this before and knows how to do.

    I just got my first Mac and I really enjoy free programs that are installed.

    Thank you

    Adam

    It is not really possible to do with iMovie and difficult even with professional video editors.

    I would put the k 4 clip in the timeline panel as the first clip in order to put the project to 4 k.  I would try to stabilize it but this will very probably stabilize background rather than the position of the aircraft in the framework.  You can crop the video but the only way to move from his position is by using the Ken Burns effect, but it does not seem possible to use keyframes to follow the plan (as you can with picture in picture).  You can split the clip into parts and apply individual effects of Ken Burns to everyone, but it will be awfully tedious if the movement of the aircraft is fast and jerky.

    To do this you must use a professional editor like FCPX, for which there are plugins from third party that can follow an object in a frame.   Even then, it is not easy to get a good result.

    Geoff.

  • How drag and drop a picture into a shape of the object?

    On my old Lion system that I used to be able to drag a picture from iphoto in the shape of the object open in Pages.  I can't be able to do more.  The system changed?  I tried to use Inspector (under help), but it won't let me access the file of the photo on the right.

    You can drag and drop a picture in a form in v4.3 Pages ' 09, but this can be done in any version of v5 Pages. Quite different applications, as well as more recent Pages has lost about 100 features that were in its antecedent.

    Check if you have Pages ' 09 v4.3 in your Applications: iWork ' 09 file. If so, use it.

    Pages v5 requires that you select a shape, and then on the Image tab in the right panel, you choose Image, scale to fill fill, and then select your image for the background. You cannot select this image from the inside, but you can add text to the form that will appear on your image.

  • Please tell us how to remove the 'message thread function' in the column 'Object' of my Inbox.

    Hello!
    For some reason, the column of the object on the Inbox of my e-mail account now has the topics of conversation. I have no idea how the son got there - and you would appreciate the help in eliminating these threads.
    Thanks a lot for your help.

    In the main menu bar:
    View (Alt - V) - sort by - Unthreaded

  • The text of the e-mail under the column of the object does not match the selection

    When I get to my Inbox and select an e-mail to open the middle box and the text box below do not match the selection in the object column. This has occurred recently and only on my laptop. My office works fine. The central area and the text matching, this email has been deleted but the text won't just change and go. I'm going on a trip tomorrow, and if I can't fix this, I won't be able to open emails with possible solutions. I'll see answers but can't open them.

    right click on the folder, select Properties, and then on the button repair.

  • The object you have requested is not currently available in Apple music in India.

    "The object you requested is not currently available in the music for Apple in India." I see this error when I select an album. I'm not able to see the album. I am able to see only ablbum when I connect, but when I connect with my apple id I can't find this album.

    It is not available in India, the message said.

    This means that the copyright holder has no have license to distribute in India.

Maybe you are looking for

  • account name on my 'password reset info' is NOT mine and I can't delete it

    In the account overview > password reset information > Email is an email account that is not mine and I can't remove it. If I click on remove and return the e-mail address appears as LOST, marked in red, but has not disappeared. Thank you

  • View compound do not pass physics

    HelloMy ODI12C installed in the mapping, I'm not found view composed of physical mapping tab.I have attached the current view.Help, please.BRFrançoise

  • external drive suddenly protected by bitlocker

    I have just connected my external hard drive to a machine of win8 and was informed that it was protected from bitlocker. I had never heard of bitlocker and therefore have no idea of the key. I then connected the same drive to another, more recent mac

  • Editable ComboBox bug?

    HelloI reproduce a ComBox behavior which I suspect to be a bug in a small example.When the TextField object intercepts the event, the println displays the current value = > OKWhen the ComboBox control (which is editable) intercept the println event d

  • Center of HP Solution missing components Windows 8

    I've just upgraded my PC to Windows 8 Pro (X 64) I downloaded solution Center software for my HP C309a all in one and discovered that there is only half of the available elements that were in the version of Windows 7. Specifically printing to disc fu