Using select cursor(select...) from ...

I am trying to use the following construction in the report region:
select
cursor(select * from employees) as "EMPs",
cursor(select * from departments) as "DEPTs"
from dual
It is failing with the following error:
report error:
ORA-00932: inconsistent datatypes: expected NUMBER got CURSER
Just wondering if I just cannot use such a construction, or it's a bug....

OK,
My real query is much more complex then the one I specified above. I was just interested in using that specific syntaxis, as I use it a lot in my XSQL pages, and it works perfectly.
For a sake of an argument, lets say I want to see all the departments' attributes, alltogether with a list of all employees working for that specific department. Of course, I could have used an outer join to achieve this, but I want to use the following:
SELECT d.department_id,
       d.department_name,
       d.location_id,
       CURSOR(SELECT e.first_name,
                     e.last_name
              FROM   employees e
              WHERE  e.department_id = d.department_id
       ) emps
FROM   depatments dWhen I use similar syntaxis in my XSQL pages, it returns a pretty xml document like the following:
<ROW_SET>
  <ROW id="1">
    <department_id>1</department_id>
    <department_name>Accounting</department_name>
    <location_id>12</location_id>
    <ROW_SET_EMPS>
      <ROW id="1">
        <first_name>John</first_name>
        <last_name>Smith</last_name>
      </ROW>
      <ROW id="2">
        <first_name>Smith</first_name>
        <last_name>Johnson</last_name>
      </ROW>
    </ROW_SET_EMPS>
  </ROW>
</ROW_SET>Then I just apply an XSLT over the returned XML, and I get a pretty HTML page displayed in the browser window...
I am specifically interested in this syntaxis, because I have A LOT of XSQL pages published to my intranet users, and I would like to just take those queries and publish them as reports in HTMLDB, since HTMLDB provides me with the session management, authentication, etc., etc., capabilities.
Thank you for all your replies.

