Add column to user defined type based on existing table

Hello guys,
I am trying to compile my function which returns a user defined type based on existing table. Throughout the initializing process though my query returns one additional column - SCORE(1). Here is my package:
create or replace
PACKAGE STAFF_AGENCY_PKG AS
TYPE TYPE_SEEKER_TABLE IS TABLE OF TOSS.SEEKER%ROWTYPE;
FUNCTION GET_SEEKERS(IN_KEYWORD IN VARCHAR2)
RETURN TYPE_SEEKER_TABLE PIPELINED;
END STAFF_AGENCY_PKG;
create or replace
PACKAGE BODY STAFF_AGENCY_PKG
AS
FUNCTION GET_SEEKERS(IN_KEYWORD IN VARCHAR2)
RETURN TYPE_SEEKER_TABLE PIPELINED
IS
R_TBL TYPE_SEEKER_TABLE; -- to be returned
BEGIN
FOR R IN(
SELECT Seeker.SEEKER_ID,
Seeker.FIRSTNAME,
Seeker.LASTNAME,
Seeker.NATIONALITY,
Seeker.ISELIGIBLE,
Seeker.BIRTHDATE,
Seeker.ISRECIEVEEMAILS,
Seeker.HIGHESTDEGREE,
Seeker.ETHNICITY,
Seeker.GENDER,
Seeker.ISDISABILITY,
Seeker.DISABILITY,
Seeker.CV,
Seeker.PASSWORD,
Seeker.PREFFERED_CITY,
SEEKER.EMAIL,
SEEKER.JOB_PREFERENCES_ID,
SCORE(1)
FROM SEEKER Seeker
WHERE CONTAINS(CV, '<query>
<textquery lang="ENGLISH" grammar="context">' ||
GET_RELATED_CATEGORIES(IN_KEYWORD) ||
'</textquery>
<score datatype="INTEGER"/>
</query>', 1) > 0
LOOP
PIPE ROW(R); --Error(38,10): PLS-00382: expression is of wrong type
END LOOP;
RETURN;
END GET_SEEKERS;
END STAFF_AGENCY_PKG;
How do I need to amend my user type in order to suffice?
Oracle Release 11.2.0.1.0
Many thanks in advance!

>
How do I need to amend my user type in order to suffice?
>
You will need to create two new TYPEs. One that has all of the columns of the TOSS.SEEKER table and the new SCORE column and then a TYPE that is a table of the first type.
See the Example 12-22 Using a Pipelined Table Function For a Transformation in the PL/SQl language reference
http://docs.oracle.com/cd/B28359_01/appdev.111/b28370/tuning.htm#i53120
Here is the first part
-- Define the ref cursor types and function
CREATE OR REPLACE PACKAGE refcur_pkg IS
  TYPE refcur_t IS REF CURSOR RETURN employees%ROWTYPE;
  TYPE outrec_typ IS RECORD (
    var_num    NUMBER(6),
    var_char1  VARCHAR2(30),
    var_char2  VARCHAR2(30));
  TYPE outrecset IS TABLE OF outrec_typ;
FUNCTION f_trans(p refcur_t)
      RETURN outrecset PIPELINED;
END refcur_pkg;
CREATE OR REPLACE PACKAGE BODY refcur_pkg IS
  FUNCTION f_trans(p refcur_t)
   RETURN outrecset PIPELINED IS
    out_rec outrec_typ;
    in_rec  p%ROWTYPE;
  BEGINModify
  TYPE outrec_typ IS RECORD (
    var_num    NUMBER(6),
    var_char1  VARCHAR2(30),
    var_char2  VARCHAR2(30));
  TYPE outrecset IS TABLE OF outrec_typ;to include all of the columns you need. Unfortunately you will have to manually list all of the columns of the TOSS.SEEKER table. If you expect to need this same structure in other places you should create them as SQL types instead of PL/SQL types.
This example should be enough to show you how to change your code to do something similar.

Similar Messages

  • How to create a user defined type base on existing table

    Hi Everyone,
    Are there any way to create a user defined type base on existing table us as :
    CREATE OR REPLACE Type MyTable Is Table Of PART%ROWTYPE;
    where Part is a table.
    Regards,
    JDang

    Hi JDAng,
    Can't be done. %ROWTYPE is a PL/SQL construct, and as such cannot be used in SQL.
    Regards
    Peter

  • Using columns of user defined types

    Can anyone help me display data from a column within a table which is of a user defined type - a object with 4 elements .
    Discoverer wont currently display the data - it says a MAP or ORDER method is required.
    The type is declared as :
    create or replace type m_p as object
    ( m_p_id number(9),
    m_p_start number,
    m_p_end number,
    m_p_length number )
    and the table is declared as
    create table t_m_p (
    N_ID NUMBER,
    N_PL M_P,
    N_ATT VARCHAR2(1)
    What do I need to do to allow Discoverer 3.1 to display the data held in the N_PL column?
    Also : can anyone tell me if it is possible to display data in Discoverer from a thre dimensional varray? - or would I have to create a view on it?

    Discoverer does not currently allow queries to contain the extended Oracle 8 object types. The way to resolve this is to write views that present a relational view of the object structure and then build a business area based on these views
    Oracle Discoverer Team
    <BLOCKQUOTE><font size="1" face="Verdana, Arial">quote:</font><HR>Originally posted by nikstace ([email protected]):
    Can anyone help me display data from a column within a table which is of a user defined type - a object with 4 elements .
    Discoverer wont currently display the data - it says a MAP or ORDER method is required.
    The type is declared as :
    create or replace type m_p as object
    ( m_p_id number(9),
    m_p_start number,
    m_p_end number,
    m_p_length number )
    and the table is declared as
    create table t_m_p (
    N_ID NUMBER,
    N_PL M_P,
    N_ATT VARCHAR2(1)
    What do I need to do to allow Discoverer 3.1 to display the data held in the N_PL column?
    Also : can anyone tell me if it is possible to display data in Discoverer from a thre dimensional varray? - or would I have to create a view on it?<HR></BLOCKQUOTE>
    null

  • Selecting Columns with User Defined Types... in PHP

    I've looked all over google and this forum and can't find anything about this... here's what I've got:
    a User Defined Type:
    CREATE TYPE "ADDRESS" AS OBJECT (
    ADDRESS VARCHAR2(256),
    COUNTRY VARCHAR2(256),
    STATE VARCHAR2(256),
    SUBURB VARCHAR2(256),
    TOWNCITY VARCHAR2(256)
    and it is used in a column in one of my tables:
    CREATE TABLE "SUPPLIERS" (
    "ID" NUMBER,
    "USER_ID" NUMBER,
    "NAME" VARCHAR2(50),
    "ADDRESS" "ADDRESS"
    so that column "address" is of type "address". I am then able to insert a row using:
    INSERT INTO "SUPPLIERS" VALUES(1,1,'name',ADDRESS('address','country','state','suburb','town city'));
    and that all works as expected. I can select the data using iSqlPlus and get the result I expect;
    ADDRESS('address', 'country', 'state', 'suburb', 'town city')
    So here's the problem. I cannot reterieve the data as expected, using PHP. If I make a select statement on the table that excludes the ADDRESS column I get the results as expected. If the ADDRESS column is included I get an error when fetching the row:
    ORA-00932: inconsistent datatypes: expected CHAR got ADT
    I'm assuming this is because the the cell cannot be cast to a string. How can I select the row so that the ADDRESS column is returned as an object? Can I even? If I can't, I don't see the use of Object Data Types... :(
    I have found that I can select a field of the type using:
    SELECT t.ADDRESS.TOWNCITY FROM SUPPLIERS t;
    But this is not ideal, because the whole idea was that I could (potentially) change the format for, in my example, an address, and not need to alter my SQL statements.
    Any ideas??

    PHP OCI8 can currently only bind simple types. Here are two possible
    solutions.
    -- cj
    create or replace type mytype as object (myid number, mydata varchar2(20));
    show errors
    create or replace type mytabletype as table of mytype;
    show errors
    create or replace procedure mycreatedata1(outdata out mytabletype) as
    begin
      outdata := mytabletype();
      for i in 1..10 loop
        outdata.extend;
        outdata(i) := mytype(i, 'some name'||i);
      end loop;
    end;
    show errors
    -- Turn the data into a ref cursor (but PHP OCI8 doesn't use prefetching for ref cursors)
    create or replace procedure mywrapper1(rcemp out sys_refcursor) as
    data mytabletype;
    begin
      mycreatedata1(data);
      open rcemp for select * from table(cast(data as mytabletype));
    end mywrapper1;
    show errors
    -- Turn the data into two collections
    -- This might be faster than returning a ref cursor because you can
    -- use oci_bind_array_by_name() on each parameter.
    create or replace procedure mywrapper2(pempno out dbms_sql.NUMBER_table, pename out dbms_sql.VARCHAR2_table) as
    data mytabletype;
    begin
      mycreatedata1(data);
      select myid, mydata
      bulk collect into pempno, pename
      from table(cast(data as mytabletype));
    end mywrapper2;
    show errorsThen in PHP you could do:
    // Use a Ref Cursor
    $s = oci_parse($c, "begin mywrapper1(:myid); end;");
    $rc = oci_new_cursor($c);
    oci_bind_by_name($s, ':myid', $rc, -1, OCI_B_CURSOR);
    oci_execute($s);
    oci_execute($rc);
    oci_fetch_all($rc, $res);
    var_dump($res);
    // Use Collections
    $s = oci_parse($c, "begin mywrapper2(:myid, :mydata); end;");
    oci_bind_array_by_name($s, ":myid", $myid, 10, -1, SQLT_INT);
    oci_bind_array_by_name($s, ":mydata", $mydata, 10, 20, SQLT_CHR);
    oci_execute($s);
    var_dump($myid);
    var_dump($mydata);

  • Data retrieval from columns having user defined type

    I was learning abstract types the other day.So I created an abstract type and a table.
    create type student_ty as object
    (name varchar2(20),roll number);
    create table result(
    student student_ty,
    total number);
    I have also inserted some data.But I am having some problems with the rretrieval of data.Suppose I want to select only the roll and name of the student as described in the studen type.So I used the follwing query:-
    select student.name from result;
    But its not working.But when i'm using something like this:-
    select r.total,r.student.name from result r;
    It is working perfectly.My question is that is it a rule that oracle enforces to use an alias whenever retrieving values from a user defined datatype?.Please help.
    Thanks in advance.

    Hi,
    Good observation. As you can see with your first query, the student is considered by oracle as a alias instead of a user-defined type column which is included in your result's table.
    >
    select student.name from result;
    >That is why in this case, you really need to use an alias or you can just use the complete table name like this:
    select result.student.name from resultBut, of course, it is not recommended, using alias is much appropriate.
    Cheers.

  • How to change list's column to user defined type in sharepoint2013?

    In my SharePoint Site Collection has a one list, it contains some column of the following type text, date, multiline  etc, so here i want to change the number field into range filed(like slider <input type="range" min="0" max="100"/>
    ) so i don't know, how to do this...? 
    and I am using sharepoint2013, visual studio 2013 and SharePoint Designer

    Not sure what you mean by slider field, However, create a custom field with custom type. Refer to the following posts for more information
    https://sp2013fieldsamples.codeplex.com/
    http://social.msdn.microsoft.com/Forums/sharepoint/en-US/5c9ffbe9-122f-4afa-a910-281926e6b2c9/how-to-create-custom-field-types-for-sharepoint-2013?forum=sharepointdevelopment
    --Cheers

  • How to add a user defined constructor to an existing type?

    Hi,
    I want to alter an existing type (ORDSys.ORDVideo), where I do not have the source code of the type body. There is only a wrapped version, where I don't know, how to alter it.
    Because the existing functions use the constructor of the original type I can't simply add new attributes. That's why I want to add a new user defined constructor which equals the old built in.
    Is there any way to do this, without having the bodys source code?
    Thanks, Christian

    Unfortunately, No.
    <quote source="oracle_documentation">
    Oracle interMedia describes the ORDVideo object type, which supports the storage and management of video data.
    </quote>
    It comes along with the Oracle interMedia and the modifications could not be performed by the customer.
    You could however, try to create a derived type based on this type and add your constructors/functions on top.

  • Access result set in user define type of table

    here is the situation. I have a stored procedure that dequeues messages of a AQ and passes them as an OUT parameter in a collection of a user defined type. The same type used to define the queues. The java code executes properly but seems like we don't/can't access the result set. We don't receive any erros but don't know how to access the results. I've included relevant parts of the problem.
    I know this should be doable but........Can someone please tell us what we are doing wrong....thanks in advance.
    -----create object type
    create type evt_ot as object(
    table_name varchar(40),
    table_data varchar(4000));
    ---create table of object types.
    create type msg_evt_table is table of evt_ot;
    ----create queue table with object type
    begin
    DBMS_AQADM.CREATE_QUEUE_TABLE (
    Queue_table => 'etlload.aq_qtt_text',
    Queue_payload_type => 'etlload.evt_ot');
    end;
    ---create queues.
    begin
    DBMS_AQADM.CREATE_QUEUE (
    Queue_name => 'etlload.aq_text_que',
    Queue_table => 'etlload.aq_qtt_text');
    end;
    Rem
    Rem Starting the queues and enable both enqueue and dequeue
    Rem
    EXECUTE DBMS_AQADM.START_QUEUE (Queue_name => 'etlload.aq_text_que');
    ----create procedure to dequeue an array and pass it OUT using msg_evt_table ---type collection.
    create or replace procedure test_aq_q (
    i_array_size in number ,
    o_array_size out number ,
    text1 out msg_evt_table) is
    begin
    DECLARE
    message_properties_array dbms_aq.message_properties_array_t :=
    dbms_aq.message_properties_array_t();
    msgid_array dbms_aq.msgid_array_t;
    dequeue_options dbms_aq.dequeue_options_t;
    message etlload.msg_evt_table;
    id pls_integer := 0;
    retval pls_integer := 0;
    total_retval pls_integer := 0;
    ctr number :=0;
    havedata boolean :=true;
    java_exp exception;
    no_messages exception;
    pragma EXCEPTION_INIT (java_exp, -24197);
    pragma exception_init (no_messages, -25228);
    BEGIN
    DBMS_OUTPUT.ENABLE (20000);
    dequeue_options.wait :=0;
    dequeue_options.correlation := 'event' ;
    id := i_array_size;
    -- Dequeue this message from AQ queue using DBMS_AQ package
    begin
    retval := dbms_aq.dequeue_array(
    queue_name => 'etlload.aq_text_que',
    dequeue_options => dequeue_options,
    array_size => id,
    message_properties_array => message_properties_array,
    payload_array => message,
    msgid_array => msgid_array);
    text1 := message;
    o_array_size := retval;
    EXCEPTION
    WHEN java_exp THEN
    dbms_output.put_line('exception information:');
    WHEN no_messages THEN
    havedata := false;
    o_array_size := 0;
    end;
    end;
    END;
    ----below is the java code....
    import java.sql.Connection;
    import java.sql.DriverManager;
    import java.sql.ResultSet;
    import java.sql.SQLException;
    import java.sql.Struct;
    import oracle.jdbc.driver.OracleCallableStatement;
    import oracle.jdbc.driver.OracleTypes;
    public class TestOracleArray {
         private final String SQL = "{call etlload.test_aq_q(?,?,?)}";//array size, var name for return value, MessageEventTable
         private final String driverClass = "oracle.jdbc.driver.OracleDriver";
         private final String serverName = "OurServerName";
         private final String port = "1500";
         private final String sid = "OurSid";
         private final String userId = "OurUser";
         private final String pwd = "OurPwd";
         Connection conn = null;
         public static void main(String[] args){
              TestOracleArray toa = new TestOracleArray();
              try {
                   toa.go();
              } catch (InstantiationException e) {
                   // TODO Auto-generated catch block
                   e.printStackTrace();
              } catch (IllegalAccessException e) {
                   // TODO Auto-generated catch block
                   e.printStackTrace();
              } catch (ClassNotFoundException e) {
                   // TODO Auto-generated catch block
                   e.printStackTrace();
              } catch (SQLException e) {
                   // TODO Auto-generated catch block
                   e.printStackTrace();
         private void go() throws InstantiationException, IllegalAccessException, ClassNotFoundException, SQLException{
              Class.forName(driverClass).newInstance();
              String url = "jdbc:oracle:thin:@"+serverName+":"+port+":"+sid;
              conn = DriverManager.getConnection(url,userId,pwd);
              OracleCallableStatement stmt = (OracleCallableStatement)conn.prepareCall(SQL);
              //set 1 input
              stmt.setInt(1, 50);
              //register out 1
              stmt.registerOutParameter(2, OracleTypes.NUMERIC);
              //register out 2
              stmt.registerOutParameter(3, OracleTypes.ARRAY, "MSG_EVT_TABLE");
              * This code returns a non-null ResultSet but there is no data in the ResultSet
              * ResultSet rs = stmt.executeQuery();
              * rs.close();
              * Tried all sorts of combinations of getXXXX(1);
              * All return the same error Message: Invalid column index
              * So it appears that the execute statment returns no data.
              stmt.execute();
              Struct myObject = (Struct)stmt.getObject(1);
              stmt.close();
              conn.close();
    }

    Hi,
    Sorry but I'd refer you to the following sections (and code samples/snippets) in my book:
    Mapping User-Defined Object Types (AD) to oracle.sql.STRUCT in section 3.3, shows how to pass user defined types as IN, OUT,IN/OUT
    JMS over Streams/AQ in the Database: shows how to consume AQ
    message paylod in section 4.2.4
    CorporateOnine, in section 17.2, show how to exchanges user defined type objects b/w AQ and JMS
    All these will hopefully help you achieve what you are trying to do.
    Kuassi

  • Accessing User Defined Types

    We have recently updated our libraries to the latest version (2.102.2.20) - and have lost access to the critical objects and methods that were accessing our User Defined Types on Oracle.
    In particular, this code:
    OracleUdtDescriptor descriptor = OracleUdtDescriptor.GetOracleUdtDescriptor((OracleConnection)conn, "MY_USER.MYTYPE");
    OracleArray items = new OracleArray(descriptor);
    foreach (string s in testArrayItems)
    items.Append(s);
    IDbDataParameter itemsParam = cmd.OracleParameters.Add("items", OracleDbType.VArray, items, ParameterDirection.Input);
    simply doesn't work anymore. The 'OracleUdtDescriptor' and 'OracleArray' references no longer exist. This has brought all development on a critical application to a halt. (Doesn't it always.)
    How can I get the same functionality using the new version (2.102.2.20) of the Oracle.DataAccess library?

    Hi,
    Here's what I was referring to... say you wanted to execute the same procedure from PLSQL via an anonymous block. Execute the same anonymous block via ODP.NET.
    Here's a simple dumb example that passes an object type to a stored procedure, hope it helps. Hokey example, but hopefully points out what I was trying to say.
    Greg
    SQL
    ========
    create or replace type person_typ as object (name varchar2(50), age number(4))
    create table person_tab(col1 number, col2 person_typ);
    create or replace procedure insert_person_proc(v1 in number, v2 in person_typ) as
    begin
    insert into person_tab values(v1,v2);
    end;
    You could execute that via PLSQL as follows
    =================================
    declare
      myperson person_typ;
    begin
      myperson := person_typ('melody',5);
      insert_person_proc(1,myperson);
    end;
    /And do the same thing via ODP.NET
    =============================
    using System;
    using System.Data;
    using Oracle.DataAccess.Client;
    class Program
        static void Main(string[] args)
            using (OracleConnection con = new OracleConnection("data source=orcl;user id=scott;password=tiger"))
                con.Open();
                using (OracleCommand cmd = new OracleCommand("",con))
                    string strsql = "declare " +
                                    "myperson person_typ; " +
                                    "begin " +
                                    "myperson := person_typ(:1,:2); " +
                                    "insert_person(:3,myperson); " +
                                    "end; ";
                    cmd.CommandText = strsql;
                    cmd.Parameters.Add(new OracleParameter("", "Melody"));
                    cmd.Parameters.Add(new OracleParameter("", 5));
                    cmd.Parameters.Add(new OracleParameter("", 1));
                    cmd.ExecuteNonQuery();
    }

  • View Object with User Defined Type input

    I am trying to use a View Object with a query that requires a user defined object as an input parameter.
    I have the query working with a PreparedStatement, but would like to use a View Object.
    When I use the PreparedStatement, I prepare the user defined type data like this:
    // get the data into an object array
    Object[] wSRecObjArr = wSRec.getObjectArray();
    // set up rec descriptor
    StructDescriptor WSRecDescriptor = StructDescriptor.createDescriptor("WS_REC",conn);
    // populate the record struct
    STRUCT wSRecStruct = new STRUCT(WSRecDescriptor,conn,wSRecObjArr);
    Then I can use this in the PreparedStatement like this:
    OraclePreparedStatement stat = null;
    ResultSet rs = null;
    stat = (OraclePreparedStatement)conn.prepareStatement("Select test_pkg.test_function(?) FROM DUAL");
    stat.setSTRUCT(1, wSRecStruct);
    rs = stat.executeQuery();
    I would like to do the same process with a View Object instead of the PreparedStatement.
    My question is "How do I create the input objects"?
    I obtain the View Object from the Application Module using findViewObject(). I don't actually have a connection object to pass into the StructDescriptor.createDescriptor method.
    I have tried just using Java Object Arrays (Object[]) to pass the data, but that gave an error:
    oracle.jbo.SQLStmtException: JBO-27122: SQL error during statement preparation.
    Any help or pointers are greatly appreciated.
    Thank you.
    Edited by: 942120 on May 1, 2013 8:45 AM
    Edited by: 942120 on May 1, 2013 8:46 AM
    Edited by: 942120 on May 1, 2013 9:05 AM
    Edited by: 942120 on May 1, 2013 9:06 AM

    Custom domains are the way to go.
    When I try to pass custom domains that represent my user defined types - it works.
    However, one of the functions requires a table of a user defined type be passed in.
    I tried creating a domain of the table type. It forces me to add a field during creation (in JDEV), so I tried adding a field of type Array of Element of the domain representing the user defined type.
    I populate the table by setting the field I created, but the table is empty in PL/SQL (TEST_TAB.COUNT = 0).
    I also tried passing the oracle.jbo.domain.Array object, but that produced an error:
    java.sql.SQLException: ORA-06553: PLS-306: wrong number or types of arguments in call
    I also tried passing Object[], but that produced an error:
    oracle.jbo.SQLStmtException: JBO-27122: SQL error during statement preparation.
    How do I properly create, and pass an domain that represents a table of a user defined type?
    When I use a OraclePreparedStatement, I can pass a oracle.sql.ARRAY using stat.setARRAY.
    Thank you for the help you have provided, and any future advice.
    JDEV 10.1.2.3
    JDBC 10.2.0.5
    Edited by: 942120 on May 13, 2013 7:13 AM
    Edited by: 942120 on May 13, 2013 7:16 AM

  • Cannot SELECT into a user-defined type variable

    Hi All,
    Oracle 11.2 on Linux.
    See the steps below. I am not able to insert/select into a TYPE variable. I do not want to do a TABLE declaration in my PL/SQL block, but want to use a user defined type. Is it possible ?
    SQL> create or replace type sample_obj_rec as object
      2  (
      3     object_id    number,
      4     object_name  varchar2(32),
      5     object_type  varchar2(32)
      6  );
      7  /
    Type created.
    SQL> create or replace type sample_obj_tab as table of sample_obj_rec ;
      2  /
    Type created.
    -- ------------   CASE 1 ---------------------
    SQL> declare
      2      v_tab   sample_obj_tab := sample_obj_tab() ;
      3  begin
      4      select object_id, object_name, object_type
      5      bulk   collect into v_tab
      6      from   dba_objects
      7      where  rownum < 11 ;
      8  end ;
      9  /
        from   dba_objects
    ERROR at line 6:
    ORA-06550: line 6, column 5:
    PL/SQL: ORA-00947: not enough values
    ORA-06550: line 4, column 5:
    PL/SQL: SQL Statement ignored
    -- ------------   CASE 2 ---------------------
    SQL> declare
      2      v_rec   sample_obj_rec;
      3  begin
      4      select object_id, object_name, object_type
      5      into   v_rec
      6      from   dba_objects
      7      where  rownum = 1;
      8  end ;
      9  /
        from   dba_objects
    ERROR at line 6:
    ORA-06550: line 6, column 5:
    PL/SQL: ORA-00947: not enough values
    ORA-06550: line 4, column 5:
    PL/SQL: SQL Statement ignoredWhat is the issue with both the above cases? what am I missing here?
    Thanks in advance.

    One small detail in the SELECT.
    SQL> create or replace type sample_obj_rec as object
      2  (object_id    number,
      3   object_name  varchar2(32),
      4   object_type  varchar2(32));
      5  /
    Type created.
    SQL>
    SQL> create or replace type sample_obj_tab as table of sample_obj_rec ;
      2  /
    Type created.
    SQL>
    SQL> declare
      2     v_tab   sample_obj_tab := sample_obj_tab() ;
      3  begin
      4     select sample_obj_rec(object_id, object_name, object_type)
      5     bulk   collect into v_tab
      6     from   dba_objects
      7     where  rownum < 11 ;
      8  end ;
      9  /
    PL/SQL procedure successfully completed.
    SQL>

  • Create user defined type under SQL type

    Hello guys,
    I have a table PART_NEEDED and a table function which returns table of PART_NEEDED%ROWTYPE. This works fine but if I try to create new user defined type with with the same attributes as PART_NEEDED and pipe the rows into table of that type I am getting an inconsistency of types error - Error(30,16): PLS-00382: expression is of wrong type.
    Please refer to the script below. I appreciate any help!
    CREATE TABLE "TOSS"."PART_NEEDED"
    "PART_NEEDED_ID" NUMBER NOT NULL ENABLE,
    "TYPE_OF_PART_NEEDS_ID" NUMBER,
    "TYPE_OF_PART_IS_NEEDED_ID" NUMBER,
    "AMOUNT" NUMBER
    SEGMENT CREATION IMMEDIATE PCTFREE 10 PCTUSED 40 INITRANS 1 MAXTRANS 255 NOCOMPRESS LOGGING STORAGE
    INITIAL 65536 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645 PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1 BUFFER_POOL DEFAULT FLASH_CACHE DEFAULT CELL_FLASH_CACHE DEFAULT
    TABLESPACE "USERS" ;
    CREATE OR REPLACE TYPE "TYPE_PART_NEEDED" AS OBJECT
    ID NUMBER,
    PART_ID NUMBER,
    SUB_PART_ID NUMBER,
    AMOUNT NUMBER
    create or replace package KOLEV_ADMIN_PKG as
    TYPE TYPE_PART_NEEDED_TBL IS TABLE OF TOSS.TYPE_PART_NEEDED; -- if the type here is PART_NEEDED%ROWTYPE it works perfectly fine
    FUNCTION GET_SUBPARTS (IN_PART_ID IN NUMBER)
    RETURN TYPE_PART_NEEDED_TBL PIPELINED;
    end;
    CREATE OR REPLACE PACKAGE BODY "KOLEV_ADMIN_PKG" AS
    FUNCTION GET_SUBPARTS (IN_PART_ID IN NUMBER)
    RETURN TYPE_PART_NEEDED_TBL PIPELINED
    IS
    R_TBL TYPE_PART_NEEDED_TBL; -- To be returned
    BEGIN
    FOR R IN (
    WITH
    SUBPARTS(ID, PART_ID, SUBPART_ID, AMOUNT) AS
    SELECT PART_NEEDED_ID, TYPE_OF_PART_NEEDS_ID, TYPE_OF_PART_IS_NEEDED_ID, AMOUNT
    FROM PART_NEEDED
    WHERE TYPE_OF_PART_NEEDS_ID = IN_PART_ID
    UNION ALL
    SELECT PN.PART_NEEDED_ID, PN.TYPE_OF_PART_NEEDS_ID, PN.TYPE_OF_PART_IS_NEEDED_ID, PN.AMOUNT
    FROM SUBPARTS SP, PART_NEEDED PN
    WHERE PN.TYPE_OF_PART_NEEDS_ID = SP.SUBPART_ID
    SELECT SP.ID, SP.PART_ID, SP.SUBPART_ID, SP.AMOUNT
    FROM SUBPARTS SP
    ORDER BY PART_ID
    LOOP
    PIPE ROW(R); -- Error(30,16): PLS-00382: expression is of wrong type
    END LOOP;
    RETURN;
    END GET_SUBPARTS;
    END "KOLEV_ADMIN_PKG";
    INSERT INTO "TOSS"."PART_NEEDED" (PART_NEEDED_ID, TYPE_OF_PART_NEEDS_ID, TYPE_OF_PART_IS_NEEDED_ID, AMOUNT) VALUES ('4', '2', '3', '2')
    INSERT INTO "TOSS"."PART_NEEDED" (PART_NEEDED_ID, TYPE_OF_PART_NEEDS_ID, TYPE_OF_PART_IS_NEEDED_ID, AMOUNT) VALUES ('5', '3', '1', '2')
    INSERT INTO "TOSS"."PART_NEEDED" (PART_NEEDED_ID, TYPE_OF_PART_NEEDS_ID, TYPE_OF_PART_IS_NEEDED_ID, AMOUNT) VALUES ('3', '2', '1', '4')
    INSERT INTO "TOSS"."PART_NEEDED" (PART_NEEDED_ID, TYPE_OF_PART_NEEDS_ID, TYPE_OF_PART_IS_NEEDED_ID, AMOUNT) VALUES ('17', '3', '4', '1')
    Database Release 11.2.0.1.0
    I want this functionality because I need to make some joins and add descriptions for each part. Now this table PART_NEEDED contains only IDs - many to many.
    Regards!
    Edited by: Todor Kolev on Mar 3, 2012 12:47 PM

    CREATE OR REPLACE
      PACKAGE BODY KOLEV_ADMIN_PKG
        AS
          FUNCTION GET_SUBPARTS (IN_PART_ID IN NUMBER)
            RETURN TYPE_PART_NEEDED_TBL PIPELINED
            IS
            BEGIN
                FOR R IN (
                          WITH SUBPARTS(ID, PART_ID, SUBPART_ID, AMOUNT)
                            AS (
                                 SELECT  PART_NEEDED_ID,
                                         TYPE_OF_PART_NEEDS_ID,
                                         TYPE_OF_PART_IS_NEEDED_ID,
                                         AMOUNT
                                   FROM  PART_NEEDED
                                   WHERE TYPE_OF_PART_NEEDS_ID = IN_PART_ID
                                UNION ALL
                                 SELECT  PN.PART_NEEDED_ID,
                                         PN.TYPE_OF_PART_NEEDS_ID,
                                         PN.TYPE_OF_PART_IS_NEEDED_ID,
                                         PN.AMOUNT
                                   FROM  SUBPARTS SP,
                                         PART_NEEDED PN
                                   WHERE PN.TYPE_OF_PART_NEEDS_ID = SP.SUBPART_ID
                          SELECT  TYPE_PART_NEEDED(
                                                   SP.ID,
                                                   SP.PART_ID,
                                                   SP.SUBPART_ID,
                                                   SP.AMOUNT
                                                  ) O
                            FROM  SUBPARTS SP
                            ORDER BY PART_ID
                         ) LOOP
                  PIPE ROW(R.O);
                END LOOP;
                RETURN;
          END GET_SUBPARTS;
    END KOLEV_ADMIN_PKG;
    /SY.

  • Create user-defined type

    Can I create a user-defined type with a range between 1 to 10.
    e.g. insert into table values (udt(11)) will prompt an error

    You will need to either provide different names for the
    constraints or let the system provide the names, like this:
    SET     ECHO OFF
    SET     FEEDBACK OFF
    SET     PAGESIZE 0
    SPOOL   add_constraints.sql
    SELECT 'ALTER TABLE ' || table_name
       || ' ADD CHECK (udt BETWEEN 1 AND 10);'
    FROM    user_tab_columns
    WHERE   column_name = 'UDT';
    SPOOL   OFF
    SET     PAGESIZE 24
    SET     FEEDBACK ON
    SET     ECHO ON
    START   add_constraints

  • Querying user-defined types

    I have a table in which one of the columns is a user-defined datatype:
    SQL> describe my_table
    USER_DATA    MYTYPEThe type "MYTYPE" is a simple object that contains one field: a CLOB called MESSAGE:
    SQL> describe mytype
    Name       Null?    Type
    MESSAGE          CLOBWhen I do a "select * ..." from this table, the column USER_DATA is displayed as "MYTYPE(oracle.sql.CLOB@898c2d)"
    I know that for CLOB and BLOB fields, SQL Developer will let me double click the value and view the contents. But for a user-defined type like this that contains a field, I cannot browse into the data members of the type. I find myself wanting to do something like a "select user_data.message from my_table", but this is not valid syntax. Is there a way to query a specific data member of this user-defined type with the rest of the columns in the table so that I can be shown the CLOB member instead of a representation of the object? If not, is there a way to configure SQL Developer to allow me to browse the data members of user-defined types? TOAD has a feature like this but I would like to use SQL Developer exclusively and this is one table I must work with regularly.

    Just to back up a previous post:
    sqldeveloper 1.5.5.59.69 against 10.2 (Express Edition)
    desc r2
    input:
    select r.message from r2; --fails
    select r2.r.message from r2; --fails
    select this.r.message from r2 this; --succeeds
    output:
    desc r2
    Name Null Type
    R REALLY_CLOB()
    Error starting at line 1 in command:
    select r.message from r2
    Error at Command Line:1 Column:7
    Error report:
    SQL Error: ORA-00904: "R"."MESSAGE": invalid identifier
    00904. 00000 - "%s: invalid identifier"
    *Cause:   
    *Action:
    Error starting at line 2 in command:
    select r2.r.message from r2
    Error at Command Line:2 Column:7
    Error report:
    SQL Error: ORA-00904: "R2"."R"."MESSAGE": invalid identifier
    00904. 00000 - "%s: invalid identifier"
    *Cause:   
    *Action:
    R.MESSAGE
    (CLOB)
    (CLOB)
    (CLOB) start of clob
    3 rows selected

  • Calling Oracle stored procedure with out param of user define type from Entity Framework 5 with code first

    Guys i am using Entity Framework 5 code first (I am not using edmx) with Oracle and all works good, Now i am trying to get data from stored procedure which is under package but stored procedure have out param which is user define type, Now my question is
    how i will call stored procedure from entity framework
    Thanks in advance.

    I agree with you, but issue is we have lots of existing store procedure, which we need to call where damn required. I am sure those will be few but still i need to find out.
    If you think you are going to get existing MS Stored Procedures  or Oracle Packages that had nothing to do with the ORM previously to work that are not geared to do simple CRUD operations with the ORM and the database tables, you have a rude awakening
    coming that's for sure. You had better look into using ADO.NET and Oracle Command objects and call those Oracle Packages by those means and use a datareader.
    You could use the EF backdoor, call Oracle Command object and use the Packages,  if that's even possible, just like you can use MS SQL Server Stored Procedures or in-line T-SQL via the EF backdoor.
    That's about your best shot.
    http://blogs.msdn.com/b/alexj/archive/2009/11/07/tip-41-how-to-execute-t-sql-directly-against-the-database.aspx

Maybe you are looking for

  • Variable not expanding in command, unsure why

    Hello, I have a relatively straightforward problem in a script I am making, it has to do with a variable not expanding properly but I am unsure why and not sure what else I can do to further debug the issue, any advise would be appreciated. Basically

  • Slim Java Edition OR Full Java Edition?

    I've been struggling to get the Flightlist demo to work with Slim Java Edition (SAP NetWeaver 04 SP11) with added "lcrserver.ear in "C:\usr\sap\J2E\JC00\SDM\root\origin\sap.com\com.sap.lcr\SAP AG\6.4011.00.0000.20050127171551.0000" to be able to use

  • Article 19363100 0500  blocked

    Dear Friends, There is a problem with Article (Material) when user is creating a vendor invoice. At the time of invoice user getting the below error message. "Article 19363100 0500  blocked" Message no. M8573 But I have checked the Article master whi

  • Smart Album's jumping around after edits

    Hello, I'm working on organizing my large library of images and I've created a few simple smart albums to group images by date so that it is easier for me to categorize them. These can be rather large smart albums - 1,000 - 2,000 images. Everything w

  • Playing unchecked music

    I have an iPod Nano, so I'm limited to choosing about 7.45GB of music to put on it (somewhere in there, I got cheated out of 550MB of memory...). So, I click the box that says "only sync checked items." It works great, except that when I'm listening