Ora - 22905

Dear All,
I have one function as follows;
CREATE OR REPLACE TYPE split_tbl IS TABLE OF number;
CREATE OR REPLACE FUNCTION split (p_list VARCHAR2, p_delim VARCHAR2:=' ') RETURN SPLIT_TBL PIPELINED IS
l_idx    PLS_INTEGER;
l_list   VARCHAR2(32767) := p_list;
l_value  VARCHAR2(32767);
BEGIN
LOOP
l_idx := INSTR(l_list, p_delim);
IF l_idx > 0 THEN
PIPE ROW(SUBSTR(l_list, 1, l_idx-1));
l_list := SUBSTR(l_list, l_idx+LENGTH(p_delim));
ELSE
PIPE ROW(l_list);
EXIT;
END IF;
END LOOP;
RETURN;
END SPLIT;
Now I am createing new function as follows;
create or replace function sm_imagetext_data (mstring in varchar2)
return blob
is
cursor c1 is
select COLUMN_VALUE from table(split(mstring,','));
l_sm_imagetextid number;
l_data blob;
l_data1 blob;
begin
open c1;
loop
fetch c1 into l_sm_imagetextid;
--select COLUMN_VALUE into l_sm_imagetextid from table(split(mstring,','));
select data into l_data from sm_imagetext where sm_imagetextid = l_sm_imagetextid ;
l_data1 := l_data;
end loop;
return l_data1;
--close c1;
end;
But while executing
select sm_imagetext_data('7,8') from dual;
I received ORA -22905 error.
why this errors occoured.
Thanks in advance.

create or replace function sm_imagetext_data (mstring
in varchar2)
return blob
Here the return is BLOB
select sm_imagetext_data('7,8') from dual;SQL*Plus can't handle BLOBs.
Use DBMS_LOB package to do something for LOBs.
CHeers
Sarma.

