Display output of ref cursor in sql developer

Hi,
I am writing following procedure.
create or replace
procedure test_output(
arg_like in varchar2,
cv_results in out sys_refcursor)
is
Type sys_refcursor is ref cursor;
begin
open cv_results for
select * from claim_status where status_id like 'arg_like%';
end;
I would like to check the output by running the procedure in sql developer.

Boneist wrote:
What, not even if you run it as a script?
This is in the [SQL Developer Documentation|http://download.oracle.com/docs/cd/E12151_01/doc.150/e12152/intro.htm#CHDJBBIH] :
1.7.1 SQL*Plus Statements Supported and Not Supported in SQL WorksheetThe SQL Worksheet supports some SQL*Plus statements. SQL*Plus statements must be interpreted by the SQL Worksheet before being passed to the database; any SQL*Plus that are not supported by the SQL Worksheet are ignored and not passed to the database.
The following SQL*Plus statements are not supported by the SQL Worksheet:
a[ppend]
archive
attr[ibute]
bre[ak]
bti[tle]
c[hange]
col[ulmn]
comp[ute]
copy
del
disc[onnect]
ed[it]
get
help
i[nput]
l[ist]
newpage
oradebug
passw[ord]
print
r[un]
recover
repf[ooter]
reph[eader]
sav[e]
sho[w]
shu[tdown]
spo[ol]
startup
store
tti[tle]
*var[iable]*

Similar Messages

  • Procedure output like a query in SQL developer?

    Hi!
    How can a PL procedure create output like a query in SQL developer?
    This block
    begin
    for record in (
    select * from my_db
    loop
    dbms_output.put_line(record.name ' ' || record.address)
    end loop;
    end;
    would print a of names and adresses in my_db. However, output sent to a query result window which would be the result of
    select name,address from my_db;
    How could I make the PL block behave the same way as the SQL query, i.e. present its output in a query result window?

    Welcome to the forum!
    Please provide your 4 digit Oracle version (result of SELECT * FROM V$VERSION) wheneve you ask a question.
    Do you mean query a procedure as if it were a table?
    You can do that with a pipelined function. Here is sample code you can test using the SCOTT schema
    -- type to match emp record
    create or replace type emp_scalar_type as object
      (EMPNO NUMBER(4) ,
       ENAME VARCHAR2(10),
       JOB VARCHAR2(9),
       MGR NUMBER(4),
       HIREDATE DATE,
       SAL NUMBER(7, 2),
       COMM NUMBER(7, 2),
       DEPTNO NUMBER(2)
    -- table of emp records
    create or replace type emp_table_type as table of emp_scalar_type
    -- pipelined function
    create or replace function get_emp( p_deptno in number )
      return emp_table_type
      PIPELINED
      as
       TYPE EmpCurTyp IS REF CURSOR RETURN emp%ROWTYPE;
        emp_cv EmpCurTyp;
        l_rec  emp%rowtype;
      begin
        open emp_cv for select * from emp where deptno = p_deptno;
        loop
          fetch emp_cv into l_rec;
          exit when (emp_cv%notfound);
          pipe row( emp_scalar_type( l_rec.empno, LOWER(l_rec.ename),
              l_rec.job, l_rec.mgr, l_rec.hiredate, l_rec.sal, l_rec.comm, l_rec.deptno ) );
        end loop;
        return;
      end;
      /Then you can query the function as if it were a table
    select * from table(get_emp(20))Is that what you were looking for?

  • Output of REF CURSOR

    I have a PL/SQL ref cursor, I would like to pass the output from REF CURSOR to a ORACLE table
    The output is Comma separated values of VARCHAR2 datatype
    Pls suggest how to pass this output to a ORACLE table dynamically?
    Thanks
    Edited by: 859486 on Oct 9, 2012 12:18 PM

    859486 wrote:
    I have a PL/SQL ref cursor, I would like to pass the output from REF CURSOR to a ORACLE table
    The output is Comma separated values of VARCHAR2 datatype
    Pls suggest how to pass this output to a ORACLE table dynamically?Why are you using a Ref Cursor? What problem are you trying to solve by using it? A Ref Cursor is usually used to pass an executing query back to a third party application layer, very rarely is is used within PL/SQL itself.
    {thread:id=886365}

  • Security risk of ref cursor & dynamic sql

    Hi guys,
    I am using Ref Cursor to execute a dynamic sql in my stored procedure. Inputs to the dynamic SQL are passed in as parameters. My code fragments:
    parameters:
    CREATE PROCEDURE mm_select(
    aaa     IN VARCHAR2,
    bbb     IN VARCHAR2 )
    in the code:
    sqlstmt := 'SELECT * FROM dbaivoc.mm ' ||
    'WHERE b in (' || role_id_list || ') ' ||
    'AND c = '|| application_fn_id_list ;
    OPEN RC1 FOR sqlstmt;
    My question is, is it possible for anyone to pass in a malicious SQL like drop table xxx into the parameter list eg. exec mm_select(1,'1; drop table aa;')
    I've tried but it doesn't seem to work. I'm just asking for confirmation. Thanks for any help!
    rgds,
    mas

    I don't see in your small pieces of code what the input parameters aaa and bbb are used for.
    If your statement is always
    sqlstmt := 'select ....'
    then I don't see how this can be changed to 'drop table ...'.
    It would be something different if you have something like this in your procedure:
    execute immediate bbb;

  • DBMS output to Ref cursor

    Hi. This is my first time posting here. Here is my question: I am using a non-Oracle reporting tool (WebFOCUS) and I need to access an Oracle stored procedure (ex. EX SQL proc (cursor_variable) ). The Oracle developer I work with tends to use regular cursors to fill variables and then after some conditional logic (IF,THEN,ELSE) write the result set to dbms_output.put_line. My question is how can I return the result set in a cursor variable without having to re-write the procedure?

    Hi Prakash and Aron and thanks for the responses. My question is not regarding the structure of cursor variable. I'm wondering if there is some way to bring back (in a cursor variable) a recordset that is partially a result of a 'standard' cursor and partially filled through an IF statement...without having to re-write the whole procedure. Currently, the procedure is written in a standard OPEN...FOR/LOOP...FETCH INTO configuration which fetches the majority of the desired recordset. The remaining part of the recordset is filled and then outputted through dbms upon succesful passing of conditional IF/THEN logic.
    Here's what I mean:
    create or replace procedure procb is
    CURSOR c1 IS
    SELECT t.work_id, t.wk_last_name, t.wk_first_name
    FROM table t
    WHERE t.name ...
    BEGIN
    OPEN c1;
    dbms_output.enable(1000000);
    LOOP
    FETCH c1
    INTO work_id, wk_last_name, wk_first_name;
    EXIT WHEN c1%NOTFOUND;
    IF wk_sup_name IS NOT NULL
    AND wk_sup_posn IS NOT NULL
    AND wk_sup_suff IS NOT NULL
    THEN
    SELECT c.job_status, c.job_effective_date
    INTO wk_status, wk_eff_dt
    FROM jobtable c
    WHERE ...
    END IF;
    dbms_output.put_line(wk_id || wk_last_name ||wk_first_name ||wk_posn ||wk_status||wk_eff_dt)
    END LOOP;
    CLOSE c1;
    end procb;
    Thanks in advance for your help.
    Anthony

  • Using REF with object table in SQL Developer

    When i create object tables and fill them with data, then in SQL Developer de REF value isn't displayed.
    I did the following:
    CREATE TYPE adres_type AS OBJECT
    (straat VARCHAR2(20)
    ,nummer VARCHAR2(10)
    ,postcode VARCHAR2(6)
    ,plaats VARCHAR2(50));
    CREATE TABLE adressen of adres_type;
    CREATE TYPE locatie_type AS OBJECT
    (nr NUMBER
    ,naam VARCHAR2(20)
    ,adres REF adres_type);
    CREATE TABLE locaties OF locatie_type;
    CREATE TABLE locaties OF locatie_type
    (SCOPE FOR (adres) IS adressen);
    insert into adressen values (adres_type('Arnhemsestraatweg', '33','6881ND','Velp'));
    insert into locaties values (1,'Directie', (select ref (a) from adressen a where a.plaats = 'Velp'))
    Then in SQL Developer de REF(A) column is empty, while in SQL*Plus it displays the REF value:
    In SQL Developer: SELECT a.*, REF(a) FROM adressen a;
    STRAAT NUMMER POSTCODE PLAATS REF(A)
    Arnhemsestraatweg 33 6881ND Velp
    In SQLPLUS: SELECT a.*, REF(a) FROM adressen a;
    STRAAT NUMMER POSTCODE PLAATS REF(A)
    Arnhemsestraatweg 33 6881ND Velp 0000280209C70341FBB96B4F77813B27B50E53BB4332382E22ADD64AD9B755F651D416B6DA010134
    Is this a bug or is there another reason why the ID doesnt display in SQL Developer.
    (this didnt work in all the previous SQL Developer releases and still not in de 2.1 E.A. version)

    Hi <not sure of your first name>,
    I have replicated the issues and logged a bug against this
    Bug 9102579 - FORUM: REF FUNCTION NOT RETURNING CORRECT RESULT
    Regards,
    Dermot O'Neill
    SQL Developer Team

  • Sql developer UTF-8 display problems

    Hi
    I use a development tool that is supposed to allow utf-8 encoding. If you enter text 'ABCDÉFGH' (É is ctrl alt E) through the software it is written to a VARCHAR2 value. When you look at the value using SQL Developer or (Congnos Impromptu) this value is displayed as ABCDÉFGH.
    Should Sql Developer convert É to É when displaying the value. Or is the problem with the development tool where it is not writing the value to the table correctly.
    linux/unix platform.
    The following NLS_DATABASE_PARAMETERS are.
    PARAMETER VALUE
    NLS_LANGUAGE ENGLISH
    NLS_TERRITORY UNITED KINGDOM
    NLS_CURRENCY #
    NLS_ISO_CURRENCY UNITED KINGDOM
    NLS_NUMERIC_CHARACTERS .,
    NLS_CHARACTERSET AL32UTF8
    NLS_CALENDAR GREGORIAN
    NLS_DATE_FORMAT DD-MON-RR
    NLS_DATE_LANGUAGE ENGLISH
    NLS_SORT BINARY
    NLS_TIME_FORMAT HH24.MI.SSXFF
    NLS_TIMESTAMP_FORMAT DD-MON-RR HH24.MI.SSXFF
    NLS_TIME_TZ_FORMAT HH24.MI.SSXFF TZR
    NLS_TIMESTAMP_TZ_FORMAT DD-MON-RR HH24.MI.SSXFF TZR
    NLS_DUAL_CURRENCY ?
    NLS_COMP BINARY
    NLS_LENGTH_SEMANTICS BYTE
    NLS_NCHAR_CONV_EXCP FALSE
    NLS_NCHAR_CHARACTERSET UTF8
    NLS_RDBMS_VERSION 10.2.0.4.0
    thanks
    andy
    Edited by: user8646247 on 21-Jul-2009 06:39

    There is a forum dedicated to SQL Developer, which is monitored by members of the product dev team. You should consider posting your question there. [Link to forum|http://forums.oracle.com/forums/forum.jspa?forumID=260].
    Cheers, APC
    blog: http://radiofreetooting.blogspot.com

  • SQL Developer - displaying double byte (Japanese) characters

    I have installed SQL Developer on an English Windows XP system with Asian regional support installed.
    SQL Developer > preferences > database > set language, territory to Japan/Japanese.
    The strings are displaying as square boxes which means the characters are unable to display, I have verified on a Japanese machine that the characters to display with the same version of SQL Developer.
    Any ideas on how to get these characters to display?

    Hi user625396,
    Square boxes mean font not installed, for example on my Linux box for displaying Chinese:
    Chinese characters in linux see http://isis.poly.edu/~qiming/chinese-debian-mini-howto.html basically:
    1. create a jre/lib/fonts/fallback directory if necessary and
    2. copy or link the fonts files into this directory. (On my Linux system: /usr/share/fonts/truetype/arphic/gbsn00lp.ttf )
    3. I will install Japanese when the business need arises.
    Please confirm this fallback directory works for Japanese and Windows XP, with / changed to \ and the path to a Japanese font replacing /usr/share/fonts/truetype/arphic/gbsn00lp.ttf .
    I had a quick look for a windows XP/Japanese/fallback font page but I could not see one.
    -Turloch

  • Ref Cursors / throwing data into a Ref Cursor as data is fetched

    I was wondering if anyone has executed an SQL statement and as each row is being fetched back from an SQL, doing some data checks and processing to see if the row is valid to return or not, based on the values being fetched in an SQL.
    For example, I'm taking an SQL statement and trying to do some tuning. I have an Exists clause in the Where statement that has a nested sub-query with some parameters passed in. I am attempting to move that statement to a function call in a package (which is called in the SELECT statement). As I fetch each row back, I want to check some values that are Selected and if the values are met, then, I want to execute the function to see if the data exists. If it does exist, then, I want the fetched row returned in the Ref Cursor. If the criteria is met and the row doesn't exist in the function call, then, I don't want the fetched row to return.
    Right now, the data has to be thrown to REF Cursor because it's being outputted to the Java application as a Result Set.
    I've found many statements where you can take a SELECT statement and throw the Results in the Ref Cursor. But, I want to go a step further and before I throw each row in the Ref Cursor, I want to some processing to see if I put the Fetched Row in the Ref Cursor.
    If someone has a better idea to accomplish this, I'm all ears. Like I say, I'm doing this method only for the sake of doing some database tuning and I think this will speed things up. Having the EXISTS clause works and it runs fast from an End-user standpoint but, when it processes on the database with the nested subquery, it is slow.
    Here's an example of something that might be a problem (Notice the nested subquery). I moved the nested subquery to a function call written on the database package and make the call to the procedure/package in the SELECT statement. As I process each row, I want to check some values prior having the function call execute. If it meet some criteria, then the record is Ok to fetch and display in the Ref Cursor. If it does not meet the criteria and goes through the function and doesn't return data, then, I don't want the Fetched row from the main query to return the data.:
    SELECT EMPNO,
    FIRST_NAME,
    LAST_NAME
    FROM EMP E,
    DEPT D
    WHERE E.DEPTNO = D.DEPTNO
    AND EXISTS (SELECT 'X'
    FROM MANAGER M
    WHERE M.MANAGER_ID = E.MANAGER_ID
    AND MANAGER_TYPE IN (SELECT MANAGER_TYPE
    FROM MANAGER_LOOKUP ML WHERE ML.MANAGER_TYPE = M.MANAGER_TYPE))
    Any help or ideas of other things to try is appreciated. Keep in mind that I am returning this data to the Java application so, throwing the data to a Ref Cursor in the PL/SQL is the ideal method.
    Chris

    Ref cursors are not required nor desirable when writing java database application. Cursors are mentioned only once in the JDBC documentation reference guide, in the section "Memory Leaks and Running Out of Cursors".
    In a word cursors are just plain ridiculous, and in fact I never used them in my 15+ years of application development practice:
    http://vadimtropashko.wordpress.com/cursors/

  • PL/SQL 101 : Cursors and SQL Projection

    PL/SQL 101 : Cursors and SQL Projection
    This is not a question, it's a forum article, in reponse to the number of questions we get regarding a "dynamic number of columns" or "rows to columns"
    There are two integral parts to an SQL Select statement that relate to what data is selected. One is Projection and the other is Selection:-
    Selection is the one that we always recognise and use as it forms the WHERE clause of the select statement, and hence selects which rows of data are queried.
    The other, SQL Projection is the one that is less understood, and the one that this article will help to explain.
    In short, SQL Projection is the collective name for the columns that are Selected and returned from a query.
    So what? Big deal eh? Why do we need to know this?
    The reason for knowing this is that many people are not aware of when SQL projection comes into play when you issue a select statement. So let's take a basic query...
    First create some test data...
    create table proj_test as
      select 1 as id, 1 as rn, 'Fred' as nm from dual union all
      select 1,2,'Bloggs' from dual union all
      select 2,1,'Scott' from dual union all
      select 2,2,'Smith' from dual union all
      select 3,1,'Jim' from dual union all
      select 3,2,'Jones' from dual
    ... and now query that data...
    SQL> select * from proj_test;
             ID         RN NM
             1          1 Fred
             1          2 Bloggs
             2          1 Scott
             2          2 Smith
             3          1 Jim
             3          2 Jones
    6 rows selected.
    OK, so what is that query actually doing?
    To know that we need to consider that all queries are cursors and all cursors are processed in a set manner, roughly speaking...
    1. The cursor is opened
    2. The query is parsed
    3. The query is described to know the projection (what columns are going to be returned, names, datatypes etc.)
    4. Bind variables are bound in
    5. The query is executed to apply the selection and identify the data to be retrieved
    6. A row of data is fetched
    7. The data values from the columns within that row are extracted into the known projection
    8. Step 6 and 7 are repeated until there is no more data or another condition ceases the fetching
    9. The cursor is closed
    The purpose of the projection being determined is so that the internal processing of the cursor can allocate memory etc. ready to fetch the data into. We won't get to see that memory allocation happening easily, but we can see the same query being executed in these steps if we do it programatically using the dbms_sql package...
    CREATE OR REPLACE PROCEDURE process_cursor (p_query in varchar2) IS
      v_sql       varchar2(32767) := p_query;
      v_cursor    number;            -- A cursor is a handle (numeric identifier) to the query
      col_cnt     integer;
      v_n_val     number;            -- numeric type to fetch data into
      v_v_val     varchar2(20);      -- varchar type to fetch data into
      v_d_val     date;              -- date type to fetch data into
      rec_tab     dbms_sql.desc_tab; -- table structure to hold sql projection info
      dummy       number;
      v_ret       number;            -- number of rows returned
      v_finaltxt  varchar2(100);
      col_num     number;
    BEGIN
      -- 1. Open the cursor
      dbms_output.put_line('1 - Opening Cursor');
      v_cursor := dbms_sql.open_cursor;
      -- 2. Parse the cursor
      dbms_output.put_line('2 - Parsing the query');
      dbms_sql.parse(v_cursor, v_sql, dbms_sql.NATIVE);
      -- 3. Describe the query
      -- Note: The query has been described internally when it was parsed, but we can look at
      --       that description...
      -- Fetch the description into a structure we can read, returning the count of columns that has been projected
      dbms_output.put_line('3 - Describing the query');
      dbms_sql.describe_columns(v_cursor, col_cnt, rec_tab);
      -- Use that description to define local datatypes into which we want to fetch our values
      -- Note: This only defines the types, it doesn't fetch any data and whilst we can also
      --       determine the size of the columns we'll just use some fixed sizes for this example
      dbms_output.put_line(chr(10)||'3a - SQL Projection:-');
      for j in 1..col_cnt
      loop
        v_finaltxt := 'Column Name: '||rpad(upper(rec_tab(j).col_name),30,' ');
        case rec_tab(j).col_type
          -- if the type of column is varchar2, bind that to our varchar2 variable
          when 1 then
            dbms_sql.define_column(v_cursor,j,v_v_val,20);
            v_finaltxt := v_finaltxt||' Datatype: Varchar2';
          -- if the type of the column is number, bind that to our number variable
          when 2 then
            dbms_sql.define_column(v_cursor,j,v_n_val);
            v_finaltxt := v_finaltxt||' Datatype: Number';
          -- if the type of the column is date, bind that to our date variable
          when 12 then
            dbms_sql.define_column(v_cursor,j,v_d_val);
            v_finaltxt := v_finaltxt||' Datatype: Date';
          -- ...Other types can be added as necessary...
        else
          -- All other types we'll assume are varchar2 compatible (implicitly converted)
          dbms_sql.DEFINE_COLUMN(v_cursor,j,v_v_val,2000);
          v_finaltxt := v_finaltxt||' Datatype: Varchar2 (implicit)';
        end case;
        dbms_output.put_line(v_finaltxt);
      end loop;
      -- 4. Bind variables
      dbms_output.put_line(chr(10)||'4 - Binding in values');
      null; -- we have no values to bind in for our test
      -- 5. Execute the query to make it identify the data on the database (Selection)
      -- Note: This doesn't fetch any data, it just identifies what data is required.
      dbms_output.put_line('5 - Executing the query');
      dummy := dbms_sql.execute(v_cursor);
      -- 6.,7.,8. Fetch the rows of data...
      dbms_output.put_line(chr(10)||'6,7 and 8 Fetching Data:-');
      loop
        -- 6. Fetch next row of data
        v_ret := dbms_sql.fetch_rows(v_cursor);
        -- If the fetch returned no row then exit the loop
        exit when v_ret = 0;
        -- 7. Extract the values from the row
        v_finaltxt := null;
        -- loop through each of the Projected columns
        for j in 1..col_cnt
        loop
          case rec_tab(j).col_type
            -- if it's a varchar2 column
            when 1 then
              -- read the value into our varchar2 variable
              dbms_sql.column_value(v_cursor,j,v_v_val);
              v_finaltxt := ltrim(v_finaltxt||','||rpad(v_v_val,20,' '),',');
            -- if it's a number column
            when 2 then
              -- read the value into our number variable
              dbms_sql.column_value(v_cursor,j,v_n_val);
              v_finaltxt := ltrim(v_finaltxt||','||to_char(v_n_val,'fm999999'),',');
            -- if it's a date column
            when 12 then
              -- read the value into our date variable
              dbms_sql.column_value(v_cursor,j,v_d_val);
              v_finaltxt := ltrim(v_finaltxt||','||to_char(v_d_val,'DD/MM/YYYY HH24:MI:SS'),',');
          else
            -- read the value into our varchar2 variable (assumes it can be implicitly converted)
            dbms_sql.column_value(v_cursor,j,v_v_val);
            v_finaltxt := ltrim(v_finaltxt||',"'||rpad(v_v_val,20,' ')||'"',',');
          end case;
        end loop;
        dbms_output.put_line(v_finaltxt);
        -- 8. Loop to fetch next row
      end loop;
      -- 9. Close the cursor
      dbms_output.put_line(chr(10)||'9 - Closing the cursor');
      dbms_sql.close_cursor(v_cursor);
    END;
    SQL> exec process_cursor('select * from proj_test');
    1 - Opening Cursor
    2 - Parsing the query
    3 - Describing the query
    3a - SQL Projection:-
    Column Name: ID                             Datatype: Number
    Column Name: RN                             Datatype: Number
    Column Name: NM                             Datatype: Varchar2
    4 - Binding in values
    5 - Executing the query
    6,7 and 8 Fetching Data:-
    1     ,1     ,Fred
    1     ,2     ,Bloggs
    2     ,1     ,Scott
    2     ,2     ,Smith
    3     ,1     ,Jim
    3     ,2     ,Jones
    1     ,3     ,Freddy
    1     ,4     ,Fud
    9 - Closing the cursor
    PL/SQL procedure successfully completed.
    So, what's really the point in knowing when SQL Projection occurs in a query?
    Well, we get many questions asking "How do I convert rows to columns?" (otherwise known as a pivot) or questions like "How can I get the data back from a dynamic query with different columns?"
    Let's look at a regular pivot. We would normally do something like...
    SQL> select id
      2        ,max(decode(rn,1,nm)) as nm_1
      3        ,max(decode(rn,2,nm)) as nm_2
      4  from proj_test
      5  group by id
      6  /
            ID NM_1   NM_2
             1 Fred   Bloggs
             2 Scott  Smith
             3 Jim    Jones
    (or, in 11g, use the new PIVOT statement)
    but many of these questioners don't understand it when they say their issue is that, they have an unknown number of rows and don't know how many columns it will have, and they are told that you can't do that in a single SQL statement. e.g.
    SQL> insert into proj_test (id, rn, nm) values (1,3,'Freddy');
    1 row created.
    SQL> select id
      2        ,max(decode(rn,1,nm)) as nm_1
      3        ,max(decode(rn,2,nm)) as nm_2
      4  from proj_test
      5  group by id
      6  /
            ID NM_1   NM_2
             1 Fred   Bloggs
             2 Scott  Smith
             3 Jim    Jones
    ... it's not giving us this 3rd entry as a new column and we can only get that by writing the expected columns into the query, but then what if more columns are added after that etc.
    If we look back at the steps of a cursor we see again that the description and projection of what columns are returned by a query happens before any data is fetched back.
    Because of this, it's not possible to have the query return back a number of columns that are based on the data itself, as no data has been fetched at the point the projection is required.
    So, what is the answer to getting an unknown number of columns in the output?
    1) The most obvious answer is, don't use SQL to try and pivot your data. Pivoting of data is more of a reporting requirement and most reporting tools include the ability to pivot data either as part of the initial report generation or on-the-fly at the users request. The main point about using the reporting tools is that they query the data first and then the pivoting is simply a case of manipulating the display of those results, which can be dynamically determined by the reporting tool based on what data there is.
    2) The other answer is to write dynamic SQL. Because you're not going to know the number of columns, this isn't just a simple case of building up a SQL query as a string and passing it to the EXECUTE IMMEDIATE command within PL/SQL, because you won't have a suitable structure to read the results back into as those structures must have a known number of variables for each of the columns at design time, before the data is know. As such, inside PL/SQL code, you would have to use the DBMS_SQL package, just like in the code above that showed the workings of a cursor, as the columns there are referenced by position rather than name, and you have to deal with each column seperately. What you do with each column is up to you... store them in an array/collection, process them as you get them, or whatever. They key thing though with doing this is that, just like the reporting tools, you would need to process the data first to determine what your SQL projection is, before you execute the query to fetch the data in the format you want e.g.
    create or replace procedure dyn_pivot is
      v_sql varchar2(32767);
      -- cursor to find out the maximum number of projected columns required
      -- by looking at the data
      cursor cur_proj_test is
        select distinct rn
        from   proj_test
        order by rn;
    begin
      v_sql := 'select id';
      for i in cur_proj_test
      loop
        -- dynamically add to the projection for the query
        v_sql := v_sql||',max(decode(rn,'||i.rn||',nm)) as nm_'||i.rn;
      end loop;
      v_sql := v_sql||' from proj_test group by id order by id';
      dbms_output.put_line('Dynamic SQL Statement:-'||chr(10)||v_sql||chr(10)||chr(10));
      -- call our DBMS_SQL procedure to process the query with it's dynamic projection
      process_cursor(v_sql);
    end;
    SQL> exec dyn_pivot;
    Dynamic SQL Statement:-
    select id,max(decode(rn,1,nm)) as nm_1,max(decode(rn,2,nm)) as nm_2,max(decode(rn,3,nm)) as nm_3 from proj_test group by id order by id
    1 - Opening Cursor
    2 - Parsing the query
    3 - Describing the query
    3a - SQL Projection:-
    Column Name: ID                             Datatype: Number
    Column Name: NM_1                           Datatype: Varchar2
    Column Name: NM_2                           Datatype: Varchar2
    Column Name: NM_3                           Datatype: Varchar2
    4 - Binding in values
    5 - Executing the query
    6,7 and 8 Fetching Data:-
    1     ,Fred                ,Bloggs              ,Freddy
    2     ,Scott               ,Smith               ,
    3     ,Jim                 ,Jones               ,
    9 - Closing the cursor
    PL/SQL procedure successfully completed.
    ... and if more data is added ...
    SQL> insert into proj_test (id, rn, nm) values (1,4,'Fud');
    1 row created.
    SQL> exec dyn_pivot;
    Dynamic SQL Statement:-
    select id,max(decode(rn,1,nm)) as nm_1,max(decode(rn,2,nm)) as nm_2,max(decode(rn,3,nm)) as nm_3,max(decode(rn,4,nm)) as nm_4 from proj_test group by id order by id
    1 - Opening Cursor
    2 - Parsing the query
    3 - Describing the query
    3a - SQL Projection:-
    Column Name: ID                             Datatype: Number
    Column Name: NM_1                           Datatype: Varchar2
    Column Name: NM_2                           Datatype: Varchar2
    Column Name: NM_3                           Datatype: Varchar2
    Column Name: NM_4                           Datatype: Varchar2
    4 - Binding in values
    5 - Executing the query
    6,7 and 8 Fetching Data:-
    1     ,Fred                ,Bloggs              ,Freddy              ,Fud
    2     ,Scott               ,Smith               ,                    ,
    3     ,Jim                 ,Jones               ,                    ,
    9 - Closing the cursor
    PL/SQL procedure successfully completed.
    Of course there are other methods, using dynamically generated scripts etc. (see Re: 4. How do I convert rows to columns?), but the above simply demonstrates that:-
    a) having a dynamic projection requires two passes of the data; one to dynamically generate the query and another to actually query the data,
    b) it is not a good idea in most cases as it requires code to handle the results dynamically rather than being able to simply query directly into a known structure or variables, and
    c) a simple SQL statement cannot have a dynamic projection.
    Most importantly, dynamic queries prevent validation of your queries at the time your code is compiled, so the compiler can't check that the column names are correct or the tables names, or that the actual syntax of the generated query is correct. This only happens at run-time, and depending upon the complexity of your dynamic query, some problems may only be experienced under certain conditions. In effect you are writing queries that are harder to validate and could potentially have bugs in them that would are not apparent until they get to a run time environment. Dynamic queries can also introduce the possibility of SQL injection (a potential security risk), especially if a user is supplying a string value into the query from an interface.
    To summarise:-
    The projection of an SQL statement must be known by the SQL engine before any data is fetched, so don't expect SQL to magically create columns on-the-fly based on the data it's retrieving back; and, if you find yourself thinking of using dynamic SQL to get around it, just take a step back and see if what you are trying to achieve may be better done elsewhere, such as in a reporting tool or the user interface.
    Other articles in the PL/SQL 101 series:-
    PL/SQL 101 : Understanding Ref Cursors
    PL/SQL 101 : Exception Handling

    excellent article. However there is one thing which is slightly erroneous. You don't need a type to be declared in the database to fetch the data, but you do need to declare a type;
    here is one of my unit test scripts that does just that.
    DECLARE
    PN_CARDAPPL_ID NUMBER;
    v_Return Cci_Standard.ref_cursor;
    type getcardapplattrval_recordtype
    Is record
    (cardappl_id ci_cardapplattrvalue.cardappl_ID%TYPE,
    tag ci_cardapplattrvalue.tag%TYPE,
    value ci_cardapplattrvalue.value%TYPE
    getcardapplattrvalue_record getcardapplattrval_recordtype;
    BEGIN
    PN_CARDAPPL_ID := 1; --value must be supplied
    v_Return := CCI_GETCUSTCARD.GETCARDAPPLATTRVALUE(
    PN_CARDAPPL_ID => PN_CARDAPPL_ID
    loop
    fetch v_return
    into getcardapplattrvalue_record;
    dbms_output.put_line('Cardappl_id=>'||getcardapplattrvalue_record.cardappl_id);
    dbms_output.put_line('Tag =>'||getcardapplattrvalue_record.tag);
    dbms_output.put_line('Value =>'||getcardapplattrvalue_record.value);
    exit when v_Return%NOTFOUND;
    end loop;
    END;

  • Ref Cursor

    Hi,
    If anybody know how to execute function which has ref cursor type.
    Can I call that function in my select statement in query.
    Function is using week ref cursor type and id as IN parameter.
    Thans for you help in advance.

    You can use a function returning a ref cursor in SQL, the output is nested cursor though.
    SQL> create or replace function f
      2  return sys_refcursor
      3  as
      4    c sys_refcursor;
      5  begin
      6    open c for
      7      select * from emp where deptno = 10;
      8    return c;
      9  end;
    10  /
    Function created.
    SQL> select f from dual;
    F
    CURSOR STATEMENT : 1
    CURSOR STATEMENT : 1
    EMPNO ENAME      JOB          MGR HIREDATE      SAL   COMM DEPTNO
      7782 CLARK      MANAGER     7839 06-09-1981   2450            10
      7839 KING       PRESIDENT        11-17-1981   5000            10
      7934 MILLER     CLERK       7782 01-23-1982   1300            10
    SQL>

  • Changed behaviour when handling Oracle Objects in SQL Developer 3.1

    In version of SQL Developer before (and including) 3.0, when one executed - F5, run script, not F9, run query - a query that included an SDO_GEOMETRY (oracle object) object the object's elements where displayed in the output text form.
    In SQL Developer 3.1 that has changed. Now, one only gets [MDSYS.SDO_GEOMETRY] as a placeholder.
    Many spatial users prefer the former behaviour.
    Has something changed in 3.1 that causes this?
    Is there a way that I can get the previous behaviour back?
    I program the GeoRaptor SQL Developer extension. GeoRaptor has an Addin that allows it to reformat SDO_GEOMETRY objects in a result set on the fly.
    Does one need to do something similar now in SQL Developer 3.1?
    If so, can you provide an example.
    Finally, are there any plans to release Javadoc for the SQL Developer jar files that an extension developer needs to use when constructing an extension?
    regards
    Simon

    >
    In SQL Developer 3.1 that has changed. Now, one only gets [MDSYS.SDO_GEOMETRY] as a placeholder.
    >
    Yes - there has been some history re SDO_GEOMETRY in particular.
    See Gary Graham's reply in this thread
    Re: Query result window doesn't show contents of collection types
    >
    There is some history behind this change. It started with a performance issue populating the grid for SDO_GEOMETRY objects:
    Re: SQLD 3.1EA -  Fails to render resultset output containing SDO_GEOMETRY

  • SQL Developer problem. Rows without columns on data tab

    Hello,
    I have a strange behavior in Oracle SQL Developer Version 2.1.0.63. When I'm trying to open the "Data tab" for some tables, SQL Developer shows data rows but without columns! It seems that I can select different rows but I can't see neither any data nor column names.
    Under the filter setting there are no available columns either.
    At the same time, when I'm trying to open sys tables they are displayed normally.
    From the other side, those tables which are not displayed correctly in 2.1.0.63, could be opened in Version 1.5.5 without any problems.
    Do you have any ideas?
    Thanks in advance.

    Hi,
    Refer to the SQL Developer forum: SQL Developer for SQL Developer related questions

  • SQL Developer 4.0 EA3. query result in export format problem

    Query output in export format (insert, csv, xml,...) is not working in 4.0 EA3.
    Query executed as script (F5) does not display anything:
    select /*insert*/ * from dual;
    SQL Developer 3 displays the result correctly:
    REM INSERTING into dual
    SET DEFINE OFF;
    Insert into "dual" (DUMMY) values ('X');
    About
    Oracle SQL Developer 4.0.0.13
    Version 4.0.0.13
    Build MAIN-13.30
    IDE Version: 12.1.3.0.41.131007.2031
    Product ID: oracle.sqldeveloper
    Product Version: 12.2.0.13.30
    Version
    Component    Version
    =========    =======
    Oracle IDE    4.0.0.13.30
    Java(TM) Platform    1.7.0_07
    Versioning Support    4.0.0.13.30

    That's been fixed for the next release.

  • REF cursor with special characters

    Hi all,
    I want to display the record set using ref cursor. I am passing varchar field as parameter. How to give this in where cluase of select statement.
    i want to use like %parameter_name% in where condition. How to use it in ref cursor.
    Thanks in advance,
    Pal

    user546710 wrote:
    Hi all,
    I want to display the record set using ref cursor. I am passing varchar field as parameter. How to give this in where cluase of select statement.
    i want to use like %parameter_name% in where condition. How to use it in ref cursor.
    Thanks in advance,
    PalWhy using a ref cursor? Do you understand the purpose of ref cursors and how to use them?
    Perhaps take a read of the following to get to grips with the basics...
    PL/SQL 101 : Understanding Ref Cursors
    PL/SQL 101 : Understanding Ref Cursors

Maybe you are looking for

  • "Check that the library name an prefix are correct." Yep, they are. Now what?

    Hello, I have a customer who is using a Labview wrapper for an IVI driver to create an application to send commands to an LXI instrument.  The problem is even the initialize call results in the following error: Driver Status:  (Hex 0xBFFA000A) Check

  • Itunes isnt working

    hello. I run windows XP, and the wierdest thing is happening. iTunes wont load. I get the error in this picture http://img401.imageshack.us/img401/8646/itunesbrokenyg9.png Please help. If restarting wont do anything, this stinks. Also, my iPod is set

  • Convert Solaris 10 zones to Logical Domain

    I am in the process of building a Solaris 10 server on a T3-2 server. I am installing the 8/11 update of Solaris 10 and will be installing OVM for SPARC v2.2 on the server. Currently we are running a number of Solaris Zones on Solaris 10 servers. Ins

  • Authorization check flow

    Hello Folks, I wonder if some one can help clearing a doubt of mine. The standard definition one finds on the net for Authorization check maintenance in SU24 for transactions is: CM = Check performed AND object added in PFCG when tcode added to the r

  • Level of security is there in PDF files?

    What level of security is there in PDF files? My company has asked me to create PDFs with interactive forms that would submit to either a database or an email address (I'm not sure about this yet because I don't know what PDFs are capable of submitti