PL/SQL cursors vs. SQL*plus Select statement

Hi folks, hope you're doing well,
Here is a question that kept me wondering:
Why would I use cursors when i can achieve the same thing with a SQL+ Select statement which is much easier to formulate than a cursor (e.g. you need no declaration, loops etc)?.
Thanks so much,
-a

There is no such thing as a SQL*Plus SELECT statement. The SELECT command is part of the SQL Language - not part of the SQL*Plus (very limited small vocabulary) macro language.
All SQL SELECTs (from client languages) winds up in the SQL Engine as SQL cursors. A SQL Cursor is basically the:
- SQL source code
- SQL "compiled" code (instructions on how to fetch the rows)
On the client side, client cursors (not to be confused with SQL cursors) are used. A client cursor is created in the client language when it makes SQL calls via the database client driver (called the OCI/Oracle Call Interface for Oracle clients).
Typically this is what a client does. It makes a connection to the database and gets a database handler in return. The database handler is the "communication channel" from the client to the db. In Oracle, the database handler in the client refers to the Oracle session (for that client) on db server.
A SQL statement (source code) is used by the client. This can be a SELECT statement you type in at the SQL*Plus command line. It can be a SELECT statement for the PL/SQL cursor command in a stored procedure.
The client creates a SQL handle for this SQL statement, by calling the Oracle client driver. Note that this SQL handle is a client handle - a client cursor for that SQL statement.
E.g.
a) sqlHandle = CreateSQL( databaseHandle, 'SELECT ... FROM ...')
b) sqlHandle.Parse
c) sqlHandle.Execute
After the SQL handle (client cursor) has been executed, the client can fetch rows from it.
This is what SQL*Plus does automatically for you, without you having to write the code to do it. SQL*Plus CONNECT command create a database connection handle. You enter a SELECT statement and SQL*Plus creates a SQL handle (client cursor), executes it, fetches from it, displays the rows, and closes the SQL handle when done.
The same applies to PL/SQL. You can use a SELECT statement just like that in PL/SQL. E.g.
declare
  i integer;
begin
  select count(*) into i from emp where deptid = 123;
end;This is called an implicit cursor. PL/SQL creates (just like SQL*Plus) an implicit client cursor. It creates and disposes of that client SQL handle for you - you do not need to do it.
Or, you can create an explicit cursor. E.g. declare
  cursor c is select count(*) from emp where deptid = 123;
  i integer;
begin
  open c;
  fetch c into i;
  close c;
end;The question as to when to use implicit (client) cursors versus explicit (client) cursors depends on your requirements. Do you need to cycle through the results of the SQL? Etc.
And keep in mind that in either case, the SQL Engine creates a SQL cursor anyway on its side.

