Reg: Cursor (implicit / explicit)

Dear gurus,

Could you please give me advice on this code below. It is below an implicit cursor / explicit cursor. Insofar that I studied (correct me if wrong), a select statement runs at the SQL prompt, it is supposed to be as implicit cursor.  But, this one is explicit, as we wrote in the PLSQL block and you can call it as a CURSOR for LOOP.

SQL > ed

A written file afiedt.buf

1 start

2 for i in (select ename from emp)

loop 3

4 dbms_output.put_line (' name :'|| i.ename);

5 end of loop;

6 * end;

SQL > /.

Name: SMITH

Name: ALLEN

Name: WARD

Name: JONES

Name: MARTIN

Name: BLAKE

Name: CLARK

Name: SCOTT

Name: KING

Name: TURNER

Name: ADAMS

Name: JAMES

Name: FORD

Name: MILLER

PL/SQL procedure successfully completed.

Thank you.

Hello

IMPLICIT cursor: Implicit cursor is created "automatically" for you by Oracle when you run a query.

Example: SELECT ename FROM emp;

EXPLICIT CURSOR: You create your own explicit cursor.

DECLARE

VARCHAR2 (20) var1;

CURSOR cur IS SELECT ename FROM emp where empno = 7566;

BEGIN

Heart OPEN;      -Opening the cursor

Fetch cur INTO var;

CLOSE cur;    -Closing of the cursor, if we free the memory occupied by this cursor

END;

The code you gave is also implicit cursor only.

Tags: Database