Similar Messages

  • ORA-22905 with pipelined function

    Hi,
    I have a strange behaviour that I do not understand.
    The code below does not work. It gives me the following errors:
    ORA-22905: cannot access rows from a non-nested table item
    ORA-06512: at line 10
    ORA-06512: at line 19
    The problem comes from the line 14 in that function
    adm_usergroup.GET_GROUPIDS (userid_in)
    If I replace the variable userid_in by its values then it perfectly works.
    Can someone give me an explanation ?
    The adm_usergroup.GET_GROUPIDS (userid_in) is a pipelined function that querry a group of tables and return IDs which are number.
    A call to the function works fine as using it directly in a select statement.
    Cheers,
    Sebastien
    1 DECLARE
    2 l_groups AUTH_TYPE.GROUP_RT;
    3 l_groups_rec authgroup%ROWTYPE;
    4
    5 FUNCTION GET_GROUPS (userid_in IN AUTHUSER.USERID%TYPE)
    6 RETURN AUTH_TYPE.GROUP_RT
    7 IS
    8 l_groups_rt AUTH_TYPE.GROUP_RT;
    9 BEGIN
    10 OPEN l_groups_rt FOR
    11 SELECT ag.*
    12 FROM authgroup ag
    13 WHERE AG.GROUPID IN
    14 (SELECT * FROM table (adm_usergroup.GET_GROUPIDS (userid_in)));
    15
    16 RETURN l_groups_rt;
    17 END GET_GROUPS;
    18 BEGIN
    19 l_groups := GET_GROUPS (1);
    20
    21 LOOP
    22 FETCH l_groups INTO l_groups_rec;
    23
    24 EXIT WHEN l_groups%NOTFOUND;
    25 DBMS_OUTPUT.put_line ('ID: ' || l_groups_rec.groupid);
    26 END LOOP;
    27
    28 CLOSE l_groups;
    29 END;

    by the way here is the full code
    CREATE OR REPLACE PACKAGE AUTHDB.ADM_USERGROUP
    IS
       -- get the group and sub-group ids of a given user id
       FUNCTION get_groupids (userid_in IN AUTHUSER.USERID%TYPE)
          RETURN authgroup_set
          PIPELINED;
    END;
    CREATE OR REPLACE PACKAGE BODY AUTHDB.ADM_USERGROUP
    IS
    FUNCTION get_groupids (userid_in IN AUTHUSER.USERID%TYPE)
          RETURN authgroup_set
          PIPELINED
       IS
          CURSOR group_cur
          IS
             SELECT   mo.groupid
               FROM   memberof mo
              WHERE   MO.USERID = userid_in
             UNION
                 SELECT   gh.groupid
                   FROM   GROUPHIERARCHY gh
             CONNECT BY   PRIOR GH.GROUPID = GH.PARENTGROUP_ID
             START WITH   GH.PARENTGROUP_ID IN (SELECT   mo.groupid
                                                  FROM   memberof mo
                                                 WHERE   MO.USERID = userid_in);
       BEGIN
          FOR rec IN group_cur
          LOOP
             PIPE ROW (authgroup_type (REC.GROUPID));
          END LOOP;
       END;
    END;
    CREATE OR REPLACE
    TYPE        AUTHDB.AUTHGROUP_TYPE AS OBJECT (GROUPID NUMBER (10));
    CREATE OR REPLACE
    TYPE        AUTHGROUP_SET AS TABLE OF authgroup_type;
    DECLARE
       l_groups       AUTH_TYPE.GROUP_RT;
       l_groups_rec   authgroup%ROWTYPE;
       FUNCTION GET_GROUPS (userid_in IN AUTHUSER.USERID%TYPE)
          RETURN AUTH_TYPE.GROUP_RT
       IS
          l_groups_rt   AUTH_TYPE.GROUP_RT;
       BEGIN
          OPEN l_groups_rt FOR
             SELECT   ag.*
               FROM   authgroup ag
              WHERE   AG.GROUPID IN
                            (SELECT   * FROM table (cast(adm_usergroup.GET_GROUPIDS (userid_in) as authgroup_set)));
          RETURN l_groups_rt;
       END GET_GROUPS;
    BEGIN
       l_groups := GET_GROUPS (1);
       LOOP
          FETCH l_groups INTO   l_groups_rec;
          EXIT WHEN l_groups%NOTFOUND;
          DBMS_OUTPUT.put_line ('ID: ' || l_groups_rec.groupid);
       END LOOP;
       CLOSE l_groups;
    END;

  • ORA-22905: cannot access rows from a non-nested table item in Table func

    I am using a table function in Oracle 8.1.7.4.0. I did declare an object type and a collection type like this:
    CREATE TYPE t_obj AS OBJECT ...
    CREATE TYPE t_tab AS TABLE OF t_obj;
    My table function returns t_tab and is called like this:
    SELECT ... FROM TABLE (CAST (my_pkg.table_fnc AS t_tab)) ...
    This works pretty well as long as I run it in the same schema that owns the function and the 2 types. As soon as I run this query from another schema, I get an ORA-22905: cannot access rows from a non-nested table item error, even though I granted execute on both the types and the function to the other user and I created public synonyms for all 3 objects.
    As soon as I specify the schema name of t_tab in the cast, the query runs fine:
    SELECT ... FROM TABLE (CAST (my_pkg.table_fnc AS owner.t_tab)) ...
    I don't like to have a schema hard coded in a query, therefore I'd like to do this without the schema. Any ideas of how to get around this error?

    Richard,
    your 3 statements are correct. I'll go ahead and log a TAR.
    Both DESCs return the same output when run as the other user. And, running the table function directly in SQL*Plus (SELECT my_pkg.table_fnc FROM dual;) also returns a result and no errors. The problem has to be in the CAST function.
    Thanks for your help.

  • ORA-22905 and Cast function

    I am running a query with following code:
    select d.acct_num, lib.fmt_money(a.amt) Total Amount
    from account d, table(report.lib.expense (d.acct_num)) a
    where clause.
    Here:
    1. Report is another schema containing packqges for reporting development.
    2. lib is package name created in the report schema. It contains function such as expense.
    3. expense is a function under Lib package as
    function expense (p_acct number) return number is
    acct_num number;
    begin select xxxx into acct_num from xxx_table); return nvl(acct_num, 0);
    end expense;
    Then when I run this select statement, it gave me ORA-22905 error. Cause: attempt to access rows of an item whose type is not known at parse time or that is not of a nested table type. Action: use CAST to cast the item to a nested table type.
    I used CAST like this:
    select d.acct_num, CAST(a.amt as number ) Total Amount
    from account d, table(report.lib.expense (d.acct_num)) a
    where clause.
    It gave me ORA-00923 From keyword not found where expected.
    Please help me to find where the problem is and thank you for your help a lot.

    citicbj wrote:
    I have checked function and found that function was defined as this:
    function expense (p_exp varchar2) return number
    is
    l_exp number;
    begin
    select xxx into l_exp from xxxx where clause;
    return nvl(l_exp, 0);
    end expense;
    So this is not defined as the table of array. So I take the table off from select statement as
    select d.acct_num,
    to_number(a.amt) Total Amount
    from account d,
    report.lib.expense (d.acct_num) a
    where d.acct_num = a.acct_num;
    Then it return ORA-00933 SQL command not ptoperly ended. However, I couldn't see any not properly ended SQL code here. Please advise your comments.Should just be ...
    select
       d.acct_num,
       report.lib.expense (d.acct_num) as "Total Amount"
       --to_number(a.amt) Total Amount
    from account dNotice that i enclosed the column alias (Total Amount) in " ... that is because you can't have a column alias with spaces as you tried without doing this (the parser gets sad).
    Also, you cannot use a function returning a single value like this as a nested table (at least not the way you are trying) and in your case there's no reason. You don't want to join to it, you are passing in ACCT_NUM which the function will presumably use to filter out not relevant data.
    Finally, there's no reason to TO_NUMBER the function result ... it's already defined to return a number :)

  • Dbms_space.object_growth_trend: ORA-22905

    RDBMS: 10.1.0.5.0
    SQL> SELECT * FROM TABLE(dbms_space.object_growth_trend('JO', 'TAB1', 'TABLE'));
    SELECT * FROM TABLE(dbms_space.object_growth_trend('JO', 'TAB1', 'TABLE'))
    ERROR at line 1:
    ORA-22905: cannot access rows from a non-nested table itemWhy?

    RDBMS: 10.1.0.5.0
    SQL> SELECT * FROM TABLE(dbms_space.object_growth_trend('JO', 'TAB1', 'TABLE'));
    SELECT * FROM TABLE(dbms_space.object_growth_trend('JO', 'TAB1', 'TABLE'))
    ERROR at line 1:
    ORA-22905: cannot access rows from a non-nested table itemWhy?

  • ORA-22905: cannot access rows from a non-nested table item

    Hi All,
    This is the overview of the query used in the package.
    select ename,empno,sal,deptno from
    (select deptno from dept) a,
    (select ename,empno,sal from emp1) b
    where empno in (select * from table (pkg1.fun1('empno')))
    and a.deptno=b.deptno
    union
    select ename,empno,sal,deptno from
    (select deptno from dept) c,
    (select ename,empno,sal from emp2) d
    where empno in (select * from table (pkg1.fun1('empno')))
    and c.deptno=d.deptno
    Here the pkg1.fun1 will convert the string ('empno') into table form. ('empno') is the input parameter to the package and is a string of emp numbers.
    compilation is successful. when this is executed the below error pops up
    "ORA-22905: cannot access rows from a non-nested table item"
    Is there any problem with the table function which i am using in this query
    could anyone guide me to the solution.
    Thanks All

    I have used
    CREATE OR REPLACE
    type tab_num as table of number;
    select * from table (cast(pkg1.fun1('empno')) as tab_num))
    This throws an error during compilation itself
    "PL/SQL: ORA-00932: inconsistent datatypes:expected number got varchar2

  • Oracle error ORA-22905: cannot access rows from a non-nested table item

    Oracle error ORA-22905: cannot access rows from a non-nested table item
    Creating a report using oracle plsql code .
    Getting error ;
    Oracle error ORA-22905: cannot access rows from a non-nested table item
    when I am trying to pass data in clause in pl sql proc
    basically I have a proc which takes 2 parameters(a and b)
    proc (
    P_a varchar2,
    p_b varchar2,
    OUT SYS_REFCURSOR
    culprit code which is giving me  the error and on google they say cast it but I dont know how to do it in my context
    --where  id in (
    --        SELECT * FROM THE (SELECT p_cd_common.get_table_from_string(P_a) FROM dual)
    --        union
    --        SELECT * FROM THE (SELECT p_cd_common.get_table_from_string(P_b) FROM dual)
    data sample returned from this :SELECT * FROM THE (SELECT p_cd_common.get_table_from_string(P_a) FROM dual)
    'Abc','def',
    data sample returned from this;SELECT * FROM THE (SELECT p_cd_common.get_table_from_string(P_b) FROM dual)
    'fgd','fth',
    Any answers ?
    How to pass data in clause in a better way

    Why are you creating a duplicate post? I already asked you to post p_cd_common.get_table_from_string. In particular what is function return type and where it is declared. As I already mentioned, most likely function return type is declared in the package and therefore is PL/SQL type. And TABLE operator can only work with SQL types.
    SY.

  • Ora-22905:cannot access rows from a non-nested ...(during full outer join)

    Greetings Gurus,
    I'm getting an ORA-22905 when I try and do a full outer join in the following function. If I include the commented lines in the perstren_diff_recs2 function I get the error. Both halfs of the union query work by themselves. When I union them bam error. Also, when I use the full outer join syntax the Oracle session craps the bed with a end of file communication error. That is why I'm using the simulated full outer join.
    My goal was to abstract the XML in my queries. The results from the pipelined function is a delta between what is in the XML document and a relational base table.
    Derrick
    CREATE OR REPLACE PACKAGE XML_UTILS is
    TYPE perstren_typ is record (
    uic varchar2(6),
    tpers varchar2(2),
    deply varchar2(6),
    secur varchar2(1),
    struc number(4),
    auth number(4)
    TYPE perstren_diff_typ is record (
    uic           varchar2(6),
    transaction_type char(1),
    tpers           varchar2(2),
    deply           varchar2(6),
    secur           varchar2(1),
    struc           number(4),
    auth           number(4)
    TYPE perstrenSet is table of perstren_typ;
    TYPE perstrenDiffSet is table of perstren_diff_typ;
    function perstren_recs (uic varchar2) return perstrenSet pipelined;
    function perstren_diff_recs2 (uic varchar2) return perstrenDiffSet pipelined;
    end;
    CREATE OR REPLACE PACKAGE BODY XML_UTILS is
    function perstren_diff_recs2 (uic varchar2) return perstrenDiffSet pipelined is
    cursor perstren_recs_cur(in_uic varchar2) is
    select p.uic, p.tpers, p.deply, P.secur, p.struc,p.auth,
    doc.uic as xmluic,
    doc.tpers as xmltpers,
    doc.deply as xmldeply,
    doc.secur as xmlsecur,
    doc.struc as xmlstruc,
    doc.auth as xmlauth
    from perstren_bac p left outer join
    table(xml_utils.perstren_recs(in_uic)) doc
    on (p.uic = doc.uic and
    p.tpers = doc.tpers and
    p.deply = doc.deply)
    where p.uic = in_uic;
    -- union
    -- select p.uic, p.tpers, p.deply, P.secur, p.struc,p.auth,
    -- doc.uic as xmluic,
    -- doc.tpers as xmltpers,
    -- doc.deply as xmldeply,
    -- doc.secur as xmlsecur,
    -- doc.struc as xmlstruc,
    -- doc.auth as xmlauth
    -- from perstren_bac p right outer join
    -- table(xml_utils.perstren_recs(in_uic)) doc
    -- on (p.uic = doc.uic and
    -- p.tpers = doc.tpers and
    -- p.deply = doc.deply)
    -- where doc.uic = in_uic;
    out_rec perstren_diff_typ;
    begin
    for cur_rec in perstren_recs_cur(uic) loop
    if cur_rec.xmldeply is not null and cur_rec.xmltpers is not null then
    out_rec.uic := cur_rec.xmluic;
    out_rec.tpers := cur_rec.xmltpers;
    out_rec.deply := cur_rec.xmldeply;
    out_rec.secur := cur_rec.xmlsecur;
    out_rec.struc := cur_rec.xmlstruc;
    out_rec.auth := cur_rec.xmlauth;
    else
    out_rec.uic := cur_rec.uic;
    out_rec.tpers := cur_rec.tpers;
    out_rec.deply := cur_rec.deply;
    out_rec.secur := cur_rec.secur;
    out_rec.struc := cur_rec.struc;
    out_rec.auth := cur_rec.auth;
    end if;
    if cur_rec.uic is not null and cur_rec.xmldeply is not null and cur_rec.xmltpers is not null and (
    nvl(cur_rec.secur,'XX') != nvl(cur_rec.xmlsecur,'XX') or
    nvl(cur_rec.struc,9999) != nvl(cur_rec.xmlstruc,9999) or
    nvl(cur_rec.auth,9999) != nvl(cur_rec.xmlauth,9999)) then
    out_rec.transaction_type :='U';
    elsif cur_rec.uic is null and cur_rec.xmldeply is not null then
    out_rec.transaction_type :='I';
    elsif cur_rec.uic is not null and cur_rec.xmldeply is null then
    out_rec.transaction_type :='D';
    else
    out_rec.transaction_type :='O';
    end if;
    PIPE row (out_rec);
    end loop;
    exception
    when others then
    if perstren_recs_cur%isopen then
    close perstren_recs_cur;
    end if;
    raise;
    return;
    end;
    function perstren_recs (uic varchar2) return perstrenSet pipelined is
    cursor perstren_recs_cur(in_uic varchar2) is
    select uic,
    extractvalue(Column_value,'/PERSTREN/TPERS') as TPERS,
    extractvalue(Column_value,'/PERSTREN/DEPLY') as DEPLY,
    extractvalue(Column_value,'/PERSTREN/SECUR') as SECUR,
    extractvalue(Column_value,'/PERSTREN/STRUC') as STRUC,
    extractvalue(Column_value,'/PERSTREN/AUTH') as AUTH
    from test_ref ref,
    table(XMLSequence(extract(ref.XML_DOC,'/RasDataSet/PerstrenList/PERSTREN'))) per
    where ref.uic = in_uic;
    out_rec perstren_typ;
    begin
    open perstren_recs_cur(uic);
    loop
    fetch perstren_recs_cur into out_rec;
    exit when not perstren_recs_cur%FOUND;
    PIPE row (out_rec);
    end loop;
    close perstren_recs_cur;
    exception
    when others then
    if perstren_recs_cur%isopen then
    close perstren_recs_cur;
    end if;
    raise;
    return;
    end;
    end;

    Oracle bug when executing the query in a function

  • ERROR:-22905:ORA-22905: cannot access rows from a non-nested table item

    Hi. I have some code running on oracle 9i that gives me above error.
    Following are my type declarations.
    drop type_obj_tea_icore_glr;
    drop type_tbl_tea_icore_glr;
    create or replace type type_obj_tea_icore_glr as object (
    ns_comp_id_parent number,
    ns_comp_id_child number,
    serv_item_id number,
    glr_display_order number,
    exchange_carrier_circuit_id varchar2(53)
    show err
    create or replace type type_tbl_tea_icore_glr as table of type_obj_tea_icore_glr;
    show err
    I have a function in an oracle package tea_icore_pkg with following signature.
    FUNCTION sortpvcdesign (
    p_document_number serv_req_si.document_number%TYPE,
    p_pvc_serv_item_id serv_item.serv_item_id%TYPE,
    p_orig_port_serv_item_id serv_item.serv_item_id%TYPE
    RETURN type_tbl_tea_icore_glr
    If I run following from SQL prompt, it works fine.
    SELECT * FROM TABLE (tea_icore_pkg.sortpvcdesign(255082,2782636,2723752) );
    But when I use that within another procedure of the same packge, as follows:
    FOR glr_rec IN
    (SELECT *
    FROM TABLE
    (CAST
    (sortpvcdesign (c_pvcs.order_nbr,
    c_pvcs.pvc_serv_item_id,
    c_pvcs.orig_port_serv_item_id
    ) AS type_tbl_tea_icore_glr
    LOOP
    At the runtime, I got the above error message ( as referred to in subject ). I took all of the suggestions on CAST without much success. The user/schema is only one schema here. I mean, no permissions issue. I granted all on above types to public.
    Can someone help?

    Bil,
    I tried both with CAST and without CAST with specifying the colums. The same error.
    OR glr_rec IN
    (SELECT ns_comp_id_parent, ns_comp_id_child, serv_item_id,
    glr_display_order, exchange_carrier_circuit_id
    FROM TABLE
    (CAST
    (sortpvcdesign (c_pvcs.order_nbr,
    c_pvcs.pvc_serv_item_id,
    c_pvcs.orig_port_serv_item_id
    ) AS type_tbl_tea_icore_glr
    LOOP

  • [ORA-22905] How to read a field of an object inside another object?

    Greetings,
    I'm a student and in a current exercise we have to work with the Object Oriented Programming functionality of Oracle.
    In the database we defined an object type, which is then considered inside another object type. The thing is, that I cannot read an attribute of the inner object. I've read tens of websites but none of them have helped so far. I've read the PL/SQL User Guide and Reference document also.
    The inner object is defined as follows:
    create type address_t as object (
            street varchar(50),
            city varchar(50),
            pcode number(5,0)
            );The outer object has an object of type address_t inside it:
    CREATE TYPE professor_t as OBJECT(
              code number(2),
              p_name varchar(50),
              address address_t,
              );Also, there is a table named PROFESSORS that stores objects of type professor_t
    First of all, with a simple testing SQL statement I can see the data inside the object professor, even the object address_t:
    SELECT * FROM PROFESSORS WHERE CODE = 13;returns the following:
    CODE    |         NAME      |       ADDRESS
    13      |         JOHN     |       MYSCHEMA.ADDRESS_T('FIFTH AVENUE','NEW YORK',12345)The thing is, I want to read the field street of the object address (of type address_t) inside professor (of type professor_t).
    I could see everywhere that the way to go is to use point notation, and I've seen examples about the command VALUE, but none of the following SQL statements work:
    SELECT VALUE(ADDRESS.STREET) FROM(
      SELECT CODE,P_NAME,ADDRESS FROM PROFESSORS WHERE CODE = 13);
    SELECT ADDRESS.STREET FROM PROFESSORS WHERE CODE = 13;
    SELECT PROFESSOR.ADDRESS.STREET FROM PROFESSORS WHERE CODE = 13;I'd really appreciate if someone could show me how to access the values of the field of the object inside an object.
    Thanks in advance,
    - David
    Edited by: 858176 on May 11, 2011 6:53 PM Formatting

    Great, this worked so far.
    It is curious that you wrote 'profesores' but that is the actual name for the variable. I translated everything to english in order to post it here.
    So, the statement is:
    select value(t).DIRECCION.CIUDAD from profesores t;And It returned:
    VALUE(T).DIRECCION.CIUDAD                         
    Valencia                                          
    New York
    TijuanaAnd, applying the VALUE command to the statement:
    select codigo,
    nombre,
    value(t).DIRECCION.CALLE,
    value(t).DIRECCION.CIUDAD,
    value(t).DIRECCION.CP
    from profesores T WHERE T.CODIGO = 13;Resulting in:
    CODIGO                 NOMBRE                                             VALUE(T).DIRECCION.CALLE                           VALUE(T).DIRECCION.CIUDAD                          VALUE(T).DIRECCION.CP 
    13                     Pepito Pérez                                       Calle de los Rosales 0                           Valencia                                           46023                  That is EXACTLY what I needed.
    Thanks Thomas, It was really helpful !
    Edited by: 858176 on May 11, 2011 7:46 PM

  • Using Cursor and FOR LOOP to INSERT the data into table

    Hi all,
    I have SELECT statement that returns 3 rows:
    PROCESSNAME
    PROTDATE
    IMM
    2013-12-18
    Metrology
    2013-11-18
    CT
    2013-12-04
    SELECT  processName, MAX(NVL(protStartDate, protCreateDate)) AS protDate
        FROM TABLE(SEM_MATCH("{
                ?ipc rdf:type s:Protocol .
                ?ipc s:protocolNumber ?protNum .
                ?ipc s:protocolCreateDate ?protCreateDate .
                OPTIONAL {?ipc s:protocolSchedStartDate ?protStartDate }
                ?ipra rdf:type s:ProcessAggregate .
                ?ipra s:hasProtocol ?iprot .
                ?iprot s:protocolNumber ?protNum .
                ?ipra s:processAggregateProcess ?processName.
        }",sem_models("PROTS", "LINEARS"),NULL, SEM_ALIASES(SEM_ALIAS("","http://VISION/Data/SEMANTIC#"),SEM_ALIAS("s","http://VISION/DataSource/SEMANTIC#")),NULL))
            Group by processName
    Now I need to INSERT these values into the table along with the other values.
    these other values come from different table.
           INSERT INTO MODEL_CLASS_COUNTS (MODEL_NAME, CLASS_NAME, INS_COUNT, COUNT_DATETIME, PROCESS_NAME, PROT_DATE)
           VALUES
           ("$MODEL",     
                "${i}",
            (SELECT COUNT (DISTINCT S)  FROM TABLE(SEM_MATCH(
                            "{?s rdf:type :${i} . }",SEM_Models("$MODEL"),NULL, SEM_ALIASES(SEM_ALIAS("","http://VISION/DataSource/SEMANTIC#")),NULL))),
             SYSTIMESTAMP, %%here need to insert PROCESSNAME, PROTDATE%%
    t was giving me error:
    PL/SQL: ORA-22905: cannot access rows from a non-nested table item
    so i enclosed sparql query into single quotes.
    The code is as follows:
    declare
    type c_type is REF CURSOR;
    cur c_type;
    v_process varchar2(200);
    v_pdate varchar2(200);
    begin
    open cur for
           ' SELECT processName,  MAX(NVL(protStartDate, protCreateDate)) AS protDate   <-- it's complaining about this being too long identifier, i think...
            FROM TABLE
              (SEM_MATCH (
                            ?ipc rdf:type s:Protocol .
                            ?ipc s:protocolNumber ?protNum .
                            ?ipc s:protocolCreateDate ?protCreateDate .
                            OPTIONAL {?ipc s:protocolSchedStartDate ?protStartDate }
                            ?ipra rdf:type s:ProcessAggregate .
                            ?ipra s:hasProtocol ?iprot .
                            ?iprot s:protocolNumber ?protNum .
                            ?ipra s:processAggregateProcess ?processName.
                        }",SEM_Models("XCOMPASS", "XPROCESS"),NULL,    
              SEM_ALIASES(SEM_ALIAS("","http://VISION/Data/SEMANTIC#"),
              SEM_ALIAS("s", "http://VISION/DataSource/SEMANTIC#")),NULL))
               Group by processName';  
    loop
    fetch cur into v_process, v_pdate;
    exit when cur%NOTFOUND;
    --here I need to insert v_process , v_pdate into my table along with other values...
    dbms_output.put_line('values for process and prod_date are: ' || v_process || v_pdate );
    end loop;
    close cur;
    end;
    exit;
    Now, I get an error:
    ORA-00972: identifier is too long
    Does anyone know way around this?

    Hi,
      I tested something similar with insert into select  and it worked fine :
    insert into t_countries(ID,CITY ,POPULATION, DESCRIPTION, located, insdate )
    SELECT 1 id, city, o , city||' is a nice city' description,  max(nvl(locatedAt,'unknown')) as located,
      SYSTIMESTAMP
      FROM TABLE(SEM_MATCH(
        '{GRAPH :gCH {<http://www.semwebtech.org/mondial/10/countries/CH/> :hasCity ?cityID .
           ?cityID :name ?city .
           OPTIONAL{?cityID :locatedAt ?locatedAt .}
           ?cityID :population ?o .
        SEM_Models('VIRT_MODEL_MONDIAL'),
        SEM_Rulebases(null),
        SEM_ALIASES(SEM_ALIAS('','http://www.semwebtech.org/mondial/10/meta#'),
        SEM_ALIAS('prv','http://www.semwebtech.org/mondial/10/countries/CH/provinces/')
        null))
        group by city,o
        order by city;
    Or with execute immediate :
    declare
      v_country varchar2(200) :='http://www.semwebtech.org/mondial/10/countries/F/';
      v_text varchar2(2000);
    begin
    v_text := 'insert into t_countries(ID,CITY ,POPULATION, DESCRIPTION, located, insdate )
    SELECT 1 id, city, o , city||'' is a nice city'' description,  max(nvl(locatedAt,''unknown'')) as located,
      SYSTIMESTAMP
      FROM TABLE(SEM_MATCH(
        ''{<'||v_country||'> :hasCity ?cityID .
           ?cityID :name ?city .
           OPTIONAL{?cityID :locatedAt ?locatedAt .}
           ?cityID :population ?o .
        SEM_Models(''VIRT_MODEL_MONDIAL''),
        SEM_Rulebases(null),
        SEM_ALIASES(SEM_ALIAS('''',''http://www.semwebtech.org/mondial/10/meta#'') ),
        null))
        group by city,o
        order by city';
        dbms_output.put_line(v_text);
        delete from t_countries;
        execute immediate v_text ;
        commit;
    end;
    Marc

  • Get distinct values from plsql array

    Hi,
    I have declared a variable as below in plsql proc.
    type t_itemid is table of varchar2(10);
    inserted set of items in to this using a program
    now i want distinct values from that array how can i get it.

    I am using 9i so i cannot use set operator and more over my problem is that i am declaring the variable inside the plsql block . when i tried i am getting the below errors:
    SQL> r
    1 declare
    2 type t_type is table of varchar2(10);
    3 v_type t_type;
    4 begin
    5 v_type := t_type('toys','story','good','good','toys','story','dupe','dupe');
    6 for i in (select column_value from table(v_type)) loop
    7 dbms_output.put_line(i.column_value);
    8 end loop;
    9* end;
    for i in (select column_value from table(v_type)) loop
    ERROR at line 6:
    ORA-06550: line 6, column 41:
    PLS-00642: local collection types not allowed in SQL statements
    ORA-06550: line 6, column 35:
    PL/SQL: ORA-22905: cannot access rows from a non-nested table item
    ORA-06550: line 6, column 10:
    PL/SQL: SQL Statement ignored
    ORA-06550: line 7, column 22:
    PLS-00364: loop index variable 'I' use is invalid
    ORA-06550: line 7, column 1:
    PL/SQL: Statement ignored

  • Problem in opening a ref cursor.

    Hi,
    I'm getting the following error when i'm trying to open the ref cursor. PL/SQL: ORA-22905: cannot access rows from a non-nested table item
    What i'm trying to do is I'm dumping the data into pl/sql table and i want retrieving the by using a ref cursor. Please see the code and help me out.
    CREATE OR REPLACE PACKAGE CPS_RECR.pg_pool_status AS
      TYPE pool_rec IS RECORD (
       status  varchar2(50)
      ,stsno number
      ,stscode varchar2(5)
      ,candidatename varchar2(200)
      ,monyear varchar2(10)
      ,yyyymm number
      ,stscnt number
      --type rec_sts_tab is table of number ;--index by pls_integer;
      type pool_tab IS table of pool_rec index by binary_integer;
      type pool_cv is REF CURSOR return pool_rec;
    FUNCTION pool_status_query(p_start_date in date,p_end_date in  date,p_invitedtopoolbit  in number,p_showedForPoolBit in  number)
       RETURN pool_tab;--pool_cv ;
      cursor cur_pool(p_start_date date,p_end_date date,p_invitedtopoolbit number,p_showedForPoolBit number)
      is
         SELECT   distinct to_char(date1,'yyyymm')yearmonth
                  FROM acs100data a,
                     acs100_candidate_verification b,                
                     acs100_candidate_pool d
                 WHERE UPPER (a.basic_email) = UPPER (b.email)
                 AND (b.candidate_status IN ('FORL', 'FWRT') or BITAND (b.candidate_status_bit, 4 ) > 0
                  or BITAND (b.candidate_status_bit, 2) > 0)                         
                 AND d.pool_id = b.pool_id
                 AND pool_date BETWEEN p_start_date AND p_end_date
                 AND is_tentative_date IS NULL  ;
      cursor cur_name(p_yyyymm varchar2,p_cond number,p_start_date date,p_end_date date)
      is
      select *
      from (select distinct (case
                                when p_cond = 0 and b.candidate_status = 'FORL'
                                   then (last_name || first_name)
                                when p_cond = 1 and b.candidate_status = 'FWRT'
                                   then (last_name || first_name)
                                when p_cond = 2
                                and bitand (b.candidate_status_bit, p_cond) > 0
                                   then (last_name || first_name)
                                when p_cond = 4
                                and bitand (b.candidate_status_bit, p_cond) > 0
                                   then (last_name || first_name)
                             end
                            ) candidatename
                       from acs100data a,
                            acs100_candidate_verification b,
                            acs100_candidate_pool d
                      where upper (a.basic_email) = upper (b.email)
                        and d.pool_id = b.pool_id
                        and pool_date between p_start_date and p_end_date
                        and to_char (date1, 'yyyymm') = p_yyyymm
                        and is_tentative_date is null)
    where candidatename is not null;  
    END pg_pool_status;
    CREATE OR REPLACE PACKAGE BODY CPS_RECR.pg_pool_status
    AS
       FUNCTION pool_status_query (
          p_start_date         IN   DATE,
          p_end_date           IN   DATE,
          p_invitedtopoolbit   IN   NUMBER,
          p_showedforpoolbit   IN   NUMBER
          RETURN pool_tab--pool_cv
       IS
          tab_pool    pool_tab;
          temp_rf    pool_cv;
          n_index     NUMBER         := 1;
          --rec_sts_data  rec_sts_tab;
          n_stscnt    NUMBER;
          vc_status   VARCHAR2 (100);
          vc_label  varchar2(1000);
          vc_name  varchar2(100);
       BEGIN
          tab_pool.DELETE;
          vc_label :='Opening Pool cursor';
          FOR rec_pool IN cur_pool (p_start_date,
                                    p_end_date,
                                    p_invitedtopoolbit,
                                    p_showedforpoolbit
          LOOP
              if cur_pool%notfound then
                exit;
              end if;
             vc_label :='Opening p_cond cursor';
             FOR p_cond IN 0 .. 3
             LOOP
                n_stscnt := 0;
                vc_status := NULL;
                begin
                    SELECT   SUM
                                (NVL
                                    (COUNT
                                        (CASE
                                            WHEN p_cond = 0
                                            AND b.candidate_status = 'FORL'
                                               THEN (last_name || first_name)
                                            WHEN p_cond = 1
                                            AND b.candidate_status = 'FWRT'
                                               THEN (last_name || first_name)
                                            WHEN p_cond = 2
                                            AND BITAND (b.candidate_status_bit,
                                                        p_cond) > 0
                                               THEN (last_name || first_name)
                                            WHEN p_cond = 4
                                            AND BITAND (b.candidate_status_bit,
                                                        p_cond) > 0
                                               THEN (last_name || first_name)
                                         END
                                     0
                                ) cnt,
                             DECODE (p_cond,
                                     0, 'FAILED WRITTEN TEST',
                                     1, 'FAILED **** TEST',
                                     2, 'Invited for Pool',
                                     4, 'Showed up for Pool'
                                    ) status
                        INTO n_stscnt,
                             vc_status
                        FROM acs100data a,
                             acs100_candidate_verification b,
                             acs100_candidate_pool d
                       WHERE UPPER (a.basic_email) = UPPER (b.email)
                         AND d.pool_id = b.pool_id
                         AND pool_date BETWEEN p_start_date AND p_end_date
                         AND TO_CHAR (date1, 'yyyymm') = rec_pool.yearmonth
                         AND is_tentative_date IS NULL
                    GROUP BY candidate_status,
                             b.candidate_status_bit,
                             DECODE (p_cond,
                                     0, 'FAILED WRITTEN TEST',
                                     1, 'FAILED **** TEST',
                                     2, 'Invited for Pool',
                                     4, 'Showed up for Pool'
                  exception
                     when no_data_found
                     then
                        n_stscnt :=0;
                        vc_status :=null;
                 end;
                vc_label :='Opening name cursor';         
                FOR rec_name IN cur_name (rec_pool.yearmonth,
                                          p_cond,
                                          p_start_date,
                                          p_end_date
                LOOP
                   if cur_name%notfound then
                   exit;
                   end if;
                   tab_pool (n_index).yyyymm := rec_pool.yearmonth;
                   tab_pool (n_index).stscnt := n_stscnt;
                   tab_pool (n_index).status := vc_status;
                   tab_pool (n_index).candidatename := rec_name.candidatename;
                   dbms_output.put_line('tab_pool(n_index).yyyymm  : '||tab_pool(n_index).yyyymm);
                   dbms_output.put_line('tab_pool(n_index).stscnt : '||tab_pool(n_index).stscnt);
                   dbms_output.put_line('tab_pool(n_index).status : '||tab_pool(n_index).status);
                   dbms_output.put_line('tab_pool(n_index).candidatename : '||tab_pool(n_index).candidatename);
                   vc_name :=rec_name.candidatename;
                END LOOP;
                n_index := n_index + 1;
             END LOOP;
          END LOOP;      
          RETURN tab_pool;
       exception
         when others
         then
             dbms_output.put_line('error :'||vc_label||'--'||  vc_name); 
       END;
    END pg_pool_status;
    ---run script
    DECLARE
      RetVal CPS_RECR.PG_POOL_STATUS.pool_tab;
      P_START_DATE DATE;
      P_END_DATE DATE;
      P_INVITEDTOPOOLBIT NUMBER;
      P_SHOWEDFORPOOLBIT NUMBER;
    temp_cv CPS_RECR.PG_POOL_STATUS.pool_cv;
    BEGIN
      P_START_DATE := to_date('09/01/2008','mm/dd/yyyy');
      P_END_DATE := to_date('09/30/2008','mm/dd/yyyy');
      P_INVITEDTOPOOLBIT := 2;
      P_SHOWEDFORPOOLBIT := 4;
      open temp_cv for select * from  table((CPS_RECR.PG_POOL_STATUS.POOL_STATUS_QUERY ( P_START_DATE, P_END_DATE, P_INVITEDTOPOOLBIT, P_SHOWEDFORPOOLBIT )) );
      end loop;
    exception
       when others
       then
          dbms_output.put_line(sqlerrm);
    END;

    Satyaki,
    It doesn't help me out. I'm worndering one of code sample is working fine. i didn't my current is giving the problem.
    FYI, please see the some code i followed.
    SQL> Create or replace PACKAGE cv IS
      2     type comp_rec is RECORD
      3               (deptno number,
      4                ename  varchar(10),
      5                compensation number);
      6     type comp_tbl IS table of comp_rec;
      7     function get_coll return comp_tbl pipelined;
      8     temp_tbl comp_tbl := comp_tbl();
      9     type comp_cv is REF CURSOR return comp_rec;
    10  end;
    11  /
    Package created.
    SQL> Create or replace PACKAGE body cv IS
      2     function get_coll return comp_tbl pipelined
      3     is
      4     begin
      5      for i in 1..temp_tbl.count loop
      6       pipe row(temp_tbl(i));
      7      end loop;
      8      return;
      9     end;
    10  end;
    11  /
    Package body created.
    SQL> declare
      2     temp_cv cv.comp_cv;
      3     rc cv.comp_rec;
      4  begin
      5           cv.temp_tbl.delete;
      6           cv.temp_tbl.extend;
      7    cv.temp_tbl(1).deptno:=10;
      8    cv.temp_tbl(1).ename:='1223';
      9    cv.temp_tbl(1).compensation:=10;
    10  
    11          -- erroring out
    12   open temp_cv for select * from  table(cv.get_coll);
    13          fetch temp_cv into rc;
    14          dbms_output.put_line('Deptno is ' || rc.deptno);
    15          dbms_output.put_line('ename is ' || rc.ename);
    16  end;
    17  /
    Deptno is 10
    ename is 1223
    PL/SQL procedure successfully completed.

  • MERGE using nested table doesn't work on Oracle 9i

    Hi,
    Oracle 9i Enterprise Edition Release 9.2.0.4.0 on Red hat Linux
    SQL> create table PERSONS (
      2    ID  number(9)
      3   ,SURNAME  varchar2(50)
      4   ,constraint PERSONS_PK primary key (ID)
      5  );
    Table created.
    SQL> create or replace type T_NUMBER_ARRAY as table of number;
      2  /
    Type created.
    SQL> create or replace procedure P_MRGTS2 (P_ID  PERSONS.ID%type)
      2  is
      3    L_IDS  T_NUMBER_ARRAY;
      4  begin
      5    L_IDS := T_NUMBER_ARRAY(P_ID);
      6    merge into PERSONS P using (select * from table(L_IDS)) D on (
      7      P.ID = D.COLUMN_VALUE
      8    )
      9    when matched then update
    10      set SURNAME = 'Updated'
    11    when not matched then
    12      insert (
    13        ID
    14       ,SURNAME
    15      )
    16      values (
    17        D.COLUMN_VALUE
    18       ,'Inserted'
    19      );
    20  end;
    21  /
    Procedure created.
    SQL> exec P_MRGTS2(1)
    BEGIN P_MRGTS2(1,'Avi'); END;
    ERROR at line 1:
    ORA-22905: cannot access rows from a non-nested table item
    ORA-06512: at "OPS$AABRAMI.P_MRGTS2", line 9
    ORA-06512: at line 1However, the same code on Oracle 10g Release 10.2.0.1.0 on SUN Solaris 9 works.
    Is there any way to make it work on Oracle 9i?
    One way I found is the following:
    procedure P_MRGTST (P_ID  PERSONS.ID%type)
    is
      L_IDS  T_NUMBER_ARRAY;
    begin
      L_IDS := T_NUMBER_ARRAY(P_ID);
      forall I in L_IDS.first..L_IDS.last
        merge into PERSONS P using DUAL D on (
          P.ID = L_IDS(I)
        when matched then update
          set SURNAME = 'Updated'
        when not matched then
          insert (
            ID
           ,SURNAME
          values (
            L_IDS(I)
           ,'Inserted'
    end;On Oracle 10g there is negligible difference in time taken to execute both procedures, as displayed in SQL*Plus when issuing:
    set timing onIs there something that makes one of the procedures preferrable over the other?
    Thanks,
    Avi.

    Is there any way to make it work on Oracle 9i?
    michaels>  select * from v$version
    BANNER                                                         
    Oracle9i Enterprise Edition Release 9.2.0.8.0 - 64bit Production
    PL/SQL Release 9.2.0.8.0 - Production                          
    CORE     9.2.0.8.0     Production                                      
    TNS for HPUX: Version 9.2.0.8.0 - Production                   
    NLSRTL Version 9.2.0.8.0 - Production                          
    michaels>  create table persons (
        id  number(9)
           ,surname  varchar2(50)
              ,constraint persons_pk primary key (id)    )
    Table created.
    michaels>  create or replace type t_number_array as table of number;
    Type created.
    michaels>  create or replace procedure p_mrgts2 (p_id persons.id%type)
    is
       l_ids   t_number_array;
    begin
       l_ids := t_number_array (p_id);
       merge into persons p
          using (select * from table (cast (l_ids as t_number_array))) d
          on (p.id = d.column_value)
          when matched then
             update set surname = 'Updated'
          when not matched then
             insert (id, surname) values (d.column_value, 'Inserted');
    end p_mrgts2;
    Procedure created.
    michaels>  exec p_mrgts2(1)
    PL/SQL procedure successfully completed.
    michaels>  select * from persons
            ID SURNAME                                          
             1 Inserted                                         
    1 row selected.

  • Open sys_refcursor for select from table variable?

    Hi,
    I've got a challenge for you! :-)
    I've got a procedure that has a lot of logic to determine what data should be loaded into a table variable. Because of various application constraints, i can not create a global temporary table. Instead, i'd like to create a table variable and populate it with stuff as i go through the procedure.
    The end result of the procedure is that i must be able to pass the results back as a sys_refcursor. This is a requirement that is beyond my control as well.
    Is there a way to make this sort of procedure work?
    Create Or Replace Procedure Xtst
    Mu_Cur In Out Sys_Refcursor
    Is
    Type Xdmlrectype Is Record (Col1 Varchar2(66));
    Type Xdmltype Is Table Of Xdmlrectype;
    Rtn Xdmltype;
    Begin
    Select Internal_Id Bulk Collect Into Rtn From Zc_State;
    open mu_cur for select col1 from table(rtn);
    end;
    11/42 PLS-00642: local collection types not allowed in SQL statements
    11/36 PL/SQL: ORA-22905: cannot access rows from a non-nested table item
    11/19 PL/SQL: SQL Statement ignored
    Show Errors;

    Not anything i'd want to personally implement.
    But for educational purposes only of course....
    create table this_will_be_gross
       column1 number,
       column2 varchar2(30)
    insert into this_will_be_gross values (1, 'begin the ugliness');
    insert into this_will_be_gross values (2, 'end the ugliness');
    variable x refcursor;
    ME_XE?
    declare
       Rtn sys.ODCIVARCHAR2LIST;
    BEGIN
       SELECT
          column1 || '-' || column2 Bulk Collect
       INTO
          Rtn
       FROM
          this_will_be_gross;
       OPEN :x FOR
       SELECT 
          regexp_substr (column_value, '[^-]+', 1, 1) as column1,
          regexp_substr (column_value, '[^-]+', 1, 2) as column2      
       FROM TABLE(CAST(rtn AS sys.ODCIVARCHAR2LIST));
    end;
    17  /
    PL/SQL procedure successfully completed.
    Elapsed: 00:00:00.09
    ME_XE?
    ME_XE?print :x
    COLUMN1                        COLUMN2
    1                              begin the ugliness
    2                              end the ugliness
    2 rows selected.
    Elapsed: 00:00:00.11In the above example i 'knew' that a hypen was a safe character to use to break up my data elements (as it would not be found anywhere in the data itself).
    I would strongly encourage you not to implement something like this. I realize it's tempting when you are working in strict environments where it can take a serious battle to get structures like temporary tables or SQL Types created, but that's really the proper approach to be taking.

Maybe you are looking for

  • My iPad Air will suddenly quit in the middle of an application and return to home screen.

    Can anyone tell me why my iPad Air will suddenly stop in the middle of an application, (usually a game), and return to my home screen?  Thanks

  • Currency format in excel

    I am using file_oper to create an excel report. There are some decimal fields that are not being displayed properly. How do I format these fields so they are displayed properly? These are currency fields. ex: 12323.45 34.4 2534.674 10000.02

  • P.O rate for required on parent material

    I am using sub contracting PO for processing material. I need to send parent material 'Á' for processing & converting it into child material 'B'. But I want P.O rate to be based on qty processed of parent material. In sub contracting PO, I have to gi

  • How is IOS 5.01 working on IPAD1?

    My ipad is still 4.33 and my friend told me IOS 5 doesn't work smoothly on Ipad1 so that I'm still hesitating whether to upgrade it or not. What do you think? Thanks!

  • MDX substring function

    Hi all, I am trying to use select {Substring([Q1W01],1,4)} ON COLUMNS FROM [test].[db] But it throws syntax error. What am I doing wrong? Essbase 11.1.2.2 Many thanks.