Similar Messages

  • Execute an sql command other than an select statement

    hello,
    is it possible to execute an sql-command other than a
    select statement in a report ?
    something like execute ... ?
    i want ro execute a statement BEFORE the select ...
    or is the one and only possible statement in a report
    a "select ?"
    greetings
    Thorsten Lorenz

    Hi ,
    You can always use the Report triggers to execute any other SQL commands . If you need to execute them before the SELECT statement of you Data Model query , then You can use the Parameter Form triggers / before Report Trigger. Be sure to put in a commit statement as well, if the result of the Select statement you intend to do depends on these SQL commands.
    Thanks
    Oracle Reports Team.

  • How to create a cursor on a union select statement?

    Hi,
    Using Oracle 10g RAC +ASM ( RELEASE 1002000300)
    What are is the proper way to create a cursor on a union select statement?
    Is it possible?
    code lines, Results in PLS-00201 error: sT := crsR.STATUS; sS := crsR.TIME;
    Procedure listed below:
    CREATE OR REPLACE PROCEDURE BUILD_SUMMARY IS
    CURSOR csrO IS
    SELECT
    STATUS,
    TIME
    FROM (
    SELECT
    SUBSTR(DESCRIPTION,1,50) STATUS,
    TO_CHAR(TIMESTAMP,'MM/DD/YY hh12:mi:ss') TIME
    FROM GLOBALSALES.CUBE_STATUS
    UNION ALL
    SELECT
    ' TOTAL BUILD TIME',
    TO_CHAR(TO_DATE('00:00:00','HH24:MI:SS') +(MAX(TIMESTAMP) - MIN(TIMESTAMP)), 'HH24:MI:SS')
    FROM GLOBALSALES.CUBE_STATUS);
    csrR csrO%ROWTYPE;
    sT LONG :='';
    sS LONG :='';
    BEGIN
    FOR csrR IN csrO
    LOOP
    sT := crsR.STATUS;
    sS := crsR.TIME;
    DBMS_OUTPUT.PUT_LINE(sT || ' ' || sS);
    END LOOP;
    END;
    /

    csrR csrO%ROWTYPE;
    Declares the csrR correct? Cursor Record of Cursor Object Type?That line declares one variable CSRR with your column structure described by the cursor (CSRO) type you declared above it. It means the CSRR variable has the columns you had in the SELECT statement in that cursor.
    When you run a cursor as you did you don't need to declare the record variable. Try this:
    CREATE OR REPLACE PROCEDURE build_summary IS
      CURSOR csro IS
        SELECT status, TIME
          FROM (SELECT substr(description, 1, 50) status, to_char(TIMESTAMP, 'MM/DD/YY hh12:mi:ss') TIME
                  FROM globalsales.cube_status
                UNION ALL
                SELECT ' TOTAL BUILD TIME',
                       to_char(to_date('00:00:00', 'HH24:MI:SS') + (MAX(TIMESTAMP) - MIN(TIMESTAMP)),
                               'HH24:MI:SS')
                  FROM globalsales.cube_status);
      --csrr csro%ROWTYPE;
      st   LONG := '';
      ss   LONG := '';
    BEGIN
      FOR csrr IN csro
      LOOP
        st := csrr.status;
        ss := csrr.time;
        dbms_output.put_line(st || ' ' || ss);
      END LOOP;
    END;Also why are you using LONG? It's a deprecated data type and Oracle recommends against using it. Either pick varchar2(4000) or CLOB.
    DBMS_OUTPUT.PUT_LINE will implicitly convert that LONG data type anyway.

  • Mappings code generation : regular SQL / cursor PL/SQL

    Hi,
    When designing mappings, I fear that code generation can be potentially dangerous, because OWB automatically chooses the best method to generate the code (regular SQL or PL/SQL).
    I am looking for some examples where code generation for a mapping:
    - gives a regular SQL statement
    - gives a cursor-based PL/SQL
    - a small change in a mapping makes a regular SQL mapping to be transformed in a cursor-based PL/SQL
    Thank you
    Alexandre
    Message was edited by:
    Alexandre Abric

    I have not said that different modes executes at the same way – what the use to have different options if they actually mean the same, right? I have said that they produced the same result i.e. if you expect the mapping to insert 1000 rows from the source to the target – it will be done no matter which operation mode you choose.
    But by different ways. To keep it simple lets say that:
    set base mode will result in:
    insert into target (…)
    select … from source;
    row based will result in:
    begin
    for a in (select * from source) loop
    insert … into target
    end loop;
    end;
    Now lets assume that 5 rows from those 1000 you are going to insert, will break some NOT NULL constraint at the target.
    If you choose Set-base mode entire insert from select will fail resulting no rows is inserted into target. Audit trail will contain message like “constraint … violated” and that’s it. You will have to find bad records by yourself.
    If you choose Row-base mode – 995 rows will be inserted (depending on mapping configuration) into the target and 5 will be listed in audit trail with the same “ constraint violated” message.
    That’s why default operating mode is “Set based fail over to Row based”. That means OWB will try to execute mapping in the fastest way – set based, but if it fail, it will try again to accomplish the task by running in row base mode, providing complete audit trail fro bad rows.

  • Cursor - Suggestions for Dynamic select statements

    Hey,
    Am trying to define a cursor like this -
    cursor c1 is
    select table_name from dba_tables INTERSECT select table_name from dba_tables@SOME_DBLINKMy need is to pass this dblink as IN parameter to the procedure and use it in the select statement for cursor. How can I do this?
    Any suggestion is highly appreciated. Thanks!

    Well that was meant to be my point. If you had two, you wouldn't (I hope) call the second one "c2" - you would be forced to think about what it represented, and name it "c_order_history" or something. Sticking "1" on the end does not make an extensible naming convention for cursors any more than it does for variables, procedures, tables or anything else, and so the "1" in "c1" is redundant because there will never be a c2.

  • Pl/sql function body returning SQL query - if with in select statement

    hello all,
    I have a condition where when summary field is checked alone we have show that column for the users in the report. Is IF statement possible for this case ? I have given the code below.. is it possible to write something like below or is there any other way to do it ?
    v_sql := 'select TBLCASES.INVESTIGATOR as INVESTIGATOR,';
    v_sql := v_sql ||' TBLCASES.CASENUMBER as CASENUMBER,';
    v_sql := v_sql ||' TBLCASES.OPENDATE as OPENDATE,';
    v_sql := v_sql ||' TBLCASES.ESTCOMPLETE as TARGETDATE,';
    v_sql := v_sql ||' TBLCASES.STATUS as STATUS,';
    v_sql := v_sql ||' TBLCASES.CASECODE as CASECODE,';
    v_sql := V_sql ||' TBLCASES.FAIR_HOTLINE as FAIRHotline,';
    v_sql := v_sql ||' TBLCASES.NYSIG as NYSIGCase,';
    v_sql := v_sql ||' TBLCASES.REGION as Region,';
    IF :P44_INCLUDE_SUMMARY_FIELD is not null THEN
    v_sql := v_sql||' TBLCASES.SUMMARY as SUMMARY,';
    END IF ;
    v_sql := v_sql ||' TBLCASES.PROGAREA as PROGArea ';
    v_sql := v_sql ||' from TBLCASES where 1=1';
    ..\

    Hi Lucy,
    You are adding and removing a column from a report so it may help to have the extra on the end of the query.
    Do you get an error? If so paste it in...
    BUT - this I would put a condition on the column where ':P44_INCLUDE_SUMMARY_FIELD is not null '
    Under he report's "Column Attributes" Select the column edit icon and it has a "Condition" breadcrumb.
    Select "Value of Item in Expression 1 is Not Null" and put P44_INCLUDE_SUMMARY_FIELD in Expression 1 text area.
    And I make it more readable like this when I do dynamic SQL:
    IF :P44_INCLUDE_SUMMARY_FIELD is not null THEN
    v_INCLUDE_SUMMARY_FIELD := ' TBLCASES.SUMMARY as SUMMARY ';
    END IF ;
    v_sql := 'select TBLCASES.INVESTIGATOR as INVESTIGATOR,
    TBLCASES.CASENUMBER as CASENUMBER,
    TBLCASES.OPENDATE as OPENDATE,
    TBLCASES.ESTCOMPLETE as TARGETDATE,
    TBLCASES.STATUS as STATUS,
    TBLCASES.CASECODE as CASECODE,
    TBLCASES.FAIR_HOTLINE as FAIRHotline,
    TBLCASES.NYSIG as NYSIGCase,
    TBLCASES.REGION as Region,
    TBLCASES.PROGAREA as PROGArea,'||
    v_INCLUDE_SUMMARY_FIELD ||
    'from TBLCASES where 1=1; ';
    Hope it helps,
    BC

  • SQL- 2005 : User Input in select statement's where cond [Input Parameter]

    Hi All
    i am using SQL Server 2005 , i want to select the data based on the user input in where condition,
    but i am not sure what to give in where condition,can anyone have any idea on this
    SELECT [NO]
          ,[NAME]
          ,[PAGE_COUNT]
      FROM [DS].[DB].[tablename]
    where [NO]=???
    Regards
    Chaitanya.A

    HI
    public String getEmployeeName(String employeeNumber)
              // TODO : Implement
              String name = new String();
              String exception = new String();
              try
              InitialContext initialContext = new InitialContext();
              DataSource dataSource =(DataSource) initialContext.lookup("jdbc/XXXX");
              java.sql.Connection connection = dataSource.getConnection();
              PreparedStatement stmt =connection.prepareStatement("SELECT [NAME]FROM [XXX].[ASDF].[ABCD] where [NO]=?");
              stmt.setString(1,employeeNumber);
              ResultSet result = stmt.executeQuery();
              while (result.next())
                   name = result.getString("Name");
                   connection.close();
                   return name;
              catch (Exception e)
                   exception = "Exception";
                   return exception;
    i used the above function to achieve my requirement
    Thanks
    Chaitanya.A

  • In Oracle SQL, cannot use column in select statement and order by

    Hi,
    Is there a work around for this.
    Thanks in advance
    Pablo.

    Hi,
    943981 wrote:
    Hi All,
    This is the error I get:
    ORA-00960: ambiguous column naming in select list
    00960. 00000 - "ambiguous column naming in select list"
    *Cause:    A column name in the order-by list matches more than one select
    list columns.
    *Action:   Remove duplicate column naming in select list.
    Error at Line: 6 Column: 17That error message looks pretty clear to me. What don't you understand?
    Either
    (a) use aliases, so each column has a unique name, or
    (b) remove duplicate columns from the SELECT clause.
    Post your query. It's hard to say exactly what you're doing wrong when we don't know exactly what you're doing.
    For best results, post a complete test script (including CREATE TABLE and INSERT statements, if necessary) that people can to re-create the problem and test their ideas.
    See the forum FAQ {message:id=9360002}

  • XSQL bug  when using CURSOR in xsql:query SELECT statement?

    Hi there,
    When I tested with different XSQL pages, I found out that if I
    did not involve any XSQL pages that contain "CURSOR", I received
    data correctly and when I shut down Tomcat, Oracle DB server did
    NOT create any dump file (???). However, as long as I involve a
    XSQL page which contains "CURSOR", even I received data
    correctly, but when I shut down my Tomcat, Oracle DB server
    created a dump file (???).
    for example, if I involve xsql:query like:
    <xsql:query>
    SELECT emp_name,
    emp_id
    CURSOR( SELECT emp_address
    from address a
    where a.emp_id = b.emp_id)
    FROM employee b
    </xsql:query>
    Once, I involve this xsql page, when I shut down Tomcat, Oracle
    dB will create a dump file on the server.
    Even when I run this xsql page from
    oracle.xml.xsqlXSQLCommandLine, Oracle dB server still create a
    dump file on the server.
    Any idea for help ?
    Thanks,

    Hi,
    Is this what you are trying:
        try {
        Statement *stmt = conn->createStatement("SELECT ename AS aaaaaaaaaaaaaaa  FROM emp");
          ResultSet *rs = stmt->executeQuery ();
          vector<MetaData> md = rs->getColumnListMetaData ();
          int numCols = md.size ();
          cout<< "Number of columns :" << numCols << endl;
          string *colName = new string [numCols];
          int type = (int ) malloc (numCols);
          for (int i = 0; i < numCols; i++ ) {
            int ptype = md [ i ].getInt (MetaData::ATTR_PTYPE);
            if ( ptype == MetaData::PTYPE_COL ) {
              colName[ i ] = md[ i ].getString (MetaData::ATTR_NAME);
              cout<<"Column Name :" << colName[ i ] << endl;
          delete[] colName;
          stmt->closeResultSet (rs);
          conn->terminateStatement (stmt);
        catch (SQLException &ex) {
                    cout<<ex.getMessage()<<endl;
        }The above snippet works correctly for me.
    Rgds.
    Amogh

  • Need to wite pl sql procedure for dynamic select statement

    Need pl sql procedure for a Dynamic select statement which will drop tables older than 45 days
    select 'Drop table'||' ' ||STG_TBL_NAME||'_DTL_STG;' from IG_SESSION_LOG where substr(DTTM_STAMP, 1, 9) < current_date - 45 and INTF_STATUS=0 order by DTTM_STAMP desc;

    I used this to subtract any data older than 2 years, adjustments can be made so that it fits for forty five days, you can see how I changed it from the originaln dd-mon-yyyy to a "monyy", this way it doesn't become confused with the Static data in the in Oracle, and call back to the previous year when unnecessary:
    TO_NUMBER(TO_CHAR(A.MV_DATE,'YYMM')) >= TO_NUMBER(TO_CHAR(SYSDATE - 365, 'YYMM'))

  • Use of cursors insted of select statements

    could any one please explain what is the advantage of using cursors instead of simple select statements
    thanks
    siby

    A benefit to using an explicit cursor rather than a select statement, is for the NO_DATA_FOUND exception. Its kind of like a free IF statment. IF no data is found, then stop.
    if you write a select statement, and no data is returned, you SHOULD code for the NO_DATA_FOUND exception. Often people say, "i'll ALWAYS get a row returned". but you should always cover your code "just in case". so you must code an exception...
    declare
    v_var varchar2(1);
    procedure do_something(p_parm varchar2) is
    begin
    null;
    end do_something;
    procedure log_error is
    begin
    null;
    end log_error;
    begin <<main>>
    do_something('x');
    begin <<selectblock>>
    select dummy
    into v_var
    from dual
    where dummy = 'a';
    do_something(v_var);
    exception
    when no_data_found then
    log_error;
    end selectblock;
    do_something (v_var||'abc');
    end main;
    if you use an explicit cursor instead, you don't need to code for the NO_DATA_FOUND. If an explicit cursor opens and finds no rows, there are simply no rows. of course, you don't need a loop if you expect only 1 row returned under normal circumstances.
    BTW, don' forget that SQL%ROWCOUNT and your_cursor%ROWCOUNT are not initialized. There is a null, until a row is successfully fetched. therefore if no rows are returned at all, %ROWCOUNT is NULL.
    declare
    v_var varchar2(1);
    cursor my_cur is
    select dummy
    from dual
    where dummy = 'a';
    procedure do_something(p_parm varchar2) is
    begin
    null;
    end do_something;
    procedure log_error is
    begin
    null;
    end log_error;
    begin << main>>
    for cur_rec in my_cur loop
    dbms_output.put_line('inside');
    begin <<loop_block>>
    if nvl(my_cur%rowcount,0) > 1 then
    do_something(cur_rec.dummy);
    else
    log_error;
    end if;
    end loop_block;
    end loop;
    end main;
    /

  • PL/SQL Cursor Help

    I am trying to figure out how to get the following code to work.
    I am using a cursor to run a SELECT statement with a group function. How do I get the information from the group function to print out with a dbms_output.put_line statement? Just for my knowledge, is there some way to reference the next/previous cursor field as part of the wf_country_spoken_rec variable?
    DECLARE
    CURSOR wf_country_spoken_cur IS SELECT c.country_name, COUNT(s.language_id)
    FROM wf_countries c, wf_spoken_languages s
    WHERE c.country_id = s.country_id
    GROUP BY country_name
    HAVING COUNT(s.language_id) > 6;
    wf_rowcount INTEGER;
    BEGIN
    FOR wf_country_spoken_rec IN wf_country_spoken_cur
    LOOP
    DBMS_OUTPUT.PUT_LINE(wf_country_spoken_rec.country_name || ' ' || wf_country_spoken_rec.language_id);
    wf_rowcount := wf_country_spoken_cur%ROWCOUNT;
    END LOOP;
    DBMS_OUTPUT.PUT_LINE(wf_rowcount);
    END;
    Thanks,
    John

    The only problem I think your code has is how it's referencing the language_id. If it suppose to print out the count of language_ids then you just need to add an alias to it. just like this:
    DECLARE
        CURSOR wf_country_spoken_cur IS
            SELECT c.country_name,
                   COUNT(s.language_id) language_id_cnt
              FROM wf_countries c,
                   wf_spoken_languages s
             WHERE c.country_id = s.country_id
             GROUP BY country_name
            HAVING COUNT(s.language_id) > 6;
        wf_rowcount INTEGER;
    BEGIN
        FOR wf_country_spoken_rec IN wf_country_spoken_cur
        LOOP
            DBMS_OUTPUT.PUT_LINE(wf_country_spoken_rec.country_name || ' ' || wf_country_spoken_rec.language_id_cnt);
            wf_rowcount := wf_country_spoken_cur%ROWCOUNT;
        END LOOP;
        DBMS_OUTPUT.PUT_LINE(wf_rowcount);
    END;
    /

  • Usage of cursor in sql select stmt

    HI
    how can i use cursor in SELECT statement for fetching the multiple records at a time.
    thanx.

    Hi,
    do you mean something like this? - hope I've understood correctlry :-)
    Example in Sql*Plus (v 10)
    SCOTT>
    SCOTT>SELECT A.TABLE_NAME,
    2 CURSOR (SELECT B.COLUMN_NAME
    3 FROM ALL_TAB_COLUMNS B
    4 WHERE B.TABLE_NAME = A.TABLE_NAME
    5 ) CURSOR_1
    6 FROM ALL_TABLES A
    7 WHERE A.TABLE_NAME = 'DUAL'
    8 /
    TABLE_NAME CURSOR_1
    DUAL CURSOR STATEMENT : 2
    CURSOR STATEMENT : 2
    COLUMN_NAME
    DUMMY
    1 row selected.
    1 row selected.
    SCOTT>
    SCOTT>
    If you want to user this in PL, you need to declare a cursor and fetch the CURSOR_1 column in a ref cursor
    this is another example :
    procedure Example1 (ppLocId in locations.location_id%type)
    is
    type rcRefCursor is ref cursor;
    cursor cAllInOne is
    select l.city,
    cursor (select d.department_name,
    cursor (select e.last_name
    from employees e
    where e.department_id = d.department_id
    ) eName
    from departments d
    where d.location_id = l.location_id
    ) dName
    from locations l
    where location_id = ppLocId;
    cDepts rcRefCursor;
    cEmployees rcRefCursor;
    vCity locations.city%type;
    vDepartment departments.department_name%type;
    vEmpName employees.last_name%type;
    begin
    open cAllInOne;
    loop
    fetch cAllInOne
    into vCity,
    cDepts;
    exit when cAllInOne%notfound;
    loop
    fetch cDepts
    into vDepartment,
    cEmployees;
    exit when cDepts%notfound;
    loop
    fetch cEmployees
    into vEmpName;
    exit when cEmployees%notfound;
    dbms_output.put_line ('City : ' || vCity ||
    ' Dept : ' || vDepartment ||
    ' Name : ' || vEmpName
    end loop;
    end loop;
    end loop;
    close cAllInOne;
    end Example1;
    bye
    fabio

  • Bind Variable in SELECT statement and get the value  in PL/SQL block

    Hi All,
    I would like  pass bind variable in SELECT statement and get the value of the column in Dynamic SQL
    Please seee below
    I want to get the below value
    Expected result:
    select  distinct empno ,pr.dept   from emp pr, dept ps where   ps.dept like '%IT'  and pr.empno =100
    100, HR
    select  distinct ename ,pr.dept   from emp pr, dept ps where   ps.dept like '%IT'  and pr.empno =100
    TEST, HR
    select  distinct loc ,pr.dept   from emp pr, dept ps where   ps.dept like '%IT'  and pr.empno =100
    NYC, HR
    Using the below block I am getting column names only not the value of the column. I need to pass that value(TEST,NYC..) into l_col_val variable
    Please suggest
    ----- TABLE LIST
    CREATE TABLE EMP(
    EMPNO NUMBER,
    ENAME VARCHAR2(255),
    DEPT VARCHAR2(255),
    LOC    VARCHAR2(255)
    INSERT INTO EMP (EMPNO,ENAME,DEPT,LOC) VALUES (100,'TEST','HR','NYC');
    INSERT INTO EMP (EMPNO,ENAME,DEPT,LOC) VALUES (200,'TEST1','IT','NYC');
    INSERT INTO EMP (EMPNO,ENAME,DEPT,LOC) VALUES (300,'TEST2','MR','NYC');
    INSERT INTO EMP (EMPNO,ENAME,DEPT,LOC) VALUES (400,'TEST3','HR','DTR');
    INSERT INTO EMP (EMPNO,ENAME,DEPT,LOC) VALUES (500,'TEST4','HR','DAL');
    INSERT INTO EMP (EMPNO,ENAME,DEPT,LOC) VALUES (600,'TEST5','IT','ATL');
    INSERT INTO EMP (EMPNO,ENAME,DEPT,LOC) VALUES (700,'TEST6','IT','BOS');
    INSERT INTO EMP (EMPNO,ENAME,DEPT,LOC) VALUES (800,'TEST7','HR','NYC');
    COMMIT;
    CREATE TABLE COLUMNAMES(
    COLUMNAME VARCHAR2(255)
    INSERT INTO COLUMNAMES(COLUMNAME) VALUES ('EMPNO');
    INSERT INTO COLUMNAMES(COLUMNAME) VALUES ('ENAME');
    INSERT INTO COLUMNAMES(COLUMNAME) VALUES ('DEPT');
    INSERT INTO COLUMNAMES(COLUMNAME) VALUES ('LOC');
    COMMIT;
    CREATE TABLE DEPT(
    DEPT VARCHAR2(255),
    DNAME VARCHAR2(255)
    INSERT INTO DEPT(DEPT,DNAME) VALUES ('IT','INFORMATION TECH');
    INSERT INTO DEPT(DEPT,DNAME) VALUES ('HR','HUMAN RESOURCE');
    INSERT INTO DEPT(DEPT,DNAME) VALUES ('MR','MARKETING');
    INSERT INTO DEPT(DEPT,DNAME) VALUES ('IT','INFORMATION TECH');
    COMMIT;
    PL/SQL BLOCK
    DECLARE
      TYPE EMPCurTyp  IS REF CURSOR;
      v_EMP_cursor    EMPCurTyp;
      l_col_val           EMP.ENAME%type;
      l_ENAME_val       EMP.ENAME%type;
    l_col_ddl varchar2(4000);
    l_col_name varchar2(60);
    l_tab_name varchar2(60);
    l_empno number ;
    b_l_col_name VARCHAR2(255);
    b_l_empno NUMBER;
    begin
    for rec00 in (
    select EMPNO aa from  EMP
    loop
    l_empno := rec00.aa;
    for rec in (select COLUMNAME as column_name  from  columnames
    loop
    l_col_name := rec.column_name;
    begin
      l_col_val :=null;
       l_col_ddl := 'select  distinct :b_l_col_name ,pr.dept ' ||'  from emp pr, dept ps where   ps.dept like ''%IT'' '||' and pr.empno =:b_l_empno';
       dbms_output.put_line('DDL ...'||l_col_ddl);
       OPEN v_EMP_cursor FOR l_col_ddl USING l_col_name, l_empno;
    LOOP
        l_col_val :=null;
        FETCH v_EMP_cursor INTO l_col_val,l_ename_val;
        EXIT WHEN v_EMP_cursor%NOTFOUND;
          dbms_output.put_line('l_col_name='||l_col_name ||'  empno ='||l_empno);
       END LOOP;
    CLOSE v_EMP_cursor;
    END;
    END LOOP;
    END LOOP;
    END;

    user1758353 wrote:
    Thanks Billy, Would you be able to suggest any other faster method to load the data into table. Thanks,
    As Mark responded - it all depends on the actual data to load, structure and source/origin. On my busiest database, I am loading on average 30,000 rows every second from data in external files.
    However, the data structures are just that - structured. Logical.
    Having a data structure with 100's of fields (columns in a SQL table), raise all kinds of questions about how sane that structure is, and what impact it will have on a physical data model implementation.
    There is a gross misunderstanding by many when it comes to performance and scalability. The prime factor that determines performance is not how well you code, what tools/language you use, the h/w your c ode runs on, or anything like that. The prime factor that determines perform is the design of the data model - as it determines the complexity/ease to use the data model, and the amount of I/O (the slowest of all db operations) needed to effectively use the data model.

  • PL/SQL Function in Select statement

    Hi
    I am calling a function in select statement. The query works in Toad and PL/SQL developer except SQL plus and disconnecting Oracle connection.
    The error is “ERROR at line 1: ORA-03113: end-of-file on communication channel”.
    When I called the same query from BC4J View Object the error message is “java.sql.SQLException: No more data to read from socket”.
    Can any one advise me please?
    Thanks
    Srini

    Srini
    I've seen similar cases in the past with 9.2.0.x (x <= 5). What Oracle version are you using? It's worth checking the bug database (I can't just now - I don't have a valid support id in my current contract). And as Warren says, post your SQL query.
    HTH
    Regards nigel

Maybe you are looking for

  • Error while creating Vacancy requisition object (NB) after upgrading EHP4

    Hi All, We had alreay E-Rec system with EHP2 and using last 1 year. Now based on Client requirement, we have upgrdaed to EHP4. After completing EHP4 upgradation, we are getting error while creating vacancy requisition object after all level of approv

  • Query Jump problem

    Hello, I have query jump from Q1 to Q2. The result in the Q1 is in EUR. when I jump from Q1 to Q2 it is automatically filling Currency filled with USD and key figures are showing NOT APPLICABLE DATA. Once you remove the Currenyc USD then it is showin

  • IE 7 Active X problem

    Hi, Any news from Macromedia as far as if they will add a patch to DW8 to display flash without having to add code ourselves ? Also does anyone knows how much time we have left before IE7 is released ? Alejandro

  • Sox 10.8.1 is driving me nuts

    10.8.1 deleted all most half of my apps? not to mention that now I cant access the App store now?

  • Configure dhcp on Mac OS 9

    How do I configure a dhcp connection on Mac OS 9.2.2