Similar Questions

  • Cursor implicit FOR THE LOOP and WHERE CURRENT OF

    Is it possible to add some updates and WHERE CURRENT OF for an implicit cusror of LOOPS?  There seems to be no way to reference the cursor as you can with an explicit cursor.

    BEGIN

    FOR point IN)

    SELECT last_name, job_id

    Employees

    WHERE job_id LIKE '% % CLERK '.

    AND manager_id > 120

    ORDER BY name

    )

    LOOP

    ...

    ...

    ...

    END LOOP;

    END;

    /

    Thank you

    It must be an explicit cursor.

  • Dynamic cursor Type strong?

    I am currently using Oracle 11.2 G and I was wondering if you can declare a dynamic cursor as a strong Ref Cursor type or it may be declared as weak type ref cursor? Now, if she can only be declared as a weak type Ref Cursor, is it possible to avoid having to explicitly declare the type names and field being returned by the cursor? Sense, is any way to avoid having to do something like that...
    TYPE example_rec IS RECORD
    (
     col1 VARCHAR2,
     col2 NUMBER,
     col3 NUMBER,
     etc...
    )
    Instead, I was wondering if I could just set the fields and their types by defining them as a TABLE OF THE ref cursor?

    I wonder if this is possible is because I have a large number of fields returned in my cursor, and I was hoping on not having to type each person and its type. In addition, I think this would make maintenance easier.

    user652714 wrote:
    No, not quite. I ask if I can create a strong dynamic type Ref cusors. Here is a Pseudo code:

    DECLARE
    TYPE test_rec IS TABLE OF test_cur%ROWTYPE; -- i'm wondering if i can do something like this
    --'The code below is what I am TRYING TO AVOID'
    TYPE test_cur IS REF CURSOR;
    TYPE test_rec IS RECORD
    (
    col1 VARCHAR2,
    col2 NUMBER,
    col3 NUMBEr
    )
    

    Is not possible.

    Let's say you would set an TEST_REC as above. How would refer to the members of the structure of your code? This type could describe anything like projection of the cursor could be anything - a unique column, to a 100 columns. A combination of columns that can include data types of the LOB of tables nested SQL types defined by the user.

    So, how can you refer to these columns in the structure of table TEST_REC ? Guess?

    A new concept - all SQL statements are parsed, stored and executed as sliders. REF CURSOR, cursors implicit, explicit cursors and so on, are CLIENT interfaces to the created SQL cursor. Each of these interfaces to client cursor works in a specific way and provide a set of specific features.

    Next concept - to extract a SQL cursor, the client code NEEDS to know the structure of the projection of this cursor SQL. The code needs to know the number and types of data in the columns returned by the cursor.

    The customer may address the issue in two ways.

    Statically. In other words, at the time of coding, SQL projection, returned by this SQL cursor is known. The developer can thus use some thing like + % RowType % + to indicate to the compiler that record structure to define. The compiler parses the SQL cursor in the code, describes the projection of SQL and compiles this projection of SQL as the static structure in the code.

    + % RowType + in this regard is as a #define of C macro. He tells the PL/SQL compiler to describe the cursor SQL projection, then produced a PL/SQL, based on the record structure.

    Dynamically. This means at the time of coding, SQL, returned by this SQL cursor is unknown. In this case the compiler has no idea at compile time what structure will be returned by the cursor. Compiled source code may not define a static structure for this cursor SQL - the SQL cursor may return any kind of structure. The source code needs to use the same approach as what the compiler does when it comes to SQL static cursors.

    The source code needs to analyze the cursor, describe the SQL cursor and then pick dynamically by the cursor. Client cursor interface that supports this approach is DBMS_SQL. No ref Cursor.

    Keep in mind that these static and dynamic methods to describe how the code consumes the cursor - extraction of rows in the cursor.

    A static method (where the projection of SQL is known) however apply to the TWO instructions static SQL and dynamic SQL statements. You can use dynamic SQL statements in your code, but a rule which stipulates that, regardless of the SQL code is waiting for a specific static SQL projection of this SQL cursor.

    The dynamic method (where the projection of SQL is unknown) is 'real' dynamic SQL - as the projection of SQL and are all two dynamic SQL code.

    Examples of Basic code:

    // STATIC SQL CURSOR
    SQL> create or replace procedure FooProc is
      2          cursor  c is select object_id, object_name from user_objects;
      3          type    TBuffer is table of c%RowType;
      4          buffer  TBuffer;
      5  begin
      6          open c;
      7          loop
      8                  fetch c bulk collect into buffer limit 100;
      9                  DBMS_OUTPUT.put_line( buffer.Count||' row(s) fetched.' );
     10                  exit when c%NotFound;
     11          end loop;
     12          close c;
     13  end;
     14  /
    
    Procedure created.
    
    SQL>
    SQL> exec FooProc
    100 row(s) fetched.
    43 row(s) fetched.
    
    PL/SQL procedure successfully completed.
    
    // STATIC SQL PROJECTION, BUT DYNAMIC SQL CURSOR
    SQL> create or replace procedure FooProc( c in out sys_refcursor ) is
      2          E_CURSOR_ERROR  exception;
      3          pragma exception_init( E_CURSOR_ERROR, -00932 );
      4          type    TRecord is record(
      5                          name varchar2(30),
      6                          value varchar2(100)
      7                  );
      8          type    TBuffer is table of TRecord;
      9          buffer  TBuffer;
     10  begin
     11          loop
     12                  fetch c bulk collect into buffer limit 100;
     13                  DBMS_OUTPUT.put_line( buffer.Count||' row(s) fetched.' );
     14                  exit when c%NotFound;
     15          end loop;
     16          close c;
     17  exception when E_CURSOR_ERROR then
     18          close c;
     19          raise_application_error(
     20                  -20000,
     21                  'Cursor projection contains an invalid data structure.'
     22          );
     23  end;
     24  /
    
    Procedure created.
    
    SQL> var c refcursor
    SQL> exec open :c for select object_id, object_name from user_objects;
    
    PL/SQL procedure successfully completed.
    
    SQL> exec FooProc( :c );
    100 row(s) fetched.
    43 row(s) fetched.
    
    PL/SQL procedure successfully completed.
    
    SQL> exec open :c for select object_id, object_name, created from user_objects;
    
    PL/SQL procedure successfully completed.
    
    SQL> exec FooProc( :c );
    BEGIN FooProc( :c ); END;
    
    *
    ERROR at line 1:
    ORA-20000: Cursor projection contains an invalid data structure.
    ORA-06512: at "BILLY.FOOPROC", line 19
    ORA-06512: at line 1
    
    // DYNAMIC SQL AND DYNAMIC SQL PROJECTION
    SQL> create or replace procedure FooProc( sqlSelect varchar2 ) is
      2          c               integer;
      3          rc              integer;
      4          colCnt          integer;
      5          fetchCnt        integer;
      6          projection      DBMS_SQL.DESC_TAB;
      7  begin
      8          --// ceate and parse the cursor
      9          c := DBMS_SQL.open_cursor;
     10          DBMS_SQL.parse(
     11                  c,
     12                  sqlSelect,
     13                  DBMS_SQL.native
     14          );
     15
     16          rc := DBMS_SQL.execute( c );
     17
     18          --// describe the sql projection
     19          DBMS_SQL.describe_columns( c, colCnt, projection );
     20
     21          --// the sql projection's fields/columns
     22          DBMS_OUTPUT.put_line( 'SQL projection:' );
     23          for i in 1..colCnt loop
     24                  DBMS_OUTPUT.put_line( '- '||projection(i).col_name );
     25          end loop;
     26
     27          --// fetch and process
     28          fetchCnt := 0;
     29          loop
     30                  rc := DBMS_SQL.fetch_rows( c );
     31                  exit when rc = 0;
     32                  --// use DBMS_SQL.column_value() to read fetched row's columns
     33                  fetchCnt := fetchCnt + 1;
     34          end loop;
     35          DBMS_OUTPUT.put_line( fetchCnt||' row(s) fetched.' );
     36
     37          DBMS_SQL.close_cursor( c );
     38  end;
     39  /
    
    Procedure created.
    
    SQL>
    SQL> exec FooProc( 'select object_id, object_name from user_objects' );
    SQL projection:
    - OBJECT_ID
    - OBJECT_NAME
    143 row(s) fetched.
    
    PL/SQL procedure successfully completed.
    
  • Ref Cursor on implicit and explicit cursors

    Hello

    In my company the drafting of PL/SQL procedure, everyone uses "Ref Cursor",
    But the article below, said implicit is the best, then Explicit and Ref Cursor...

    [http://www.oracle-base.com/forums/viewtopic.php?f=2 & t = 10720]

    I'm a bit confused by this, can someone help me understand this?

    Thank you

    SeshuGiri wrote:

    In my company the drafting of PL/SQL procedure, everyone uses "Ref Cursor",
    But the article below, said implicit is the best, then Explicit and Ref Cursor...

    [http://www.oracle-base.com/forums/viewtopic.php?f=2&t=10720]

    I'm a bit confused by this, can someone help me understand this?

    It has performance and it has performance...

    To explain. There is one type of cursor in Oracle - that is the cursor which is analyzed and compiled by the SQL engine and stored in the shared the database pool. The "+ client +" then receives a handle (called a SQL statement handle of many APIs) that can be used to make reference to this slider in the SQL engine.

    The performance of this slider is not determined by the customer. It is determined by the execution plan and how much enforcement of this slider cost ito of server resources.

    The customer can be Java, VB, .net - or a PL/SQL program. This client language (SQL client), has its own structures dealing with this from the SQL engine cursor handle.

    It can hide by the developer all together - so that they can't even see that there is a statement handle. That's what the implicit cursors in PL/SQL.

    It can allow the developer to manually define the structure of slider - this is what the explicit cursors, ref Cursor and DBMS_SQL cursors in PL/SQL.

    Each of these client cursor structures provides the programmer with a set of features to address different SQL cursor. Explicit cursor in PL/SQL constructs do not have the use of dynamic SQL statements. REF CURSOR and cursors DBMS_SQL do. REF CURSOR does not allow the programmer determine, at runtime, the structure of the projection of the cursor SQL. DBMS_SQL sliders do.

    Only ref Cursor can be created in PL/SQL and then handed over to another client (for example, Java/VB) for treatment. Etc.

    If each of the works of art/customer interfaces gives you a different feature for SQL cursors.

    Choose the implicit cursors for example does not the SQL cursor move faster. The SQL engine does not know and does not care, which customer construct you use to deal with the SQL cursor handle, he gave you. It does not matter. It does not affect his performance of cursor SQL.

    But on the client side, it can matter - if your code when dealing with that SQL cursor determines how fast your interaction with this SQL cursor is. How many context changes you make. How you use and reuse the SQL (for example hard vs soft analysis vs analysis reusing the same cursor handle). Etc.

    Are there any unique client cursor construction which is better? N °

    It's ignorant views. The customer's language provides a box tool, where each tool has a specific application. The competent developer will use the right tool for the job. The stupid developer will select a tool and use it as The Hammer to 'solve' all problems.

  • Explain implicit and explicit curesor for example?

    Explain implicit and explicit curesor for example?

    Is less than the example of implicit cursor belogs?

    Set serverout
    Start
    I'm in (select * from emp)
    loop
    dbms_output.put_line (i.empno);
    end loop;
    end;

    All THE SQLs are analyzed and stored and runs under the cursor. These are stored in shared SQL database Pool.

    You can view the contents of the shared pool (and sliders inside it) using the V$ SQLAREA and other views of virtual performance.

    The concept of a cursor implicit and explicit cursor is a concept of LANGUAGE - not a SQL concept. It depends on how this language (client) (PL/SQL or Java or C/C++ or Delphi or c# and Perl, etc.) implements its interface language for SQL cursors created in Shared Pool data.

  • What representations using implicit or expicit cursor?

    Don't you be any considaration to use implicit or explicit cursors? I would like to know, especially in terms of performance, when and if it is better to choose betweeen implicitly and a explicit cursor. I'm working on Oracle. 8.1.7
    Thanks in advance.

    Mark1970 wrote:
    Don't you be any considaration to use implicit or explicit cursors? I would like to know, especially in terms of performance, when and if it is better to choose betweeen implicitly and a explicit cursor. I'm working on Oracle. 8.1.7

    There is no difference from the point of view SQL Shared Pool. All SQLs are analyzed as cursors and stored in the shared Pool.

    The SQL engine returns a handle or reference (you can even call a pointer) to the language of the client (Java, PL/SQL, etc.) that he send the SQL statement.

    So the SQL engine, there is no difference. He does not care how the client will use that face returned. If the customer uses this handle as an implicit cursor handle, an explicit cursor handle, the ref, the handle for DBMS_SQL cursor cursor handle... or whatever. He is indifferent to the SQL cursor in the pool shared SQL. He cannot do this slider faster or slower execution.

    On the client side, there are several reasons why it can use this handle to SQL cursor returned by the SQL engine as a variable of implicit cursor or explicit... or as a ref cursor variable These reasons dictate which is the best tool for the job at hand - and the programmer must understand these and select the right tool for the job.

    There is therefore no such thing as an implicit cursor being better or faster than a cursor, explicit, or vice versa. Both are tools to deal with a SQL cursor in the SQL engine. A procedure/package can use this SQL cursor via an implicit cursor variable. An another procedure/package can use the same SQL cursor via an explicit cursor variable.

    So it's not that one is better.

    It's the programmer understand that a cursor is, HOW the client implements access to this SQL cursor via variables of cursor cursor cursor/DBMS_SQL Ref. variables or explicit/implicit... and by CHOOSING the more it is necessary to perform the task at hand.

  • implicit cursor and type oracle

    Hi all

    Is it possible to copy a rowtype of a cursor implicit to an oracle type?

    example of

    create or replace type test_123 (as_of_date date, number of contrat_number) as an object;

    declare

    help_ty test_123;

    Start

    for r1 in (select as_of_date, contract contracts) loop

    help_ty: = r1;

    end loop;

    end;

    It is said that it may not be possible, can you help me please?

    11g

    concerning

    Hello

    You can declare it in the Package specification and can use in the world through the database.

    As below

    create or replace package test_pkg
    is

    type is record (varchar2 (40) first_name, employee_id number);

    end;
    /

    declare

    l_rec test_pkg.emp_rec;

    Start

    for r1 in (select first_name, number of employees)
    loop

    l_rec: = r1;
    dbms_output.put_line (l_rec.first_name);

    end loop;

    end;
    /

    Post edited by: Suri - example added

  • Invalid cursor error

    When I try to run the following pl/sql code, I get error of invalid cursor. Can someone please explain to me where I am doing wrong.
    DECLARE
    CURSOR C1 IS SELECT employee_id,last_name,salary FROM employees;
    
    
    EMP_REC C1%ROWTYPE;
    
    BEGIN
    FOR REC IN C1
    LOOP
    FETCH C1 INTO EMP_REC;
    EXIT WHEN C1%NOTFOUND;
    
    DBMS_OUTPUT.PUT_LINE('Employee Number '||REC.employee_id);
    
    DBMS_OUTPUT.PUT_LINE('Employee Name '||REC.last_name);
    
    DBMS_OUTPUT.PUT_LINE('JOB '||REC.salary);
    END LOOP;
    END;
    Thanks in advance!

    You must decide if you want to open the cursor implicit or explicit:

    You can use:

    Variant1

    DECLARE
    CURSOR C1 IS SELECT employee_id,last_name,salary FROM employees;
    
    BEGIN
    FOR REC IN C1
    LOOP
    
    DBMS_OUTPUT.PUT_LINE('Employee Number '||REC.employee_id);
    
    DBMS_OUTPUT.PUT_LINE('Employee Name '||REC.last_name);
    
    DBMS_OUTPUT.PUT_LINE('JOB '||REC.salary);
    END LOOP;
    END;
    

    Variant2:

    DECLARE
    CURSOR C1 IS SELECT id employee_id, name last_name, id salary FROM arzt where rownum<10;
    
    EMP_REC C1%ROWTYPE;
    
    BEGIN
    open c1;
    loop
    FETCH C1 INTO EMP_REC;
    EXIT WHEN C1%NOTFOUND;
    
    DBMS_OUTPUT.PUT_LINE('Employee Number '||emp_REC.employee_id);
    
    DBMS_OUTPUT.PUT_LINE('Employee Name '||emp_REC.last_name);
    
    DBMS_OUTPUT.PUT_LINE('JOB '||emp_REC.salary);
    END LOOP;
    END;
    

    Published by: hm on 01.08.2011 00:12

  • function work at the same time that the work can also do procedure...

    pls tel me major diff b/w cursor implicit vs explicit cursor and function procedure vs.

    Published by: 955345 on August 27, 2012 22:11

    Published by: Rousseau on August 28, 2012 11:08

    Rousseau wrote:
    k k bt

    What does that mean?

    function to do some work at the same time that work also can make procedure... Why work

    Function has the ability to be used in SQL, but cannot be a procedure.

    Basically, I use the procedure for transactional operation and function for Non-transactional operation. For example, if I have to update a table I would use a procedure to wrap my update statement. And if I have to do some calculations or run some select and return a result of Ref Cursor I would use a function.

    In addition to the technical restrictions of function and procedure its more the choices make us.

  • EA4500 Router FTP Server Security

    I have a general question around the FTP server on the EA4500, is it safe? I don't see any option to use TLS or SSL, or specify only implicit/explicit connections. Is it safe to use the FTP server to the external? Any help appreciated.

    Xuggs,

    When you access your USB remotely through FTP, you send your username and password without encryption. In addition, the files you download and download are transported over the internet without encryption.

    So no, he's not sure. There is risk. How much a risk? I do not know. Obviously, you don't want to keep sensitive information on your USB key and expose it to potential FTP snooping.

    Some people might consider the photos of family on vacation to Hawaii sensitive, while others care.

    The chances of Linksys update firmware to secure FTP support? You have a better chance of winning this Saturday Powerball lottery drawing.

  • Premiere Pro - media will not import correctly

    All of a sudden the video footage that I import to first does not read in the source viewer. In the same statement with the question, I used several video clips of the unit itself. What is going on?!? Totally frustrated

    Post edited by: Kevin Monahan

    Reason: implicit explicit language in the title

    My problem has been resolved following a call to adobe support. It turns out that the cadence is a problem on some of my video clips. Thank you very much for the help.

  • Stored - procedures to obtain column information

    Hello

    Recently, I changed to unmanaged code ODP ODP managed (I use Entity Framework).

    Unmanaged pilots worked very well after adding the necessary information in the section of web.config. I could add stored procedures and generate complex types using Import - to obtain column information.

    After the switch, the configuration section has been updated and everything seemed to work. By the way changes in the format of the configuration section is little documented - to say the least.

    However when I try to generate complex types again, I just get a "System.notSupportedException' (Message: the specified type is not supported by this selector).

    This feature was not worn supported by drivers? Is there something that can be done to enable this feature?

    The Ref Cursor implicit config file format differs between managed and managed ODP.NET ODP.NET.

    To save you from pulling your hair, do the following.

    (1) install ODT 12.1 if you have not already

    (2) find the procedure stored in the Server Explorer, right click and run and enter the input parameters.

    (3) for the output ref cursor that represents the return value for the function of your entity, choose 'Add to the Config' check box.

    (4) and select either "Show Config" (and then cut and paste) or "add to configuration".

    Here is a screenshot of what I'm talking about:

    http://i.imgur.com/t1BfmUP.gif

  • Adding records int BLOCK in a loop

    Hi all

    I have problems in the following ways:

    When I press a button, I request a cursor that returns several records, according to certain values on this record that I have to add, or not a block.

    Somoeone please tell me how to do, I do:

    GO_BLOCK ('BLOCK');
    FOR reg cursor
    LOOP
    ..
    ..
    If s = reg.value"then
    create_record;
    : BLOCK. VALUE = S ';
    end if;
    ..
    ..
    END OF LOOP
    close the cursor;
    Exception
    while others
    close the cursor;


    THX in advance!

    The problem that I feel is the FRM-40102.

    The "FRM 40102 Records must be inserted or deleted everything first" error implies that you already have a line/record of "New" in your form so that when you call the CREATE_RECORD integrated forms you said that you have not met the minimum values required for the current 'new' recording you can not create a new.

    Frm40735 suggests (good choice of name, incidentally), rather than using the Create_Record, I would recommend that you check if the line the cursor is a new record before attempting to create a new record. Your code should look like this:

    GO_BLOCK('BLOCK');
      FOR reg in cursor
        LOOP
        ..
        ..
        if reg.value = 'S' then
          If (:system.record_status != 'NEW') THEN
            create_record;
          END IF;
        :BLOCK.VALUE = 'S';
        end if;
        ..
        ..
      END LOOP
      close cursor;
    Exception
      when others
        close cursor;
    

    Hope this helps,
    Craig B-)

    If someone useful or appropriate, please mark accordingly.

  • Which of the three sliders to use?

    AFAIK in PL/SQL, there are three ways to define a cursor:
    1. explicit (with open, fetch and close)
    2. with FOR clause
    3. with FOR clause (using subqueries)
    If there is no particular reasons for the use of one, you have some advice for me to use one over the other (run time, space in the memory,...) or that you usually use all these?
    Thank you!

    I can highly recommend studied (as opposed to just reading) this article written by Bryn Llewellyn (the guy who ' owns ' inside the Oracle PL/SQL):

    http://www.Oracle.com/technology/tech/pl_sql/PDF/doing_sql_from_plsql.PDF

    "Do SQL in PL/SQL.

  • AS 3.0: Loading dynamically Library symbols...

    Hello, everyone
    So I spent the whole day looking for a solution, but unfortunately, might find something relevant. Here's the brief description:
    There are several sequences filmed, which are exported to "export for Actionscript". Each clip has a unique name, but a naming model is followed, i.e.:
    clip0: inst_0
    clip1: inst_1
    ...
    Now, the idea initially was to imitate the AS2 'identifier capacity' in AS3, as he is mentioned in a number of sources that I could find on this issue.
    Basically, I wanted the script to shoot random video clips by using their unique class as the reference name. Here's the script:

    var rand: Number = Math.floor (Math.random () * 10) % n_instances; random number
    Inst var = "inst_" + rand;
    var instance = new inst();

    No matter how hard I tried, I was not able to make Flash perform "inst" as the name of a class, not a string. A constraint implicit/explicit (or whatever it's called), variable declaration - nothing works. My only hope was the "eval" function, but that one got obsolete and has no equivalent. So, the question is that "the names of the classes initialized are known", but no matter which - they can't be called using a kind of function, that uses a certain diet to reference the names.

    So is - that someone has stumbled upon such a problem? (I'm not the only dumb@ss with AS3 difficulties?)

    Thank you, Craig

Maybe you are looking for