Varray

in creating a varray withe a size_limt of 15; and initializing the varray to 5 elements starting with 1....How do you show the dbms_output.put_line statement for the collection method NEXT?
Can some assist in explaining...I know it is of binary interger type. Thanks

SET SERVEROUTPUT ON
DECLARE
TYPE varray_one IS VARRAY(15) OF NUMBER;
v1 varray_one;
BEGIN
v1:=varray_one(1,2,3,4,5);
DBMS_OUTPUT.PUT_LINE('The numbers are :');
DBMS_OUTPUT.PUT_LINE(v1.FIRST);
FOR i IN 1..v1.COUNT LOOP
DBMS_OUTPUT.PUT_LINE(v1.NEXT(i));
END LOOP ;
END;
The numbers are :
1
2
3
4
5
PL/SQL procedure successfully completed.

Similar Messages

  • Bug:4705928 PLSQL: Memory leak using small varrays

    We have Oracle version 10.2.0.1.0
    We have a problem with a procedure.
    In our scenario we make use of VARRAY in the procedure to pass some filter parameters to a select distinct querying a view made on three tables.
    Unfotunately not always execution it is successful.
    Sometimes it returns wrong value (0 for the count parameter), sometimes (rarely) the server stops working.
    We suspect that this is caused by a bug fixed in versione 10.2.0.3.0
    Bug:4705928 PLSQL: Memory leak using small varrays when trimming the whole collection and inserting into it in a loop
    We suspect this becasue we made two procedure the first (spProductCount) uses a function (fnProductFilter) to calculate the values of a varray and passes them into the select,
    while in the second procedure (spProductCount2) parameters are passed directly into the statement without varray
    and there are failures only in the first procedure.
    On the other hand on another server 10.2.0.1.0 we never have this problem.
    The instance manifesting the bug runs under shared mode, while the other is under dedicated mode.
    Turning the first one to dedicated mode makes the bugs disapear.
    Unfortunately this is not a solution.
    In the sample there are the three table with all constraints, the view, tha varray custom type, the function and the two procedures.
    Is there someone that may examine our sample and tell us if the pl/sql code corresponds to the bug desciption.
    We also want to know if it's possibile that the same server running under different mode (SHARED/DEDICATED) doesn't behave the same way.
    The tables:
    --Products
    CREATE TABLE "Products" (
         "Image" BLOB
         , "CatalogId" RAW(16)
         , "ProductId" RAW(16)
         , "MnemonicId" NVARCHAR2(50) DEFAULT ''
         , "ProductParentId" RAW(16)
    ALTER TABLE "Products"
         ADD CONSTRAINT "NN_Products_M04" CHECK ("CatalogId" IS NOT NULL)
    ALTER TABLE "Products"
         ADD CONSTRAINT "NN_Products_M05" CHECK ("ProductId" IS NOT NULL)
    ALTER TABLE "Products"
    ADD CONSTRAINT "PK_Products"
    PRIMARY KEY ("ProductId")
    CREATE INDEX "IX_Products"
    ON "Products" ("CatalogId", "MnemonicId")
    CREATE UNIQUE INDEX "UK_Products"
    ON "Products" (DECODE("MnemonicId", NULL, NULL, RAWTOHEX("CatalogId") || "MnemonicId"))
    --Languages
    CREATE TABLE "Languages" (
         "Description" NVARCHAR2(250)
         , "IsStandard" NUMBER(1)
         , "LanguageId" RAW(16)
         , "MnemonicId" NVARCHAR2(12)
    ALTER TABLE "Languages"
         ADD CONSTRAINT "NN_Languages_M01" CHECK ("LanguageId" IS NOT NULL)
    ALTER TABLE "Languages"
         ADD CONSTRAINT "NN_Languages_M05" CHECK ("MnemonicId" IS NOT NULL)
    ALTER TABLE "Languages"
    ADD CONSTRAINT "PK_Languages"
    PRIMARY KEY ("LanguageId")
    ALTER TABLE "Languages"
    ADD CONSTRAINT "UK_Languages"
    UNIQUE ("MnemonicId")
    --ProductDesc
    CREATE TABLE "ProductDesc" (
         "Comment" NCLOB
         , "PlainComment" NCLOB
         , "Description" NVARCHAR2(250)
         , "DescriptionText" NCLOB
         , "PlainDescriptionText" NCLOB
         , "LanguageId" NVARCHAR2(12)
         , "ProductId" RAW(16)
    ALTER TABLE "ProductDesc"
         ADD CONSTRAINT "NN_ProductDescM01" CHECK ("LanguageId" IS NOT NULL)
    ALTER TABLE "ProductDesc"
         ADD CONSTRAINT "NN_ProductDescM02" CHECK ("ProductId" IS NOT NULL)
    ALTER TABLE "ProductDesc"
    ADD CONSTRAINT "PK_ProductDesc"
    PRIMARY KEY ("ProductId", "LanguageId")
    ALTER TABLE "ProductDesc"
    ADD CONSTRAINT "FK_ProductDesc1"
    FOREIGN KEY("ProductId") REFERENCES "Products" ("ProductId")
    ALTER TABLE "ProductDesc"
    ADD CONSTRAINT "FK_ProductDesc2"
    FOREIGN KEY("LanguageId") REFERENCES "Languages" ("MnemonicId")
    /The view:
    --ProductView
    CREATE OR REPLACE VIEW "vwProducts"
    AS
         SELECT
               "Products"."CatalogId"
              , "ProductDesc"."Comment"
              , "ProductDesc"."PlainComment"
              , "ProductDesc"."Description"
              , "ProductDesc"."DescriptionText"
              , "ProductDesc"."PlainDescriptionText"
              , "Products"."Image"
              , "Languages"."MnemonicId" "LanguageId"
              , "Products"."MnemonicId"
              , "Products"."ProductId"
              , "Products"."ProductParentId"
              , TRIM(NVL("ProductDesc"."Description" || ' ', '') || NVL("ParentDescriptions"."Description", '')) "FullDescription"
         FROM "Products"
         CROSS JOIN "Languages"
         LEFT OUTER JOIN "ProductDesc"
         ON "Products"."ProductId" = "ProductDesc"."ProductId"
         AND "ProductDesc"."LanguageId" = "Languages"."MnemonicId"
         LEFT OUTER JOIN "ProductDesc" "ParentDescriptions"
         ON "Products"."ProductParentId" = "ParentDescriptions"."ProductId"
         AND ("ParentDescriptions"."LanguageId" = "Languages"."MnemonicId")
    /The varray:
    --CustomType VARRAY
    CREATE OR REPLACE TYPE Varray_Params IS VARRAY(100) OF NVARCHAR2(1000);
    /The function:
    --FilterFunction
    CREATE OR REPLACE FUNCTION "fnProductFilter" (
         parCatalogId "Products"."CatalogId"%TYPE,
         parLanguageId                    NVARCHAR2 := N'it-IT',
         parFilterValues                    OUT Varray_Params
    RETURN INTEGER
    AS
         varSqlCondition                    VARCHAR2(32000);
         varSqlConditionValues          NVARCHAR2(32000);
         varSql                              NVARCHAR2(32000);
         varDbmsCursor                    INTEGER;
         varDbmsResult                    INTEGER;
         varSeparator                    VARCHAR2(2);
         varFilterValue                    NVARCHAR2(1000);
         varCount                         INTEGER;
    BEGIN
         varSqlCondition := '(T_Product."CatalogId" = HEXTORAW(:parentId)) AND (T_Product."LanguageId" = :languageId )';
         varSqlConditionValues := CHR(39) || TO_CHAR(parCatalogId) || CHR(39) || N', ' || CHR(39 USING NCHAR_CS) || parLanguageId || CHR(39 USING NCHAR_CS);
         parFilterValues := Varray_Params();
         varSql := N'SELECT FilterValues.column_value FilterValue FROM TABLE(Varray_Params(' || varSqlConditionValues || N')) FilterValues';
         BEGIN
              varDbmsCursor := dbms_sql.open_cursor;
              dbms_sql.parse(varDbmsCursor, varSql, dbms_sql.native);
              dbms_sql.define_column(varDbmsCursor, 1, varFilterValue, 1000);
              varDbmsResult := dbms_sql.execute(varDbmsCursor);
              varCount := 0;
              LOOP
                   IF (dbms_sql.fetch_rows(varDbmsCursor) > 0) THEN
                        varCount := varCount + 1;
                        dbms_sql.column_value(varDbmsCursor, 1, varFilterValue);
                        parFilterValues.extend(1);
                        parFilterValues(varCount) := varFilterValue;
                   ELSE
                        -- No more rows to copy
                        EXIT;
                   END IF;
              END LOOP;
              dbms_sql.close_cursor(varDbmsCursor);
         EXCEPTION WHEN OTHERS THEN
              dbms_sql.close_cursor(varDbmsCursor);
              RETURN 0;
         END;
         FOR i in parFilterValues.first .. parFilterValues.last LOOP
              varSeparator := ', ';
         END LOOP;
         RETURN 1;
    END;
    /The procedures:
    --Procedure presenting anomaly\bug
    CREATE OR REPLACE PROCEDURE "spProductCount" (
         parCatalogId "Products"."CatalogId"%TYPE,
         parLanguageId NVARCHAR2 := N'it-IT',
         parRecords OUT NUMBER
    AS
         varFilterValues Varray_Params;
         varResult INTEGER;
         varSqlTotal VARCHAR2(32000);
    BEGIN
         parRecords := 0;
         varResult := "fnProductFilter"(parCatalogId, parLanguageId, varFilterValues);
         varSqlTotal := 'BEGIN
         SELECT count(DISTINCT T_Product."ProductId") INTO :parCount FROM "vwProducts" T_Product
              WHERE ((T_Product."CatalogId" = HEXTORAW(:parentId)) AND (T_Product."LanguageId" = :languageId ));
    END;';
         EXECUTE IMMEDIATE varSqlTotal USING OUT parRecords, varFilterValues(1), varFilterValues(2);
    END;
    --Procedure NOT presenting anomaly\bug
    CREATE OR REPLACE PROCEDURE "spProductCount2" (
         parCatalogId "Products"."CatalogId"%TYPE,
         parLanguageId NVARCHAR2 := N'it-IT',
         parRecords OUT NUMBER
    AS
         varFilterValues Varray_Params;
         varResult INTEGER;
         varSqlTotal VARCHAR2(32000);
    BEGIN
         parRecords := 0;
         varSqlTotal := 'BEGIN
         SELECT count(DISTINCT T_Product."ProductId") INTO :parCount FROM "vwProducts" T_Product
              WHERE ((T_Product."CatalogId" = HEXTORAW(:parentId)) AND (T_Product."LanguageId" = :languageId ));
    END;';
         EXECUTE IMMEDIATE varSqlTotal USING OUT parRecords, parCatalogId, parLanguageId;
    END;Edited by: 835125 on 2011-2-9 1:31

    835125 wrote:
    Using VARRAY was the only way I found to transform comma seprated text values (e.g. "'abc', 'def', '123'") in a collection of strings.A varray is just a functionally crippled version of a nested table collection type, with a defined limit you probably don't need. (Why 100 specifically?) Instead of
    CREATE OR REPLACE TYPE varray_params AS VARRAY(100) OF NVARCHAR2(1000);try
    CREATE OR REPLACE TYPE array_params AS TABLE OF NVARCHAR2(1000);I don't know whether that will solve the problem but at least it'll be a slightly more useful type.
    What makes you think it's a memory leak specifically? Do you observe session PGA memory use going up more than it should?
    btw good luck with all those quoted column names. I wouldn't like to have to work with those, although they do make the forum more colourful.
    Edited by: William Robertson on Feb 11, 2011 7:54 AM

  • Creating and displaying Varrays in Apex 4.1

    Hi,
    I am creating quite a sophisticated database, which has to support relations between different tables. In order to implement that, I've decided to use user-defined datatype - a varray which consists of 100 integers (and only of that) that will contain ID's to different rows in different tables. Since it is a user-defined datatype I have problems with using it in Application Express :)
    First question: Is there any way to make this simple datatype 'readable' for Apex? In each application I create it shows that it is 'an unsupported datatype'. Maybe I should define something more than just varray construction - the way Apex should read and edit it etc ?
    Second question: How can I implement a function that will read the IDs in the varray and transform them into names to which that IDs correspond? I would like an application to show full name of an organization (ex. "ABC Corporation") instead of its ID. I tried to put some part of code that takes up the name of an organisation in a row with given ID into +"Source"+ form in the +"Edit page item"+, however Apex doesn't seem to get the fact that the data is in different table. Any ideas? :)
    I will be grateful for any help since it is an urgent case :]

    KamilGorski wrote:
    I would happily do that if only I had more time to study SQL and learn it properly :) Unfortunately, our start-up company has no time and money at the moment to allow me to do so.Then isn't using technologies that no one knows rather a strange decision?
    But coming back to your solution - it still works only if user inputs only one product quality. Let's say that user has chosen 3 qualities and the 'SELECTED_QUALITIES' collection looks like that:
    n001 = 1,
    n002 = 3,
    n003 = 5
    And since the SELECT query you have created compares pq.quality_id only to n001, it returns all the products that have the quality no 1 - not all the products that have all three selected qualities - 1, 3 and 5. Of course, we can change the 'EXISTS' condition and add more 'OR' conditions like that:
    where pq.quality_id = q.n001
    or pq.quality_id = q.n002
    or pq.quality_id = q.n003But it has few flaws - first we assume that we know the number of qualities user has selected - 3 (and we don't know that), You've misunderstood. SQL is row based. To handle multiple values, we create more rows, not additional columns. In your preferred terms, the result of any query is an <i>m</i>&times;<i>n</i> array of columns and rows, where the number of columns <i>m</i> is fixed, and the number of rows <i>n</i> varies according to the query predicates.
    It is not necessary to know the number of selected qualities, simply create a row in the collection for each selected quality to give a set of selected qualities.
    The SELECTED_QUALITIES collection should look like:
    N001
       1
       3
       5
    secondly the query will return all the products that have one of the three selected qualities (and we want products that have all three qualities). That wasn't really clear from the information previously given, but it's certainly possible. With <tt>product_qualities(product_id, quality_id)</tt> as a primary/unique key, and with no duplicates in the selected qualities, a solution is the set of all products with the selected qualities, where the number of qualities matched for each product equals the number of qualities selected, as in this example:
    SQL> create table products (
      2      product_id    integer       primary key
      3    , product_name  varchar2(30)  not null);
    Table created.
    SQL> create table qualities (
      2      quality_id    integer       primary key
      3    , quality_name  varchar2(30)  not null);
    Table created.
    SQL> create table product_qualities (
      2        product_id  integer   not null references products
      3      , quality_id  integer   not null references qualities,
      4      constraint product_qualities_pk primary key (
      5            product_id
      6          , quality_id))
      7    organization index;
    Table created.
    SQL> create index product_qualities_ix2 on product_qualities (
      2      quality_id
      3    , product_id);
    Index created.
    SQL> insert all
      2    into products (product_id, product_name) values (1, 'widget')
      3    into products (product_id, product_name) values (2, 'thingummy')
      4    into products (product_id, product_name) values (3, 'whatsit')
      5    into products (product_id, product_name) values (4, 'gizmo')
      6    into products (product_id, product_name) values (5, 'gadget')
      7    into products (product_id, product_name) values (6, 'contraption')
      8  select * from dual;
    6 rows created.
    SQL> insert all
      2    into qualities (quality_id, quality_name) values (1, 'green')
      3    into qualities (quality_id, quality_name) values (2, 'silver')
      4    into qualities (quality_id, quality_name) values (3, 'shiny')
      5    into qualities (quality_id, quality_name) values (4, 'furry')
      6    into qualities (quality_id, quality_name) values (5, 'digital')
      7    into qualities (quality_id, quality_name) values (6, 'hd')
      8    into qualities (quality_id, quality_name) values (7, 'wireless')
      9  select * from dual;
    7 rows created.
    SQL> insert all
      2    into product_qualities (product_id, quality_id) values (1, 1)
      3    into product_qualities (product_id, quality_id) values (1, 3)
      4    into product_qualities (product_id, quality_id) values (2, 2)
      5    into product_qualities (product_id, quality_id) values (2, 4)
      6    into product_qualities (product_id, quality_id) values (3, 1)
      7    into product_qualities (product_id, quality_id) values (3, 3)
      8    into product_qualities (product_id, quality_id) values (3, 5)
      9    into product_qualities (product_id, quality_id) values (4, 2)
    10    into product_qualities (product_id, quality_id) values (4, 4)
    11    into product_qualities (product_id, quality_id) values (4, 6)
    12    into product_qualities (product_id, quality_id) values (5, 2)
    13    into product_qualities (product_id, quality_id) values (5, 3)
    14    into product_qualities (product_id, quality_id) values (5, 5)
    15    into product_qualities (product_id, quality_id) values (6, 1)
    16    into product_qualities (product_id, quality_id) values (6, 3)
    17    into product_qualities (product_id, quality_id) values (6, 5)
    18    into product_qualities (product_id, quality_id) values (6, 7)
    19  select * from dual;
    17 rows created.
    SQL> commit;
    Commit complete.For the purposes of creating a quick and simple example outside of APEX, I'm using a temporary table instead of the SELECTED_QUALITIES APEX collection. For various reasons collections work better in APEX than GTTs and are the preferred approach for temporary storage.
    SQL> create global temporary table selected_qualities (
      2    n001 integer)
      3  on commit delete rows;
    Table created.With one quality selected, we get all the products having that quality:
    SQL> insert into selected_qualities (n001) values (1);
    1 row created.
    SQL> insert into selected_qualities (n001) values (1);
    1 row created.
    SQL> select
      2            p.product_id
      3          , p.product_name
      4  from
      5            products p
      6           join product_qualities pq
      7             on p.product_id = pq.product_id
      8           join selected_qualities sq
      9             on pq.quality_id = sq.n001
    10  group by
    11            p.product_id
    12          , p.product_name
    13  having
    14             count(*) = (select count(*) from selected_qualities);
    PRODUCT_ID PRODUCT_NAME
          1 widget
          6 contraption
          3 whatsitThese products all have the next quality added, so continue to be returned:
    SQL> insert into selected_qualities (n001) values (3);
    1 row created.
    SQL> select
      2            p.product_id
      3          , p.product_name
      4  from
      5            products p
      6           join product_qualities pq
      7             on p.product_id = pq.product_id
      8           join selected_qualities sq
      9             on pq.quality_id = sq.n001
    10  group by
    11            p.product_id
    12          , p.product_name
    13  having
    14             count(*) = (select count(*) from selected_qualities);
    PRODUCT_ID PRODUCT_NAME
          1 widget
          6 contraption
          3 whatsitThen as additional qualities are selected, the result set is progressively reduced:
    SQL> insert into selected_qualities (n001) values (5);
    1 row created.
    SQL> select
      2            p.product_id
      3          , p.product_name
      4  from
      5            products p
      6           join product_qualities pq
      7             on p.product_id = pq.product_id
      8           join selected_qualities sq
      9             on pq.quality_id = sq.n001
    10  group by
    11            p.product_id
    12          , p.product_name
    13  having
    14             count(*) = (select count(*) from selected_qualities);
    PRODUCT_ID PRODUCT_NAME
          6 contraption
          3 whatsit
    SQL> insert into selected_qualities (n001) values (7);
    1 row created.
    SQL> select
      2            p.product_id
      3          , p.product_name
      4  from
      5            products p
      6           join product_qualities pq
      7             on p.product_id = pq.product_id
      8           join selected_qualities sq
      9             on pq.quality_id = sq.n001
    10  group by
    11            p.product_id
    12          , p.product_name
    13  having
    14             count(*) = (select count(*) from selected_qualities);
    PRODUCT_ID PRODUCT_NAME
          6 contraption

  • How to retrieve data from a table that match values in a varray?

    Using - Oracle 10g Release 1.2
    How to do write a sql to retrieve data matching values in a varray?
    I have the following:
    declare
        v_ct          NATURAL := 0;
        type t_cur is  REF CURSOR;
        v_cursor t_cur;
        TYPE t_array IS VARRAY(100) OF NUMBER;
        l_codes t_array := t_array();
    begin
        select count(*)
          into v_ct
          from table1
         where ind_cd IS NULL;
        IF v_ct = 0 THEN
            l_codes(1) := 1;
        END IF;
        select count(*)
          into v_ct
          from table2
         where cd IS NULL;
        IF v_ct = 0 THEN
            l_codes(2) := 2;
        END IF;  
       OPEN v_cursor for
          select * from error_table where error_cd in (SELECT * FROM TABLE(CAST(l_codes AS t_array)) );
    end;

    This may not answer your question, but what about a pure SQL solution?
    NOTE THIS IS UNTESTED:
    SELECT *
    FROM     ERROR_TABLE
    WHERE     ERROR_CD IN
              SELECT      1
              FROM      table1
              HAVING      COUNT(*) > 0
              UNION ALL
              SELECT      2
              FROM      table2
              HAVING      COUNT(*) > 0     
         )HTH!

  • What is the actual size of an (empty) varray in a record?

    what is the actual size occupied by an (empty) varray in a record?
    For example, if I create my table defined as:
    create or replace type XXX as object (
    myRefs VARRAY(10) of REF(yyy)
    create table YYY as XXX;
    what is the actual size of the record of type XXX when 'myRefs' is empty? For some reason, select data_length from all_tab_cols where table_name = YYY seems always to return 3K as the length of column myrefs.... is that correct? If not, what is the correct size?

    A tad late here...
    Storage sizes of REF attributes are described here:
    [Design Considerations for REFs - Storage Size of REFs|http://download.oracle.com/docs/cd/E11882_01/appdev.112/e11822/adobjdes.htm#i452226]
    The size of your REF attribute (or element, in your case) will depend on whether it is primary key-based or system-generated, whether it is scoped or not, and whether it carries with it a rowid hint. The overall size of your VARRAY attribute as it grows will also depend on whether you allow null REF values or not, but essentially will be the size of your REF multiplied times the number of elements in your VARRAY (plus a small, constant amount of storage for internal housekeeping, both for the attribute and for each element).
    You could try the VSIZE function as an appromixation...
    [Oracle® Database SQL Language Reference - VSIZE|http://download.oracle.com/docs/cd/E11882_01/server.112/e17118/functions233.htm#SQLRF06162]
    Hope it helps...
    Gerard

  • Calling a stored procedure with VARRAY as out parameter using JDBC

    Hi,
    I want to use the data type VARRAY as an out parameter in an Oracle stored procedure. I want to call the stored procedure from
    my java program using JDBC.
    I'm using Oracle 8.1.5 for Windows NT.
    Please help me.
    Thanks
    Sumanta
    null

    Originally posted by JDBC Development Team:
    It's very similar to other datatype except that it uses OracleTypes.ARRAY typecode and the value is mapped to a oracle.sql.ARRAY instance. The code looks as follows --
    cstmt.registerOutParameter (idx, OracleTypes.ARRAY, "VARRAY_TYPE_NAME_HERE");
    cstmt.execute ();
    ARRAY array = (ARRAY) cstmt.getObject (idx);
    Thanks for your reply.
    I have to use:-
    OracleCallableStatement cs1 = (OracleCallableStatement )conn.prepareCall
    ( "{call proj_array(?)}" ) ;
    for retrieving a collection as an OUT parameter.
    This gives me the errors:-
    C:\jdbc\VarraySQL.java:0: The method oracle.jdbc2.Blob getBlob(int) declared in class oracle.jdbc.driver.OracleCallableStatement cannot override the method of the same signature declared in interface java.sql.CallableStatement. They must have the same return type.
    import java.sql.*;
    ^
    C:\jdbc\VarraySQL.java:0: The method oracle.jdbc2.Array getArray(int) declared in class oracle.jdbc.driver.OracleCallableStatement cannot override the method of the same signature declared in interface java.sql.CallableStatement. They must have the same return type.
    import java.sql.*;
    ^
    C:\jdbc\VarraySQL.java:0: The method oracle.jdbc2.Clob getClob(int) declared in class oracle.jdbc.driver.OracleCallableStatement cannot override the method of the same signature declared in interface java.sql.CallableStatement. They must have the same return type.
    import java.sql.*;
    ^
    C:\jdbc\VarraySQL.java:0: The method oracle.jdbc2.Ref getRef(int) declared in class oracle.jdbc.driver.OracleCallableStatement cannot override the method of the same signature declared in interface java.sql.CallableStatement. They must have the same return type.
    import java.sql.*;
    ^
    How do I get rid of these errors?
    null

  • Urgent Help needed in Objects & VARRAY

    Hi all,
    This is my first time doing query involving varray and objects. I have create tables, varray and object with below scenario :-
    CREATE TABLE Analogue
    (UniqueName varchar2(20) not null,
    DefaultRole T_ROLE,
    AlarmRoles T_ROLEARRAY);
    CREATE TYPE T_ROLE REPLACED AS OBJECT
    (ROLE varchar2(20));
    CREATE TYPE T_ROLEARRAY AS VARRAY(100) OF T_ROLE;
    Ok, my questions was :-
    1) How to do insertion into T_ROLEARRAY ? And, after a record added into T_ROLEARRAY, how to
    do SELECT to view the inserted record ?
    2) Does the insertion somehow insert values into T_ROLE as well if we insert record into
    T_ROLEARRAY since T_ROLEARRAY is a varray to T_ROLE?
    3) How to do Update and Delete from both DefaultRole and AlarmRoles in Analogue table ?
    Please consult if anyone of you had came across the above case.
    Thank you.
    Sharon.

    Sharon,
    You can check out some examples online,
    1. Querying collections: http://otn.oracle.com/docs/products/oracle9i/doc_library/release2/appdev.920/a96594/adobjbas.htm#458840
    2. DMLs with collections:
    http://otn.oracle.com/docs/products/oracle9i/doc_library/release2/appdev.920/a96594/adobjbas.htm#463813.
    Regards,
    Geoff
    Hi all,
    This is my first time doing query involving varray and objects. I have create tables, varray and object with below scenario :-
    CREATE TABLE Analogue
    (UniqueName varchar2(20) not null,
    DefaultRole T_ROLE,
    AlarmRoles T_ROLEARRAY);
    CREATE TYPE T_ROLE REPLACED AS OBJECT
    (ROLE varchar2(20));
    CREATE TYPE T_ROLEARRAY AS VARRAY(100) OF T_ROLE;
    Ok, my questions was :-
    1) How to do insertion into T_ROLEARRAY ? And, after a record added into T_ROLEARRAY, how to
    do SELECT to view the inserted record ?
    2) Does the insertion somehow insert values into T_ROLE as well if we insert record into
    T_ROLEARRAY since T_ROLEARRAY is a varray to T_ROLE?
    3) How to do Update and Delete from both DefaultRole and AlarmRoles in Analogue table ?
    Please consult if anyone of you had came across the above case.
    Thank you.
    Sharon.

  • Do I need to use a Collection/VArray or ...?

    Hi, all. Here's what I'm trying to do on an Oracle 9i database: I've got some 4 dates coming in from a table; I need to verify that they're valid by checking them against the person's birthdate, and then use only the valid dates in my package. So the dates need to be available at the package level to all functions and procedures within it.
    I've looked at VARRAY and other collection types, but wasn't sure how to make them available to the entire session and have them automatically killed at the session end. Whatever I use, it needs to have at least 3 columns of data for the duation of the session. Here are a few questions for the PL/SQL gurus,
    - Is this possible?
    - Should I be using a global temporary table? Like this, defined in one function,
    execute immediate 'create global temporary table...';
    - Are the values in that available to other functions/procedures within the same session?
    Your help is deeply appreciated.

    In short, you want to create such a table once as part of setting up your application.
    SQL> create global temporary table dates(
      2    d1 date,
      3    d2 date,
      4    d3 date )
      5  on commit preserve rows;
    Table created.Then in one session you can put some data into it:
    SQL> insert into dates values(sysdate-30, sysdate-60, sysdate-90);
    1 row created.
    SQL> insert into dates values(sysdate-45, sysdate-45, sysdate-45);
    1 row created.
    SQL> select * from dates;
    D1        D2        D3
    17-AUG-05 18-JUL-05 18-JUN-05
    02-AUG-05 02-AUG-05 02-AUG-05At the same time, in a second session you can put entirely different data into it:
    SQL> insert into dates values(sysdate, sysdate+1, sysdate+2);
    1 row created.
    SQL> select * from dates;
    D1        D2        D3
    16-SEP-05 17-SEP-05 18-SEP-05Now both sessions have their own separate data in this global temporary table. When the sessions end their data simply goes away.
    Typos removed.

  • VARRAYS in FORMS 9i

    I need to access columns defined in an Oracle 9i database as VARRAY in forms 9i. How do I go about this? Any help would be appreciated as the help was no help.
    Thanks in advance,
    Joe

    Check out the online help for Forms under Oracle9 Datatypes, plsql and forms -> about oracle9 datatypes
    "Not all Oracle9 features are currently supported across this release. The major unsupported features are: Collection types (nested tables and varying arrays, or varrays) ..."

  • VARRAY colletion type retirval from java , Wrong data ???? retrieved.

    Hi all,
    I am trying to retirve VARRAY collection type created in oracle from Java. It gives the wrong results as below:
    ********Fetch Starts....********
    ********Row 1 :
    Array is of type MY_UID.STRING_VARRAY
    Array is of length 2
    index 0 = ???
    index 1 = ???
    ********Fetch Ends....********
    Note: I nls_charcterset12.jar, classes12.jar are included in project class path.
    After breaking my head for two decided to request for help from big brains out there.
    For understanding, the code is attached and any help would be appriciated on this regard.
    Advance Thanks,
    Venkat
    The Code:
    import java.sql.*;
    import oracle.sql.*;
    import oracle.jdbc.oracore.Util;
    import oracle.jdbc.*;
    public class VArrayManipulation
    public static void main (String args[])
    throws Exception
    // DriverManager.registerDriver(new oracle.jdbc.OracleDriver());
    // The sample retrieves an varray of type "STRING_VARRAY",
    // materializes the object as an object of type ARRAY.
    // A new ARRAY is then inserted into the database.
    // String url = "<connection url>";
    // Connect to the database
    Connection conn =null;
    // DriverManager.getConnection (url, "<user>" , "<password>");
    DriverManager.registerDriver(new oracle.jdbc.driver.OracleDriver());
    conn = DriverManager.getConnection(
    "jdbc:oracle:thin:@localhost:1521:system", "my_uid","my_password");
    conn.setAutoCommit (false);
    // Create a Statement
    Statement stmt = conn.createStatement ();
    try
    stmt.execute ("DROP TABLE sample_varray_table");
    stmt.execute ("DROP TYPE string_varray");
    catch (SQLException e)
    //Exceptions will be thrown if Table and types doesnt exist . Ignore this
    stmt.execute ("CREATE TYPE string_varray AS VARRAY(10) OF VARCHAR2(100)");
    stmt.execute ("CREATE TABLE sample_varray_table (acol string_varray)");
    //Insert using SQL
    stmt.execute ("INSERT INTO sample_varray_table VALUES (string_varray('Test1', 'Test2'))");
    ResultSet rs = stmt.executeQuery("SELECT acol FROM sample_varray_table");
    printResultSet (rs);
    //Insert using ArrayDescriptor
    // create a new ARRAY object
    String arrayElements[] = { "Test3", "Test4" };
    ArrayDescriptor desc = ArrayDescriptor.createDescriptor
    ("STRING_VARRAY", conn);
    ARRAY newArray = new ARRAY(desc, conn, arrayElements);
    PreparedStatement ps =
    conn.prepareStatement ("insert into sample_varray_table values (?)");
    ((OraclePreparedStatement)ps).setARRAY (1, newArray);
    ps.execute ();
    rs = stmt.executeQuery("SELECT acol FROM sample_varray_table");
    printResultSet (rs);
    // Close all the resources
    rs.close();
    ps.close();
    stmt.close();
    conn.close();
    public static void printResultSet (ResultSet rs)
    throws SQLException
    System.out.println("********Fetch Starts....********");
    int line = 0;
    while (rs.next())
    line++;
    System.out.println("********Row "+line+" : ");
    ARRAY array = ((OracleResultSet)rs).getARRAY (1);
    System.out.println ("Array is of type "+array.getSQLTypeName());
    System.out.println ("Array is of length "+array.length());
    // get Array elements
    String[] values = (String[]) array.getArray();
    for (int i=0; i<values.length; i++)
    System.out.println("index "+i+" = "+values[i] );
    System.out.println("********Fetch Ends....********");
    }

    import java.sql.Array;
    import java.sql.Connection;
    import java.sql.DriverManager;
    import java.sql.PreparedStatement;
    import java.sql.ResultSet;
    import java.sql.Statement;
    import oracle.sql.ARRAY;
    import oracle.sql.ArrayDescriptor;
    public class test
        public static void main (String args[]) throws Exception
            DriverManager.registerDriver(new oracle.jdbc.OracleDriver());
            Connection conn = DriverManager.getConnection
                ("jdbc:oracle:thin:@sta00077.us.oracle.com:1521:xe", "scott","tiger");
            Statement stmt = conn.createStatement ();
            try {
                stmt.execute("DROP TABLE varray_table");
                stmt.execute("DROP TYPE string_varray");
            } catch (Exception e) { }
            stmt.execute("CREATE TYPE string_varray AS VARRAY(10) OF VARCHAR2(10)");
            stmt.execute("CREATE TABLE varray_table (sv string_varray)");
            stmt.execute("INSERT INTO varray_table VALUES (string_varray('Test1', 'Test2'))");
            ResultSet rs = stmt.executeQuery("SELECT sv FROM varray_table");
            printResultSet(rs);
            String arrayElements[] = { "Test3", "Test4", "Test5" };
            ArrayDescriptor desc = ArrayDescriptor.createDescriptor("STRING_VARRAY", conn);
            ARRAY newArray = new ARRAY(desc, conn, arrayElements);
            PreparedStatement ps = conn.prepareStatement("INSERT INTO varray_table VALUES (?)");
            ps.setArray(1, (Array)newArray);
            ps.execute();
            rs = stmt.executeQuery("SELECT sv FROM varray_table");
            printResultSet(rs);
            rs.close();
            ps.close();
            stmt.close();
            conn.close();
        public static void printResultSet (ResultSet rs) throws Exception
            System.out.println("******** Fetch Starts ********");
            int line = 0;
            while (rs.next()) {
                line++;
                System.out.println("*** Row " + line + " ***");
                Array array = rs.getArray(1);
                String[] values = (String[])array.getArray();
                System.out.println ("Array is of type " + array.getBaseTypeName());
                System.out.println ("Array is of length " + values.length);
                for (int i = 0; i < values.length; i++)
                    System.out.println("Index " + i + " = " + values);
    System.out.println("******** Fetch Ends ********");

  • SQL*Modeler - creation of VARRAY or Collection Type of scalar type errors

    In SQl*Modeler 2.0.0 Build 584, I can create either VARRAY or Collections. These work fine for usre defined structured types but I encounter huge problems when I use a simple scalar type of number or varchar2.
    For instance I create a new collection type, give it a name, specify its a collection (or VARRAY, same problem) then click datatype. On the select Data type box I select logical type. A new window opens, I select VARCHAR from the drop down list.
    Enter the size 15, everything appears fine. I click OK, the select data type screen now shows a logical type of VARCHAR(15).
    So far I'm happy. I generate the DDL, everthing is fine, the DDL contains my collection of VARCHAR2(15).
    Now I save the model, close it and re-open the same model. My collection is now of VARCHAR so the next time I generate it will get an error because the syntax is wrong because it has no length. Same problem happens when selecting a NUMBER, looses the precision and scale but at least that command still works, just with a maximum numeric value.
    Ok, so lets try creating distinct types. Why we can't access domains when specifying types from here remains a mystery to me.
    So I create a distinct type Varchar2_15 which is of Logical type VARCHAR and give it a size. Similarly, create another distinct type of NUMERIC_22_0 precision 22 scale 0. This seems to get around the problem of losing the data but the DDL generated shows the datatype to be either VARCHAR (not VARCHAR2) and NUMERIC(22), not number(22). Now I know that VARCHAR currently maps to VARCHAR2 but isn't guaranteed to in the future (even though its been like that since V6) and NUMERIC is just an alias for NUMBER but its going to confuse a lot of java people and its totally inconsitent and just plain wrong.
    Any suggestions or workarounds will be gratefully received.
    Ian Bainbridge

    Hi Ian,
    I see a bug in save/load of collection types and as result no size or precision and scale information. It's fixed in new release.
    However I cannot reproduce the problem with distinct types - I have them generated as varchar2 and number (this is for Oracle).
    You can check:
    - database you use in DDL generation - I got varchar and numeric for MS SQL Server;
    - mapping of logical types VARCHAR and NUMERIC to native types in "Types Administration".
    Philip
    PS - I was able to reproduce it - I looked at wrong place - DDL generation for collection types is broken - it's ok for columns. I logged bug for that.
    Edited by: Philip Stoyanov on Jun 28, 2010 8:55 PM

  • VArray in Database Adapter?

    Hi,
    I unable to create partnerlink of procedure having composite type vArray using database/application adapters and getting the following error while creating the same for procedure1. Version using 10.1.2.0.2.
    "Parameter output is of type arrayOfNumber which is either not supported or not an implemented datatype."
    TYPE arrayOfNumber IS VARRAY(4) of NUMBER;
    PROCEDURE procedure1 (input IN NUMBER, output OUT arrayOfNumber);
    Any thing doing wrong, if not then any alternate.
    thx,
    Janit

    Just to clarify, by "root-level" I mean outside of a package definition. Thus
    SQL> create type vArray as varray(10) of number;
    Instead of
    SQL> create package pkg as
    type vArray is varray(10) of number;
    end;The former type definition works as the type of a parameter. The latter does not.

  • How to index a varray of object type?

    Hello,
    Is it possible to index a varray/Table type, which is of type of an object, like the way the scalar types are.
    say, CREATE OR REPLACE
    TYPE SAMPLE_TABLE AS TABLE OF Date index by binary_integer
    But if I have to change the table type from Date to an object
    lets say
    create or replace TYPE SAMPLE_TYPE AS OBJECT (
    id NUMBER(12),
    value varchar2(12)
    Will I be able to do
    CREATE OR REPLACE
    TYPE SAMPLE_TABLE AS TABLE OF SAMPLE_TYPE index by id
    If not, is there a way it can be done, or is it a limitaion that it cant be done. Any pointers to this is highly appreciated.
    Thanks

    One way to do this...
    SQL> drop type profile_options_object_array
      2  /
    SQL> drop type profile_options_object
      2  /
    SQL> drop table t
      2  /
    SQL>
    SQL> CREATE OR REPLACE TYPE profile_options_object AS OBJECT(
      2  option_name VARCHAR2(100),
      3  option_value VARCHAR(200)
      4  );
      5  /
    SQL> CREATE OR REPLACE TYPE profile_options_object_array AS VARRAY(32000) OF profile_options_object;
      2  /
    SQL>
    SQL> create table t
      2  (x varchar2(10)
      3  ,y varchar2(10)
      4  );
    SQL> insert into t values ('name1', 'value1');
    SQL> insert into t values ('name2', 'value2');
    SQL> commit;
    SQL>
    SQL> select profile_options_object (x, y)
      2    from t
      3  /
    PROFILE_OPTIONS_OBJECT(X,Y)(OPTION_NAME, OPTION_VALUE)
    PROFILE_OPTIONS_OBJECT('name1', 'value1')
    PROFILE_OPTIONS_OBJECT('name2', 'value2')
    SQL> declare
      2     profile_options  profile_options_object_array;
      3     idx pls_integer;
      4  begin
      5     select profile_options_object (x, y)
      6       bulk collect
      7       into profile_options
      8       from t
      9     ;
    10    idx := profile_options.first;
    11    while idx is not null
    12    loop
    13      dbms_output.put_line (profile_options(idx).option_name); 
    14      dbms_output.put_line (profile_options(idx).option_value);
    15      idx := profile_options.next(idx);
    16    end loop;
    17  end;
    18  /
    name1
    value1
    name2
    value2
    SQL>

  • Passing table of varray to a procedure

    Hi,
    I have a procedure which takes the following parameters:
    create or replace
    PROCEDURE VECTORSUMMARYSTATISTICS
    chartOption IN CHARTOPTION,
    userChoicedate IN C_TAB,
    AllCases IN boolean,
    strVector_id VARCHAR2,
    strEntityName VARCHAR2,
    CollectionName VARCHAR2
    ) AS
    C_TAB is a type created on the database:
    create or replace
    TYPE C_TAB AS TABLE OF C_REC;
    And C_REC:
    create or replace
    TYPE C_REC AS OBJECT
    time_value TIMESTAMP
    In the body of the procedure I am using the table "userChoicedate" in the following way:
    for idx in userChoicedate.first..userChoicedate.last
    loop
    tuserdate_rec:=userChoicedate(idx); //table passed from the parameter
    tuserdate.extend(1);
    tuserdate(idx):=tuserdate_rec;
    end loop;
    where tuserdate_rec is declared in the following way:
    --record for holding a single user date
    tuserdate_rec C_REC;
    Before executing this procedure from pl/sql I am filling some test date from another pl/sql page:
    percRec2 C_REC;
    result_tab C_TAB;
    result_tab:=C_TAB();
    result_tab.extend(10);
    percRec2:=C_REC(TO_TIMESTAMP('01-01-2004 12:00:00.000', 'DD-MM-YYYY HH:MI:SS.FF3') );
    result_tab(1):=percRec2;
    percRec2:=C_REC(TO_TIMESTAMP('01-04-2004 12:00:00.000', 'DD-MM-YYYY HH:MI:SS.FF3') );
    result_tab(2):=percRec2;
    percRec2:=C_REC(TO_TIMESTAMP('01-07-2004 12:00:00.000', 'DD-MM-YYYY HH:MI:SS.FF3'));
    result_tab(3):=percRec2;
    percRec2:=C_REC(TO_TIMESTAMP('01-10-2004 12:00:00.000', 'DD-MM-YYYY HH:MI:SS.FF3'));
    result_tab(4):=percRec2;
    So when calling the procedure:
    VECTORSUMMARYSTATISTICS(ch,result_tab,FALSE,'WBHP','PRD3','CaseCollection1');
    I am getting the following error message:
    Error report:
    ORA-06531: Reference to uninitialized collection
    ORA-06512: at "SIMSERVER.VECTORSUMMARYSTATISTICS", line 184
    ORA-06512: at line 54
    06531. 00000 - "Reference to uninitialized collection"
    *Cause:    An element or member function of a nested table or varray
    was referenced (where an initialized collection is needed)
    without the collection having been initialized.
    *Action:   Initialize the collection with an appropriate constructor
    or whole-object assignment.
    So here at this line in bold the problem is:
    For idx in userChoicedate.first..userChoicedate.last
    loop
    tuserdate_rec:=userChoicedate(idx);
    tuserdate.extend(1);
    tuserdate(idx):=tuserdate_rec;
    end loop;
    Any help
    Thanks
    Message was edited by:
    user646975

    Hi,
    Are u sure cause always the procedure is not compiling
    This time I got the following problem:
    Error(182,11): PLS-00103: Encountered the symbol "(" when expecting one of the following: in The symbol "in" was substituted for "(" to continue.
    Error(320,71): PLS-00103: Encountered the symbol "GROUP" when expecting one of the following: , from into bulk

  • How to Use VARRAY Datatype?.

    I have three rows in one table.I have done some modifications to that table.I want to Update the Total Table at Single Database call?.May I Use Collections for that?.I want to Know about Collections.

    You should google before asking these questions.
    Here is a example
    -- VARRAY
    DECLARE
    TYPE varray_type IS VARRAY(5) OF INTEGER;
    v_varray varray_type;
    BEGIN
    --v_varray := varray_type(10,20,30,40,50);
    v_varray := varray_type();
    v_varray.extend;
    v_varray(1) := 10;
    v_varray.extend;
    v_varray(7) := 20;
    DBMS_OUTPUT.PUT_LINE(v_varray(1));
    END;
    Cheers.

  • Using Sqlldr to load VARRAYs!!!!!!!

    HI,
    I've created a collection type within the database the description of which reads as follows.....
    SQL> desc LISTVARCHAR
    LISTVARCHAR VARRAY(200) OF VARCHAR2(4000)
    But when I try to insert a value of more than 255 characters using sqlldr, it seems to fail giving the following message, but works fine from within sqlplus!
    Record 1: Rejected - Error on table TESTER, column COL1.
    Field in data file exceeds maximum length
    ****** Sample Data:
    |ABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUV|
    Shouldn't this Column take as many as 4000 characters for each element within that VARRAY? Please let me know if I'm missing anything.
    Thanks a lot for your time
    Chandra M.

    You will able to find good information about it in this document :
    http://download-east.oracle.com/docs/cd/B10501_01/server.920/a96652.pdf
    Joel P�rez

Maybe you are looking for

  • Information broadcasting in 2004s for pdf and HTML format throws error

    hi experts, I am broadcasting via e-mail, when i use output format as MHTML or XML it works fine, when i change the output format to pdf or html (as zip file) i get the following errors <b>For PDF</b> --><b><i>Settings ZTEST1 were started from the BE

  • Unable to create Reversal GRN

    Hi My user is unable to do the reversal GRN for a PO. Because it shows the **** in units columns of GRN screen. When I click on the GRN in PO history tab in PO the error come as u201Cunit *** is not created in language ENu201D.  So what is the proble

  • Customer invoices payment thru ACH

    Hi We are getting a PDF file from BOA for customer payment made through ACH. Now the clients wants to be automated like the lockbox. Is there a solution for customer payment made through ACH and clearing is done in SAP. You might have came across thi

  • Could not able to join physical tables in obiee using a dataconversion func

    Hi, i am trying to join physical tables wc_perf_ratings_d and w_wrkfc_evt_month_f with condition as "Oracle Data Warehouse"."Catalog"."dbo"."Dim_WC_PERF_RATINGS_D"."RATING_CD" = to_char(round( "Oracle Data Warehouse"."Catalog"."dbo"."Fact_W_WRKFC_EVT

  • Start Element - Default Date - Error

    Hi, We have NW04s SP7 Portal and our VC version is VC Server Version is 645.7.1.0. 1. In some scenarios we want some default list (data from SAP R/3) to be displayed by passing system date, i tried using NOW() option, it is not working.In our report