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

Similar Messages

  • 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.

  • Error when creating user defined TYPE

    Hi
    I have an object type created as follows
    create type emp_add is object(empno number(3),street varchar2(50),zipcode number(6));
    when I create a type based on the Object created above using
    create type add_rec is emp_add;
    I am getting compilation error
    SQL> sho err
    Errors for TYPE ADD_REC:
    LINE/COL ERROR
    1/17 PLS-00103: Encountered the symbol "EMP_ADD" when expecting one of
    the following:
    array VARRAY_ table object fixed varying opaque sparse
    How can I get rid of this error.I am a Beginner in Oracle database development.
    Thanks in advance

    Do this ->
    satyaki>
    satyaki>create type emp_add is object(empno number(3),street varchar2(50),zipcode number(6));
      2  /
    Type created.
    Elapsed: 00:00:07.77
    satyaki>
    satyaki>create or replace type add_rec as table of emp_add;
      2  /
    Type created.
    Elapsed: 00:00:00.96
    satyaki>
    satyaki>Regards.
    Satyaki De.

  • Object Diagrams that support user define type (create type....and subtypes

    Hello it would be very nice to be able to use user define types in a diagram, at this time oracle, ibm db2 9 and sql server 2005 suport sql ansi 2003 and to use all this potential we have to take tecnology foward. My sugestion is create object diagram that can help design all this funtionability, rational rose has the oracle8 addin this will give you an exact idea of what i am asking.
    Thanks for your atention and let me know if you are planing to do this.
    Perhaps this is not the right forum please tell me where I can send this as a future requests

    JDeveloper has a UML class diagram with transformation into a Java class diagram - are you looking for anything beyond that?

  • 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

  • How to create user defined button in alv report

    how to create user defined button in alv report
    thnks in advance.

    Hi,
    U can define it the the PF-STATUS ( Menu for ALV ).
    For that u have to define it in the EVENTCAT.
    form z_eventcat  using    p_i_eventcat type slis_t_event.
      data: i_event type slis_alv_event.
      call function 'REUSE_ALV_EVENTS_GET'
        exporting
          i_list_type     = 0
        importing
          et_events       = p_i_eventcat
        exceptions
          list_type_wrong = 1
          others          = 2.
      if sy-subrc <> 0.
        message id sy-msgid type sy-msgty number sy-msgno
                with sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
      endif.
      clear i_event.
      read table p_i_eventcat with key name = slis_ev_top_of_page into
      i_event.
      if sy-subrc = 0.
        move 'TOP_OF_PAGE' to i_event-form.
        append i_event to p_i_eventcat.
      endif.
      read table p_i_eventcat with key name = slis_ev_pf_status_set into i_event.
      if sy-subrc = 0.
        move 'SET_PF_STATUS' to i_event-form.
        append i_event to p_i_eventcat.
      endif.
      clear i_event.
      read table p_i_eventcat into i_event with key name = slis_ev_user_command .
      if sy-subrc = 0.
        move 'USER_COMMAND' to i_event-form.
        append i_event to p_i_eventcat.
      endif.
    And in the DISPLAY
    call function 'REUSE_ALV_GRID_DISPLAY'
       exporting
         i_callback_program                = v_progname
         i_callback_pf_status_set          = 'SET_PF_STATUS'
         i_callback_user_command           = 'USER_COMMAND'
         i_callback_top_of_page            = 'TOP_OF_PAGE'
         i_grid_title                      = v_gridtitle
         i_save                            = 'A'
         is_layout                         = i_layout
         it_fieldcat                       = i_fieldcat[]
         it_sort                           = i_sortinfo
         it_events                         = i_eventcat
    IMPORTING
      E_EXIT_CAUSED_BY_CALLER           =
      ES_EXIT_CAUSED_BY_USER            =
        tables
          t_outtab                          = it_final
       exceptions
         program_error                     = 1
         others                            = 2
      if sy-subrc <> 0.
        message id sy-msgid type sy-msgty number sy-msgno
                with sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
      endif.
    *MENU SETTINGS.
    form set_pf_status using rt_extab type slis_t_extab.
      set pf-status 'ALV_MENU'.
    endform.                    "SET_PF_STATUS
    endform.                    " Z_EVENTCAT
    Now double click on ALV MENU nad u can create a button in the application bar.
    Regards,
    Pritha.

  • 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

  • Table OF user defined type in c#

    Hello
    I am running C# using Oracle (PL/SQL, provider ODP.NET
    11.1.0.6.20) and I have a procedure which at the moment returns a table of
    records. The code below demonstrates this.
    TYPE R_OutData_tab IS RECORD ( ... );
    TYPE OutData_tab IS TABLE OF R_OutData_tab INDEX BY BINARY_INTEGER;
    PROCEDURE PROPERTY_GET (tOutData OUT <packagename>.OutData_tab);
    Since .NET doesn't support Oracle records I'm looking into rewriting the
    procedure so that it returns a table of a user defined type instead. The
    code below demonstrates this.
    create type person_type as object (name varchar2(30), address varchar2(60),
    age varchar2(3));
    TYPE person_table IS TABLE OF odp_obj1_sample_person_type;
    PROCEDURE PERSONS_GET(out_persons OUT person_table);
    I know how to handle a single user-defined type in .NET returned from a
    Oralce procedure but what I need to do now is to receive a or pass table of a user
    defined type using procedure. Is this supported in .NET?

    Dear ,
    I have posted a similar kind of reply in one of the thread  which may help u defining the User Defined Tabel /Filed .Just check this Out :
    For cm25/CM21 : Assuming that you have all the other set up for Capacity Requirement in place , please note the belwo steps for layout design for CM25 OR cm21 or cm22( all you will be used same overall profile )
    1.Make sure that you have proper Overall profile defined in OPD0-Define Overall profile .Here u will define Time Profile , Startegy prfoile . Lay out Profile etc .
    2.To paint your layout your soultion is to Goto -CY38-Pop down the menu -Select the Lay out Key which have been used as lay out -Goto Change Mode (Pencil symbol)-Now you will find the fields are high ligheted as per CM25 dipaly in a sequnce -You can un chekcde the Filed like Operation , Operation text , Setup what ever you do not want to show in Order Pool and Hit SAVE butotn and come back .
    CM25 --> Settings --> Display Profiles --> Planning tab.profile --> I01 --> Layout ID ( Example : 'SAPSFCLA05') which is Main Capacity Lay out id .
    If you goto CY38-Pop down the menu -You will find Main Capcitity Lay out Id : Example SAPSFCAS01 -Enter this lay out and chenage accordingly as I have explained in above
    Once you save this , then go back to CM25 and execute with coupe of work centres to check how is the order pool looks now .
    Refer this threade for Layout Id and option which u may need for CM25 front end
    Exception messages in CM21 or CM25
    I hope this should work
    Regards

  • 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();
    }

  • Notification with user defined type results in PLS-00306: wrong number..

    I created a user defined type TLogMessage:
    CREATE OR REPLACE TYPE TLogMessage AS OBJECT
    module VARCHAR2(4000),
    severity NUMBER,
    message VARCHAR2(4000)
    I also created a multi-consumer queue using this type as payload.
    My callback procedure in the package PK_SYST_LOGMESSAGE is defined as follows:
         PROCEDURE DefaultLoggerCallback(
              context          RAW,
              reginfo          SYS.AQ$_REG_INFO,
              descr          SYS.AQ$_DESCRIPTOR,
              payload          RAW,
              payload1     NUMBER
    Finally, I registered the callback procedure as follows:
              DBMS_AQADM.ADD_SUBSCRIBER(
                   queue_name      => QUEUE_NAME,
                   subscriber      => SYS.AQ$_AGENT(
                                            name => 'default_logger',
                                            address => NULL,
                                            protocol => NULL
              DBMS_AQ.REGISTER(
                   SYS.AQ$_REG_INFO_LIST(
                        SYS.AQ$_REG_INFO(
                             name          => QUEUE_NAME || ':default_logger',
                             namespace     => DBMS_AQ.NAMESPACE_AQ,
                             callback     => 'plsql://MTDX.PK_SYST_LOGMESSAGE.DefaultLoggerCallback',
                             context          => HEXTORAW('FF')
                   1
    However, when I put a message in the queue using this procedure:
         PROCEDURE LogMessage(
              pModule          VARCHAR2,
              pSeverity     NUMBER,
              pMessage     VARCHAR2
         IS
              vMessage               TLogMessage;
              vEnqueueOptions          DBMS_AQ.ENQUEUE_OPTIONS_T;
              vMsgProperties          DBMS_AQ.MESSAGE_PROPERTIES_T;
              vMessageHandle          RAW(16);
         BEGIN
              vMessage := TLogMessage(module => pModule, severity => pSeverity, message => pMessage);
              vEnqueueOptions.visibility := DBMS_AQ.IMMEDIATE;
              vMsgProperties.correlation := pModule;
              vMsgProperties.priority := -pSeverity;
              -- Enqueue the message to all subscribers
              DBMS_AQ.ENQUEUE(
                   queue_name               => QUEUE_NAME,
                   enqueue_options          => vEnqueueOptions,
                   message_properties     => vMsgProperties,
                   payload                    => vMessage,
                   msgid                    => vMessageHandle
         EXCEPTION
              WHEN no_subscribers THEN
                   -- No subscribers on the queue; ignore
                   NULL;
         END;
    I can see the message in the queue, by querying the queue view. I can also see that Oracle tried to call my callback procedure, because in the trace file I see the following:
    *** 2009-02-13 08:52:25.000
    *** ACTION NAME:() 2009-02-13 08:52:24.984
    *** MODULE NAME:() 2009-02-13 08:52:24.984
    *** SERVICE NAME:(SYS$USERS) 2009-02-13 08:52:24.984
    *** SESSION ID:(609.3387) 2009-02-13 08:52:24.984
    Error in PLSQL notification of msgid:4F7962FEDD3B41FA8D9538F0B38FCDD1
    Queue :"MTDX"."LOGMESSAGE_QUEUE"
    Consumer Name :DEFAULT_LOGGER
    PLSQL function :MTDX.PK_SYST_LOGMESSAGE.DefaultLoggerCallback
    : Exception Occured, Error msg:
    ORA-00604: Fout opgetreden bij recursief SQL-niveau 2.
    ORA-06550: Regel 1, kolom 7:
    PLS-00306: Onjuist aantal of type argumenten in aanroep naar 'DEFAULTLOGGERCALLBACK'..
    ORA-06550: Regel 1, kolom 7:
    PL/SQL: Statement ignored.
    So.. how many parameters does Oracle expect, and of what type? Is there any way to find out? What is wrong with my code?

    Ok, found it... I had defined the last parameter of the callback procedure as 'payload1' (that is: 'payload-ONE') instead of 'payloadl' ('payload-ELL'). It all works like a charm now.
    What a way to waste two whole days!

  • 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

  • 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.

  • How to convert Collection to user defined type in db

    Hello All,
    I am using Apex 4.1.0.00.32 and Oracle 11g.
    I have page process to store the user selected rows (keys) in a collection as follows:
    declare
       temp varchar2(4000);
       vrow number;
       begin
       apex_collection.CREATE_OR_TRUNCATE_COLLECTION('SELECTED_PERSONS');
          IF (apex_application.g_f32.COUNT > 0) THEN
               FOR ii IN 1 .. htmldb_application.g_f32.COUNT
               LOOP
                    vrow := apex_application.g_f32(ii);
                   APEX_COLLECTION.ADD_MEMBER('SELECTED_PERSONS', apex_application.g_f30(vrow));
              END LOOP;
           END IF;
    end;I need to call a database function which takes an user defined type VC_ARRAY_1 defined as:
    create or replace TYPE  "VC_ARRAY_1"  AS TABLE OF VARCHAR2(4000) How do I convert the collection to VC_ARRAY_1, so that I can call the db function?
    Thanks,
    Rose

    Hi Joel,
    Yes, the collection contains the person_ids. But, I am selecting from a function which returns a pipelined table. In Oracle Database, few user defined types and functions are defined as given below:
    create or replace TYPE  "VC_ARRAY_1"   as table of varchar2(4000)
    create or replace FUNCTION   "GET_ARRAY" ( p_array  IN   varchar2,  p_delimiter   IN   varchar2  default ':')  return  VC_ARRAY_1 PIPELINED
    create or replace TYPE   "AFFECTED_INDIVIDUAL"  as object("PERSONKEY" VARCHAR2(4000),  "FIRST_NAME" VARCHAR2(4000), "LAST_NAME" VARCHAR2(4000)… more variables)
    create or replace TYPE  "AFF_IND_TAB"  as table of  "AFFECTED_INDIVIDUAL"
    create or replace FUNCTION  GET_AFF_INDIVIDUALS(personKeys IN VC_ARRAY_1) return  AFF_IND_TAB PIPELINEDThe function GET_AFF_INDIVIDUALS uses several tables and returns pipelined table. In Apex, I have a SQL query that feeds the Report query.
    select *  from table (get_aff_individuals(get_array(:F_SELECTED_PERSONS, ',')))The application item F_SELECTED_PERSONS is a varchar2 that contains comma separated person ids. I want to replace the application item with Apex collection. Initially, I thought that I can convert the apex collection to an array of vc_array_1.
    Thanks for your time and help.
    Rose

  • Problem calling stored procedure with user-defined type of input parameters

    Hi,
    I have to call a stored procedure with IN parameters, but these are user-defined types of input parameters.
    function fv_createnews (
    pit_groups in T_APPLICATION_USER_GROUPS,
    pit_documents in T_DOCUMENTS
    return varchar2;
    TYPE T_APPLICATION_USER_GROUPS IS
    TABLE OF varchar2(500)
    INDEX BY binary_integer;
    TYPE T_DOCUMENT IS record (
    name varchar2(256)
    ,url varchar2(1024)
    ,lang varchar2(30)
    ,foldername varchar2(150)
    TYPE T_DOCUMENTS IS
    TABLE OF T_DOCUMENT
    INDEX BY binary_integer;
    How can I do this using the TopLink 10.1.3 API.
    I already found following related posts, but I still can' t make it up:
    Using VARRAYs as parameters to a Stored Procedure
    Pass Object as In/Out Parameter in Stored Procedure
    Or do I have to create my own PreparedStatement for this special stored procedure call using Java and Toplink?

    As the related posts suggest, you will need to use direct JDBC code for this.
    Also I'm not sure JDBC supports the RECORD type, so you may need to wrap your stored functions with ones that either flatten the record out, or take OBJECT types.

Maybe you are looking for