Similar Messages

  • Special Grant to use "Select * from Table(cast..."??

    Hi,
    I've recently created the types and function to use the Table(Cast(funtion) as type)). It works fine, and gives me the correct result. I've granted execute on the types and on the function to a role that is enabled for a user, but when the user tries to use the "select * from table(cast(function) as type))", he gets a "ORA-01031: Insufficient Privileges" error message. Is there any other grant that must be given to the role, so that the user can execute the select?
    Thanks in advance!
    Daniel

    Hi Kamal,
    I'm not sure what anonymous PL/SQL block means. When I (or the user) try to run the select, I enter all the information, i.e., the owners for the type and function: "select * from table(cast(a.my_function(my_argument) as a.my_type))". I'm trying to use SQLPlus at this time, and I have Oracle 8i.
    I didn't to explicitly grant execute to the user because that would go against some rules I have to follow... I'll se if I give it a try though!
    Thanks!

  • Inserting Blob in PL/SQL using select from other table

    Oracle 11.1.7.0:
    I am trying to insert blob column as defined below but not able to. Is this the right way of inserting blobs?
    set serveroutput on
    spool a.dat
    DECLARE
    BEGIN
      for i in 1..2
      loop
         for j in  (select r_payload                      
                       from fp_data where payload_id=331525112)
         loop
           EXECUTE IMMEDIATE 'insert into fp_data (r_payload) values ( ' || j.r_payload || ')';
        end loop;
      end loop;
      rollback;
    END;
    exit;

    BLOB work same a CLOB
    SQL> @clob
    SQL> drop table toto;
    SQL> create table toto (
      2    A  VARCHAR2 (30)  NOT NULL,
      3    B  VARCHAR2 (30)  NOT NULL,
      4    C  clob default empty_clob()
      5  )
      6        lob(c) store as toto_name_lo(disable storage in row)
      7  ;
    SQL>
    SQL> set feedback off
    SQL> set timing on;
    SQL> prompt
    SQL> prompt Insert lob with enabled storage in row:
    Insert lob with enabled storage in row:
    SQL> insert into toto (a, b, c)
      2  select owner a, object_name b, owner || ' ' || object_name c from all_objects
      3  where rownum < 10
      4  ;
    Elapsed: 00:00:00.51
    SQL> set timing off;
    SQL> select a,b from toto;
    A                      B
    SYS                      ICOL$
    SYS                      I_USER1
    SYS                      CON$
    SYS                      UNDO$
    SYS                      C_COBJ#
    SYS                      I_OBJ#
    SYS                      PROXY_ROLE_DATA$
    A                      B
    SYS                      I_IND1
    SYS                      I_CDEF2
    SQL> drop   table fp_data;
    SQL> create table fp_data (r_payload clob);
    SQL> insert into fp_data select c from toto where a = 'SYS'     AND B = 'I_IND1';
    SQL> select count(*) from fp_data;
      COUNT(*)
          1no need for PL/SQL

  • Oracle 8i, selecting from Stored Procedudure

    Hi
    In InterBase it is possible to create a Stored Procedure with some input parameters and then select from it.
    for example:
    select * from my_stored_procedure (my_parameter);
    Is it possile to do something similar in Oracle 8i?
    Where to find examples on creating and using stored procedures like this?
    I am new to Oracle and have been browsing documentation CD and otn.oracle.com websites, however is seemes like finding a needle in a haystack.
    I would appreciate any samples or links.
    Thanks,
    Raigo

    As far as I know, this is not possible directly the same way as in IB. You can resort to using REF CURSORs though:
    create or replace package p
    as
    type t_rc is ref cursor; -- weak ref cursor
    function f( cond in number ) return t_rc;
    end;
    create or replace package body p
    as
    function f ( cond in number ) return t_rc
    is
    rv t_rc;
    begin
    open rv for 'select * from some_table where id = :cond' using in cond;
    -- just return open cursor
    return rv;
    end;
    end;
    then you can use it this way:
    declare
    c p.t_rc;
    r some_table%rowtype;
    begin
    c := p.f(100);
    loop
    fetch c into r;
    exit when c%notfound;
    -- process row r here
    end loop;
    end;
    You can also use SELECT FROM TABLE( CAST (function(...) AS collection_type)) syntax - browse Object-Relational Features guide, SQL Reference and Application Development - Fundamentals for more info and examples on this.

  • SELECT from table vs. CALL FUNCTION

    Hello,
    I have always wondered what the "best practice" is in this case, so I am looking for input.  When writing custom reports etc. in SAP, is it generally regarded as better practice to write a SELECT statement to get a line from say a Txxx configuration table, or is it best to use an associated BAPI or call to function module?  I know in some cases perfomance must obvioulsy be considered, but in terms of SAP's recommendations or upgrade considerations, which is typically better? 
    Assume for example something as simple as getting company code data...  Is it best to do <b>SELECT * FROM T001...</b> or to call a BAPI like <b>BAPI_COMPANYCODE_GETDETAIL</b>?
    Any feedback would be greatly appreciated.

    Hi
    Never accusing people of regarding performance, however I emphasize safety while developing. Even if it is a T* table, I try to use a standard function or call a subroutine of a standard program doing the work. I feel safer this way. Nevertheless, when I can't find any suitable (as of its interface), I use direct SELECT statements.
    If it is a simple report program then doing direct selects may be tolerable. However, if it is a more sophisticated one, especially if it deals with database updates, I highly recommend to use standards.
    As another way, I am aware you mean simple tables, but by the way, if it has a functional relation with a business entity (e.g. pa0001 for employee), I regard it as mandatory using standard FMs where applicable (I feel myself obliged to call "HR_READ_INFOTYPE" instead of using "SELECT* FROM PA0001...").
    *--Serdar

  • Is it possible to ... SELECT * FROM my_table WHERE ssn IN (..arraylist..) ?

    Hi, I have a quick question I hope someone can help me with. I'm a student and what I'm looking for should be easy but I can't find any information on it.
    Here's my code, it's probably self-explanatory but to clarify I'm trying to get a list of "Captains" in the order of who has the most wins.
    The problem is that the database tables have thousands of "Captains" and I'm only supposed to look at 200 specific "Captains" which have their ssn in a specific arraylist and then return the top 80 "Captains" from that selection.
    Something like this...
    SELECT first 80 E.name, L.ssn, COUNT(L.wins) as Wins
    FROM log L, employees E
    where type matches "[Captain]"
    and E.ssn = L.ssn
    and L.ssn IN (...arraylist...) // How do I loop through the arraylist but still return a list of the top 80 winners?
    group by E.name, L.ssn
    order by Wins desc;
    Should I start by taking the list of social security numbers from the arraylist and insert them into a temporary table and then use that temporary table to base my selection on?
    For example:
    int rows = 0;
    PreparedStatement ps = conn.prepareStatement("INSERT INTO TEMP captainsTemp (ssn) VALUES(?)");
    Iterator i = myArrayList.iterator();
    while (i.hasNext())
         // Set the variables
         for (int pos = 1; pos <= 63; pos++)
              String s = (String)i.next();
              ps.setString(pos,s);
         // insert a row
         rows += ps.execute();
    ...and then below that I could use
    "SELECT * FROM captains
    WHERE ssn IN (SELECT * FROM captainTemp)..."
    This looks like an ugly solution and I'm not sure if it works, sessionwise..
    Everything's written in Java and SQL.
    If you have any thoughts on this I would be most grateful.
    I should add that this is NOT a school assignment but something I'm trying to figure out for my work...
    Many thanks,
    sincerely,
    JT.

    hi,
    Ignore my previous response. Try out this one. It should help you.
    Lets take the example of EMP table (in Oracle's SCOTT Schema). The following is the description of the table.
    SQL> desc emp
    Name Null? Type
    EMPNO NOT NULL NUMBER(4)
    ENAME VARCHAR2(10)
    JOB VARCHAR2(9)
    MGR NUMBER(4)
    HIREDATE DATE
    SAL NUMBER(7,2)
    COMM NUMBER(7,2)
    DEPTNO NUMBER(2)
    SQL> select ename from emp;
    ENAME
    SMITH
    ALLEN
    WARD
    JONES
    MARTIN
    BLAKE
    CLARK
    SCOTT
    KING
    TURNER
    ADAMS
    JAMES
    FORD
    MILLER
    Say, the ArrayList contains 3 names CLARK,KING & MILLER. You want to loop through the ArrayList for the ENAME values.
    First construct a string like below from the ArrayList.
    "ename in 'CLARK' OR ename in 'KING' or ename in 'MILLER'";
    Append this string to the normal SELECT Query
    Query :
    select ename from emp where ename in 'CLARK' OR ename in 'KING' or ename in 'MILLER'
    Here you get the desired output & thats pretty fast because you just do it once !!!
    SQL> select ename from emp where ename in 'CLARK' OR ename in 'KING' or ename in 'MILLER';
    ENAME
    CLARK
    KING
    MILLER
    you can extend this to your Query also.
    thanks,
    Sriram

  • Interactive report on SELECT * FROM X

    Hi,
    Is there anyway to create an interactive report using SELECT * FROM my_table; where you can add a new column to "my_table" and for the interactive report to pick up the new column without having to go into the report region and hit apply changes?
    I've tried using a collection but that doesn't work as you still have to manually refresh the report region.
    I've even tried hacking my way into:
    wwv_flow_f4000_util.save_interactive_rpt_region (
    p_region_id in number,
    p_flow_id in number,
    p_plug_name in varchar2 default null,
    p_region_name in varchar2 default null,
    p_region_template in number default null,
    p_display_seq in number default null,
    p_display_column in number default null,
    p_display_point in varchar2 default null,
    p_region_source in varchar2 default null,
    p_breadcrumb_template in number default null,
    p_list_template in number default null,
    p_region_display_error_msg in varchar2 default null,
    p_required_role in varchar2 default null,
    p_display_when_cond in varchar2 default null,
    p_display_when_cond2 in varchar2 default null,
    p_display_cond_type in varchar2 default null,
    p_region_header in varchar2 default null,
    p_region_footer in varchar2 default null,
    p_region_column_width in varchar2 default null,
    p_customized in varchar2 default null,
    p_customized_name in varchar2 default null,
    p_requied_patch in number default null,
    p_url_text_begin in varchar2 default null,
    p_url_text_end in varchar2 default null,
    p_translate_title in varchar2 default null,
    p_comment in varchar2 default null);
    (Yes, I know that's bad!)
    Still can't get this to work anyway.
    There must be a way of doing this....
    Any help gratefully recieved.
    Thanks
    Yog

    Keith,
    No it doesn't.
    Here is an example.
    1. Created an interactive report with source as select * fom dept.
    2. Ran my page and saw a report based on columns deptno, dname and loc
    3. Added a column to dept called "newcol"
    4. Reran the page - columns are still deptno, dname and loc
    5. clicked on green cog / select columns and the only options avaiable are still deptno, dname and loc
    In order to get "newcol" to appear I have to edit the page, go to my report region and click Apply Changes. A summary appears with the new column "newcol" shown. I click apply changes again and run the page and only then does the new column appear.
    Cheers
    Yog

  • Selection from database tables

    Hi Experts,
    In one program I'm selecting data from tables <b>VBAK, VBAP,VBRK,VBRP,LIKP,LIPS</b>. As the tables have huge data, it's taking forever to get the data into internal tables.
    Could you please suggest  me to better the performance.
    Thnx much.

    hi dev,
      do not use select .. endselect statement and include all the key fields in your select statement.
    instead of select .. endselect statement use
    select * from <table> into table itab where < conditions)
    Regards,
    Santosh
    Message was edited by: Santosh Kumar P

  • Select *from - special character in datetime 'slash'

    I have table with DateTime colun :
    id dateTime
    1 12/08/03 11:23:25,563563456345634563456
    2 12/08/03 11:23:25,34333333
    I select the rows that were created today , for example 2012-08-03
    but when use :
    select * from TEST_TABLE where DATETIME like '12/08/03'
    i dont have any rows - I need replace '/' - slash
    how to do it ?
    Edited by: user8855885 on 2012-08-03 03:19
    Edited by: user8855885 on 2012-08-03 03:20

    Hi User,
    Welcome to Forum !!!!!!!!
    Why you are saving date in character format recommended, not to save date in character formats.
    Here it is,
    SELECT TO_DATE ('12/08/03 11:23:25', 'YY/MM/DD HH24:MI:SS'),
           TRUNC (TO_DATE ('12/08/03 11:23:25', 'YY/MM/DD HH24:MI:SS'))
      FROM DUAL;
      And,
    Query:
    SELECT *
      FROM your_table
    WHERE TRUNC (datetime) = TRUNC (SYSDATE);Here TRUNC(SYDATE) give today's date. TRUNC function removes the time. So you can get the records created today.
    Thanks,
    Shankar

  • Procedure with select from mysql db link problem

    Hi,
    first of all Oracle is new to me so if there are better ways to do this every suggestion would help.
    My problem is simple i cant use select from dblink inside a procedure.
    In Oralce SQL Developer 1.5.5:
    Im using oracle 11g and mysql 5.5.13 with mysql odbc 5.1
    in both db the user is root
    CREATE PUBLIC DATABASE LINK "MYSQL"
    CONNECT TO "root" IDENTIFIED BY "****"
    AUTHENTICATED BY "root" IDENTIFIED BY "****"
    USING 'mysql';
    select * from t1@mysql;
    run; -> result OK
    select "MAXID" from t1@mysql where "TNAME"='first';
    run; -> result OK
    create or replace
    PROCEDURE T1_IDS_PROC AS
    maxi number;
    BEGIN
    select "MAXID" into maxi from t1@mysql where "TNAME"='first';
    END T1_IDS_PROC;
    compile -> not working:
    Fehler(7,3): PL/SQL: SQL Statement ignored
    Fehler(7,47): PL/SQL: ORA-00904: "TNAME": unknown identifier
    How to solve this?

    Thanks for replay,
    yes the owner of the procedure can acces the remote table.
    I can use
    select count(*) into i from t1@mysql
    inside the procedure, but if i use specific columns inside the select i cant compile.
    Why i need double quote?
    I dont know if i need them but i read some tutorial for dblink to mysql and there was explanied
    Oracle use upercase names and Mysql is case sensitive for odbc 5.1 so i have to double qoute mysql names.
    But with or without double qoute it dont work inside procedures ;(

  • Why does "SELECT * FROM [database].[schema].[table]" not work in Azure ?

    Hi all
    In Microsoft Azure I have 2 databases.
    I work since more than 10 years with T-SQL and I always use
    fully qualified object names, means "[database].[schema].[table]".
    When I now make a connection to my database "A" in Azure and
    write a Query against database "B" ("SELECT * FROM [B].[schema].[table]")
    I get an exception. Of course when I connect to database "B" it works
    but again not to database "A". When I use "SELECT * FROM [schema].[table]"
    with the right database connected, it also works in Azure.
    Hope you understand what I mean :-)
    In MS-SQL, this of course works fine.
    Well my question is: What sense does this make ??
    Do I now have to re-write everything just for azure or will this behavior changed sometimes ?
    I know MS-SQL is not the same like Azure-SQL, but hey; does Microsoft think all projects have only one database ?? :-)
    Thanks for any answer
    Frank

    Hi Frank,
    According to your description, you want to retrieval data cross database in SQL Azure, right?
    As June said, Currently cross database joins are not supported in SQL Azure. Also you cannot change database mid query so you cannot, for example, put a USE [MyDB] in your query either. Please refer to the link below to see the details.
    http://www.britishdeveloper.co.uk/2011/11/cross-database-joins-in-sql-azure.html
    If you have any concern about this behavior, you can submit a feedback at
    http://connect.microsoft.com/SQLServer/Feedback and hope it is resolved in the next release of service pack or product. Your feedback enables Microsoft to make software and services the best that they can be, Microsoft might consider to add this feature
    in the following release after official confirmation.
    Regards,
    Charlie Liao
    TechNet Community Support

  • Wildcard search for numeric values using select ?

    Hi,
    I want do wildcard search for numeric fields of the table.
    For charcter/string i have used - select * from XX_TABLE where param1 like 'SS%'. But this query doesnt work when para1 is numeric. Please let me know first whether this is possible ? if yes how to achieve it ?
    Thanks in advance,
    Shrinivas

    Hi Jack,
    The numeric field is of  8 digits, so when i give search critera as '66', it should return values 66000000, 660000, 6600 etc. so i was not able to give between some range. I also tried storing all these values in internal table and the segregate the values it contains '66*'. This worked well but requires lot of coding effort.Please suggest if you guys have any better method ?
    Thanks,
    Shrinivas

  • Selection from BSEG table

    Hi all
    In one of my program i have to use selection from BSEG by using non key fields like anln1, hkont  etc.
    My program run time taking too much time i.e 1.5 to 2hrs
    Is there any criteria to reduce my run time.
    plz help
    thks
    sateesh

    Hi
    If you need a select by field hkont (so G/L account) use the table BSIS (open item) and BSAS (cleared item)  instead of BSEG, just Eric said.
    SELECT * FROM BSAS WHERE BUKRS = BUKRS
                                              AND HKONT = HKONT.
       SELECT SINGLE * FROM BSEG WHERE BUKRS = BSAS-BUKRS
                                                              AND BELNR = BSAS-BELNR
                                                              AND GJAHR = BSAS-GJAHR
                                                              AND BUZEI  = BSAS-BUZEI.
             SELECT SINGLE * FROM BKPF WHERE BUKRS = BSAS-BUKRS
                                                                   AND BELNR = BSAS-BELNR
                                                                   AND GJAHR = BSAS-GJAH.
    Max
    Edited by: max bianchi on Nov 5, 2008 11:03 AM

  • Error while using a cursor on select

    Hello,
    I am using a cursor for a select statement below is the code.
      OPEN CURSOR g_cursor FOR
        SELECT bkpf~blart
               bkpf~budat
               bkpf~usnam
               bsegc~bukrs
               bsegc~belnr
               bsegc~rfzei
               bsegc~kunnr
               bsegc~aunum
               bsegc~ccins
               bsegc~ccnum
               bsegc~rcrsp
               FROM bkpf
               INNER JOIN bsegc
            ON bkpf~bukrs = bsegc~bukrs AND
               bkpf~belnr = bsegc~belnr AND
               bkpf~gjahr = bsegc~gjahr
            WHERE bkpf~budat  IN s_budat
            AND   bsegc~bukrs IN s_bukrs
            AND   bsegc~rcrsp NE space.
      DO.
        FETCH NEXT CURSOR g_cursor APPENDING CORRESPONDING FIELDS OF TABLE i_bkpf PACKAGE SIZE g_pack.
        IF sy-subrc <> 0.
          EXIT.
        ENDIF.
      ENDDO.
      CLOSE CURSOR g_cursor.
      CLEAR g_cursor.
    The program gives me a dump on the fetch statement , can anyone help me understand the possible cause of this dump and suggest a solution?
    Thanks,
    Alok.

    Hi,
    What is the message that you get in the Dump?
    Regards
    Prasenjit

  • What is the column name when use select ... from table(my_table)

    I have some code that takes a csv and loads it into a type table. I am now trying to select from this table but am not sure what column name to use in my cursor. (See below I have c2.???).
    FUNCTION in_list_varchar2 (p_in_list IN VARCHAR2) RETURN VARCHAR2_TT is
    l_tab VARCHAR2_TT := VARCHAR2_TT();
    l_text VARCHAR2(32767) := p_in_list || ',';
    l_idx NUMBER;
    BEGIN
    LOOP l_idx := INSTR(l_text, ',');
    EXIT WHEN NVL(l_idx, 0) = 0;
    l_tab.extend;
    l_tab(l_tab.last) := TRIM(SUBSTR(l_text, 1, l_idx - 1));
    l_text := SUBSTR(l_text, l_idx + 1);
    END LOOP;
    RETURN l_tab;
    END in_list_varchar2;
    schema_list := 'SCOTT, TOM, MIKE';
    schema_names := regexp_replace(schema_list, '([^,]+)', '''\1''');
    schema_list_t := DATAPUMP_UTIL.in_list_varchar2(schema_list);
    for c2 in
    select *from table(schema_list_t)   
    loop
    dml_str := 'DROP USER ' || c2.??? || 'CASADE';
    EXECUTE IMMEDIATE dml_str;
    end loop;

    Chris wrote:
    I have some code that takes a csv and loads it into a type table. I am now trying to select from this table but am not sure what column name to use in my cursor. (See below I have c2.???).
    FUNCTION in_list_varchar2 (p_in_list IN VARCHAR2) RETURN VARCHAR2_TT is
    l_tab VARCHAR2_TT := VARCHAR2_TT();
    l_text VARCHAR2(32767) := p_in_list || ',';
    l_idx NUMBER;
    BEGIN
    LOOP l_idx := INSTR(l_text, ',');
    EXIT WHEN NVL(l_idx, 0) = 0;
    l_tab.extend;
    l_tab(l_tab.last) := TRIM(SUBSTR(l_text, 1, l_idx - 1));
    l_text := SUBSTR(l_text, l_idx + 1);
    END LOOP;
    RETURN l_tab;
    END in_list_varchar2;
    schema_list := 'SCOTT, TOM, MIKE';
    schema_names := regexp_replace(schema_list, '([^,]+)', '''\1''');
    schema_list_t := DATAPUMP_UTIL.in_list_varchar2(schema_list);
    for c2 in
    select *from table(schema_list_t)   
    loop
    dml_str := 'DROP USER ' || c2.??? || 'CASADE';
    EXECUTE IMMEDIATE dml_str;
    end loop;
    I have some code that takes a csv and loads it into a type table.Why a type table? Where is type table defined as such?
    with PL/SQL, objects must be declared before they can be referenced.
    You need to correct syntax errors before tackling any runtime/logic flaws.

Maybe you are looking for

  • PhotoSmart 6510 e All-IN-ONE Series HP Printer

    My HP Photosmart 6510 e-All- In -One printer suddenly stoped coping, and delivers blank pages.  When I print from my laptop the printer works but the quality is poor; printing faded out areas within the printed-out paper process.  I tries cleaning th

  • Mobile data(3g and edge) on lumia 620

    Hi, i have problem with connecting my Lumia phone to mobile data, i tried connecting through 2g, the browser was working but not my messenger apps including WhatsApp, so i tried connecting through 3g and WhatsApp, Skype and none of my messenger apps

  • Zip data posted from client does not show up correctely at Server

    The java client post GZip'd data to the Webserver. The webserver for some reason shows the first 10 bytes correctly. Not sure what I am overlooking Also get java.io.EOFException: Unexpected end of ZLIB input stream public class GetPost {      public

  • Best practice in dreamweaver based web design

    Hi DW Gurus I have been learning dreamweaver at work and at home for a while now and I am very interested in getting some details about best practices. I am aware that my designs are still quite simple and don't expand dreamweaver anyway near its abi

  • My iPad 2 doesn't show the album covers any more

    How can I get the covers back