Constant declaration of VARRAY index by varchar2 within package header

Hi there
I'm looking for the correct syntax to declare a constant
of a varray type which is indexed by varchar2. I've tried
the following:
create or replace package nl_types
is
    TYPE nt_assoc_small IS TABLE OF INTEGER INDEX BY VARCHAR2(32);
    nl_bindcnt constant nt_assoc_small ('xml_gkregnl') := 3;
end;
I know this array hat just one element, but there will
be even more when I got this example case to work. As
I tried to compile this package, the compiler said:
13/16 PL/SQL: Declaration ignored
13/25 PLS-00566: type name "NT_ASSOC_SMALL" cannot be constrained
13/70 PLS-00320: the declaration of the type of this expression is
incomplete or malformed
O.K. then: Does anybody know the "wellformed" declaration
for this kind of varray?
Thanx in advance,
Martin.

That's not a VARRAY declaration, it's a PL/SQL table / associative array.
There is no syntax to declare the contents of an associative array in-line.
They can either be assigned to directly or populated by BULK COLLECT (except for associative arrays indexed by VARCHAR2). Perhaps you could assign the return value of a function?
Oracle Database 10g Enterprise Edition Release 10.1.0.2.0 - 64bit Production
With the Partitioning, OLAP and Data Mining options
SQL> CREATE OR REPLACE PACKAGE types AS
  2   
  3    TYPE associative_array_type IS TABLE OF INTEGER
  4      INDEX BY VARCHAR2 (32);
  5 
  6    FUNCTION default_associative_array_type
  7      RETURN associative_array_type;
  8    
  9  END;
10  /
Package created.
SQL> CREATE OR REPLACE PACKAGE BODY types AS
  2 
  3    FUNCTION default_associative_array_type
  4      RETURN associative_array_type
  5    IS
  6      associative_array associative_array_type;
  7    BEGIN
  8      associative_array ('xml_gkregnl') := 3;
  9      RETURN associative_array;
10    END;
11    
12  END;
13  /
Package body created.
SQL> CREATE OR REPLACE PACKAGE constants AS
  2   
  3    associative_array CONSTANT types.associative_array_type :=
  4      types.default_associative_array_type;
  5     
  6  END;
  7  /
Package created.
SQL> SET SERVEROUTPUT ON;
SQL> BEGIN
  2    DBMS_OUTPUT.PUT_LINE (
  3      'constants.associative_array (''xml_gkregnl'') => ' ||
  4        constants.associative_array ('xml_gkregnl'));
  5  END;
  6  /
constants.associative_array ('xml_gkregnl') => 3
PL/SQL procedure successfully completed.
SQL>

Similar Messages

  • Const declaration discussion

    (Since there is no "possible/future features" forum, I'm posting here, since a lot of the postings here deal with such matters.)
    Like some other Java users I'm a fan of the const declaration concept - const methods (not modifying the instance) and parameters (the object the parameter references will not be modified by the method). In part because it adds valuable error checking ability at compile time, and in part because it makes method declarations a lot clearer in many cases.
    (I'm not advocating a run-time conversion between const/non-const like in C/C++. Like e.g. final, this characteristic should be fixed after compilation.)
    I know there is an RFE on this - which was closed some years back, without much evaluation (not posted there, anyway). I've also been able to find some shallow discussions in the forums, and some have hinted that it can be a complex feature in some scenario, perhaps implying that it would not be without caveats.
    Perhaps some readers here know more about this issue and why the const keyword (which is reserved in the Java spec) has been decided to be unused?

    I don't have a deep knowledge of this, but AFAIK it's not practical (or possible) for the compiler to enforce this.
    Consider this method:
    static void printAndPeel(const Apple a, Fruit f) {
    System.out.println(a + "is an apple");
    System.out.println(f + "is an unpeeled fruit");
    f.peel();
    System.out.println(f + "is a peeled fruit");
    The 'const' Apple referred to by a is unchanged by the method 99% of the time. But when a==f , a strange bug occurs (from the point of view of anyone expecting a to remain unpeeled). The same would happen if this were a non-static const method of Apple, where 'this' takes the place of the parameter 'const Apple a'.
    Presumably the source of the problem is that you want objects to be const (within the scope of a method, say), but using syntax which declares references to objects as const. But there can be all kinds of references to an object, including ones in different threads.
    You could ensure an object was const by:
    (a) making it immutable always,
    (b) making it mutable but (say within the scope a method), ensuring that absolutely all references to the object are const (the Collections.unmodifiableCollection() wrapper attempts to do this),
    (c) having some kind of lock in the object itself which is enabled during the scope of a method, and throws an exception if someone tries to modify the object.
    Re these:
    (a) is the way to go, I think. I'd like to see an 'immutable' keyword you could apply to a class, which ensured all its fields were final and immutable (primitives would count as immutable). This would both be useful as a compile-time check for developers, and as a hint for the JVM to do various optimisations.
    (b) I don't see how this could work at compile time. If an object is mutable, you want it to be temporarily immutable sometimes (within the scope of a method, say). The compiler would have to prove that all non-const references accessible in that method could not point to the const object - even references of type Object! This places very stringent restrictions on what you can do in a method. Additionally, you have to ensure other threads can't change the object - very hard to enforce.
    (c) sounds possible but not ideal, because it's a runtime check. The above printAndPeel() method would compile OK and fail occasionally when run. But maybe this solution could be implemented in the VM in a fairly efficient manner by reusing the synchronisation locks somehow?

  • File with constants declared?

    How do I create a file with some constants declared? Do I have to make a class out of them? Then, how do I import the file into other classes?

    Here's what I have:
    interface ConvertTypes
         public static final int IDC = 1,MDS = 2, IDC_AND_MDS = 3;
    class ctest implements ConvertTypes
         public static void main(String[] args)
              System.out.println(IDC);
    Here's the error I get after I compile ConvertTypes and ctest:
    Z:\ctest.java:1: cannot resolve symbol
    symbol : class ConvertTypes
    location: class ctest
    class ctest implements ConvertTypes
    ^
    Z:\\ctest.java:5: cannot resolve symbol
    symbol : variable IDC
    location: class ctest
              System.out.println(IDC);

  • Declare a varray in a function

    hello,
    i wanna know how declare a varray of number(13,3) in a function, without declaring it as a new type
    regards
    Elyes

    Just declare type in your function. E.g.:
    CREATE OR REPLACE
      FUNCTION F1
        RETURN NUMBER
        IS
            TYPE varray_numbers IS VARRAY(35) OF NUMBER(13,3);
            v_varray varray_numbers := varray_numbers();
        BEGIN
            v_varray.extend(5);
            v_varray(5) := 5;
            RETURN 1;
    END;
    /SY.

  • Initialize record type constant in package header

    I am creating a package to hold application constants in Oracle 8.1.7.4. I want one of my constants to be a programmer-defined record type. A constant table type of that record type will then hold multiple records. I'm new to using record data types though, and think I'm having a syntactical problem. Here's a snip of the code. Any ideas?
    CREATE OR REPLACE PACKAGE kes_constants
    AS
    TYPE T_CLASS IS RECORD (code classes.cls_code%TYPE);
    TYPE T_CLASSES IS TABLE OF T_CLASS
    INDEX BY BINARY_INTEGER;
    con_proj_realestate CONSTANT T_CLASS;
    con_proj_realestate.code := 'RE';
    END kes_constants;

    It was a bit of a simplification, but I see your point. The desire is to create varchar2 constants and a collection constant containing said varchar2 constants. The values of the constants could be stored in a table instead and selected into the collection at initialization, but I'd like to do it all in the package header without any database tables if possible.
    I've modified my code to use varchar2 rather than records to hold the values. Then I try to initialize the collection with the constant values. When I compile my example code as shown here I get error: "PLS-00492: variable or constant initialization may not refer to functions declared in the same package". When I take the type definitions out of this package and put them in a separate package, change the code shown here to refer to the types with absolute dot notation names, I get error: "PLS-00222: no function with name 'T_CLASS_TABLE' exists in this scope".
    It seems to me there should be a way to do this. Do you think I'm way off base?
    Thanks for your help, Andrew.
    CREATE OR REPLACE PACKAGE kes_constants
    AS
       TYPE t_class_table IS TABLE OF VARCHAR2(4)
             INDEX BY BINARY_INTEGER;
       TYPE t_rtype_table IS TABLE OF VARCHAR2(4)
             INDEX BY BINARY_INTEGER;
       con_proj_realestate  CONSTANT VARCHAR2(4) := 'RE';
       con_proj_vehiclesv   CONSTANT VARCHAR2(4) := 'V';
       con_proj_other       CONSTANT VARCHAR2(4) := 'O';
       con_proj_maint       CONSTANT VARCHAR2(4) := 'M';
       con_proj_replacement CONSTANT VARCHAR2(4) := 'CR';
       con_proj_swing       CONSTANT VARCHAR2(4) := 'RS';
       con_proj_refurb      CONSTANT VARCHAR2(4) := 'RF';
       con_proj_additions   CONSTANT VARCHAR2(4) := 'EA';
       con_proj_cap         CONSTANT t_class_table := t_class_table(con_proj_realestate,
                                                                    con_proj_vehicles,
                                                                    con_proj_other,
                                                                    con_proj_replacement,
                                                                    con_proj_swing,
                                                                    con_proj_refurb,
                                                                    con_proj_additions);
       con_proj_noncap      CONSTANT t_class_table := t_class_table(con_proj_maint);
    END kes_constants;

  • How to get a called procedure/function name within package?

    Hi folks,
    is it possible to obtain a called procedure/function name within package?
    For a measuring and tracing purpose, I would like to store an info at the beginning of each procedure/function in package with timestamp + additional details if needed.
    For example:
    CREATE OR REPLACE PACKAGE BODY "TEST_PACKAGE" IS
       PROCEDURE proc_1 IS
       BEGIN
          api_log.trace_data(sysdate, 'START.' || ???????);
          api_log.trace_data(sysdate, 'END.' || ???????);
       END;
       PROCEDURE proc_2 IS
       BEGIN
          api_log.trace_data(sysdate, 'START.' || ???????);
          proc_1;
          api_log.trace_data(sysdate, 'END.' || ???????);
       END;
    END; I would like to replace "???????" with a function which would return a name of called procedure, so result of trace data after calling TEST_PACKAGE.proc_2 would be:
       11.1.2013 09:00:01    START.*TEST_PACKAGE.proc_2*
       11.1.2013 09:00:01    START.*TEST_PACKAGE.proc_1*
       11.1.2013 09:00:01    END.*TEST_PACKAGE.proc_1*
       11.1.2013 09:00:01    END.*TEST_PACKAGE.proc_2*I tried to use "dbms_utility.format_call_stack" but it did not return the name of procedure/function.
    Many thanks,
    Tomas
    PS: I don't want to use an hardcoding

    You've posted enough to know that you need to provide your 4 digit Oracle version (result of SELECT * FROM V$VERSION).
    >
    is it possible to obtain a called procedure/function name within package?
    For a measuring and tracing purpose, I would like to store an info at the beginning of each procedure/function in package with timestamp + additional details if needed.
    >
    I usually use this method
    1. Create a SQL type for logging information
    2. Put the package name into a constant in the package spec
    3. Add a line to each procedure/function for the name.
    Sample package spec
          * Constants and package variables
              gc_pk_name               CONSTANT VARCHAR2(30) := 'PK_TEST';Sample procedure code in package
          PROCEDURE P_TEST_INIT
          IS
            c_proc_name CONSTANT VARCHAR2(80)  := 'P_TEST_INIT';
            v_log_info  TYPE_LOG_INFO := TYPE_LOG_INFO(gc_pk_name, c_proc_name); -- create the log type instance
          BEGIN
              NULL; -- code goes here
          EXCEPTION
          WHEN ??? THEN
              v_log_info.log_code := SQLCODE;  -- add info to the log type
              v_log_info.log_message := SQLERRM;
              v_log_info.log_time    := SYSDATE;
              pk_log.p_log_error(v_log_info);
                                    raise;
          END P_PK_TEST_INIT;Sample SQL type
    DROP TYPE TYPE_LOG_INFO;
    CREATE OR REPLACE TYPE TYPE_LOG_INFO AUTHID DEFINER AS OBJECT (
    *  NAME:      TYPE_LOG_INFO
    *  PURPOSE:   Holds info used by PK_LOG package to log errors.
    *             Using a TYPE instance keeps the procedures and functions
    *             independent of the logging mechanism.
    *             If new logging features are needed a SUB TYPE can be derived
    *             from this base type to add the new functionality without
    *             breaking any existing code.
    *  REVISIONS:
    *  Ver        Date        Author           Description
    *   1.00      mm/dd/yyyy  me               Initial Version.
        PACKAGE_NAME  VARCHAR2(80),
        PROC_NAME     VARCHAR2(80),
        STEP_NUMBER   NUMBER,
        LOG_LEVEL   VARCHAR2(10),
        LOG_CODE    NUMBER,
        LOG_MESSAGE VARCHAR2(1024),
        LOG_TIME    TIMESTAMP,
        CONSTRUCTOR FUNCTION type_log_info (p_package_name IN VARCHAR2 DEFAULT 'Uninitialized',
                                            p_proc_name IN VARCHAR2 DEFAULT 'Uninitialized',
                                            p_step_number IN NUMBER DEFAULT 1,
                                            p_LOG_level IN VARCHAR2 DEFAULT 'Uninit',
                                            p_LOG_code IN NUMBER DEFAULT -1,
                                            p_LOG_message IN VARCHAR2 DEFAULT 'Uninitialized',
                                            p_LOG_time IN DATE DEFAULT SYSDATE)
                    RETURN SELF AS RESULT
      ) NOT FINAL;
    DROP TYPE BODY TYPE_LOG_INFO;
    CREATE OR REPLACE TYPE BODY TYPE_LOG_INFO IS
        CONSTRUCTOR FUNCTION type_log_info (p_package_name IN VARCHAR2 DEFAULT 'Uninitialized',
                                            p_proc_name IN VARCHAR2 DEFAULT 'Uninitialized',
                                            p_step_number IN NUMBER DEFAULT 1,
                                            p_LOG_level IN VARCHAR2 DEFAULT 'Uninit',
                                            p_LOG_code IN NUMBER DEFAULT -1,
                                            p_LOG_message IN VARCHAR2 DEFAULT 'Uninitialized',
                                            p_LOG_time IN DATE DEFAULT SYSDATE)
         RETURN SELF AS RESULT IS
        BEGIN
          self.package_name  := p_package_name;
          self.proc_name     := p_proc_name;
          self.step_number   := p_step_number;
          self.LOG_level   := p_LOG_level;
          self.LOG_code    := p_LOG_code;
          self.LOG_message := p_LOG_message;
          self.LOG_time    := p_LOG_time;
          RETURN;
        END;
    END;
    SHO ERREdited by: rp0428 on Jan 11, 2013 10:35 AM after 1st cup of coffee ;)

  • Declaring private cursors in package header

    Hi.
    Im tunning a PLSQL package , and im having the following doubt.
    This package has alot of cursors declared in the package header, but the cursors are private. (called within the package only)
    Could the public functions from the package have a loss of performance by using those cursors? (should the private cursors be declared within the functions or at least inside package body?)
    Im kind of new with plsql, so please bare with me :) .
    Cheers.

    there's no performance loss.
    however, unless the cursors are to be accessible outside the package (which is what happens when they are declared in the spec (not header)), then there's no benefit either. if they are truely meant to be private, then you can remove them from the spec. and if you're wrong, and they are called from elsewhere, you'll find out soon enough.

  • An issue with Dynamic SQL within Package using REF CURSOR

    Hi there,
    In the following package first two procedures works file but since I have added the third one ( GET_CONTRACT_BY_DYN_SQL) it does not work for me. When I try to compile and save it gives below error.
    "Error(6,15): PLS-00323: subprogram or cursor 'GET_CONTRACT_BY_DYN_SQL' is declared in a package specification and must be defined in the package body"
    Can you please help?
    Package Header
    create or replace
    PACKAGE CONTRACTS_PKG AS
    TYPE T_CURSOR IS REF CURSOR;
    PROCEDURE GET_CONRACTS (IO_CURSOR IN OUT T_CURSOR);
    PROCEDURE GET_CONTRACT_BY_ID (I_CONTRACTID IN NUMBER, IO_CURSOR IN OUT T_CURSOR);
    PROCEDURE GET_CONTRACT_BY_DYN_SQL(P_CONTRATID IN NUMBER, P_COLS IN VARCHAR2, IO_CURSOR IN OUT T_CURSOR);
    END CONTRACTS_PKG;
    Package Body
    create or replace
    PACKAGE BODY CONTRACTS_PKG AS
    -- Get All Contracts
    PROCEDURE GET_CONRACTS(IO_CURSOR IN OUT T_CURSOR)
    IS
    V_CURSOR T_CURSOR;
    BEGIN
    OPEN V_CURSOR FOR
    SELECT * FROM CONTRACTS;
    IO_CURSOR := V_CURSOR;
    END GET_CONRACTS;
    -- Get Contract By ID
    PROCEDURE GET_CONTRACT_BY_ID(I_CONTRACTID IN NUMBER, IO_CURSOR IN OUT T_CURSOR)
    IS
    V_CURSOR T_CURSOR;
    BEGIN
    OPEN V_CURSOR FOR
    SELECT * FROM CONTRACTS WHERE contract_id = I_CONTRACTID;
    IO_CURSOR := V_CURSOR;
    END GET_CONTRACT_BY_ID;
    -- Get Contract Using Dynamic SQL
    PROCEDURE GET_CONTRACT_BY_DYN_SQL(P_CONTRACTID IN NUMBER, P_COLS IN VARCHAR2, IO_CURSOR IN OUT T_CURSOR)
    IS
    V_CURSOR T_CURSOR;
    V_SQL VARCHAR2(200);
    BEGIN
    V_SQL := 'SELECT '|| P_COLS || ' FROM CONTRACTS WHERE contract_id = ' || P_CONTRACTID ;
    --OPEN V_CURSOR FOR
    --EXECUTE IMMEDIATE V_SQL INTO V_CURSOR;
    OPEN V_CURSOR FOR V_SQL;
    EXECUTE IMMEDIATE V_SQL;
    --IO_CURSOR := V_CURSOR;    
    END GET_CONTRACT_BY_DYN_SQL;
    END CONTRACTS_PKG;
    Thanks in advance.
    Hitesh

    Thanks guys. Finally I have tweaked as per your suggestions and it's working for all 3 cases (stored procedures).
    Oracle
    ======
    Package Header
    create or replace
    PACKAGE CONTRACTS_PKG AS
    TYPE T_CURSOR IS REF CURSOR;
    PROCEDURE GET_CONRACTS (IO_CURSOR IN OUT T_CURSOR);
    PROCEDURE GET_CONTRACT_BY_ID (I_CONTRACTID IN NUMBER, IO_CURSOR IN OUT T_CURSOR);
    PROCEDURE GET_CONTRACT_BY_DYN_SQL(P_CONTRACTID IN NUMBER, P_COLS IN VARCHAR2, IO_CURSOR IN OUT T_CURSOR);
    END CONTRACTS_PKG;
    Package Body
    create or replace
    PACKAGE BODY CONTRACTS_PKG AS
    -- Get All Contracts
    PROCEDURE GET_CONRACTS(IO_CURSOR IN OUT T_CURSOR)
    IS
    V_CURSOR T_CURSOR;
    BEGIN
    OPEN V_CURSOR FOR
    SELECT * FROM CONTRACTS;
    IO_CURSOR := V_CURSOR;
    END GET_CONRACTS;
    -- Get Contract By ID
    PROCEDURE GET_CONTRACT_BY_ID(I_CONTRACTID IN NUMBER, IO_CURSOR IN OUT T_CURSOR)
    IS
    V_CURSOR T_CURSOR;
    BEGIN
    OPEN V_CURSOR FOR
    SELECT * FROM CONTRACTS WHERE contract_id = I_CONTRACTID;
    IO_CURSOR := V_CURSOR;
    END GET_CONTRACT_BY_ID;
    -- Get Contract Using Dynamic SQL
    PROCEDURE GET_CONTRACT_BY_DYN_SQL(P_CONTRACTID IN NUMBER, P_COLS IN VARCHAR2, IO_CURSOR IN OUT T_CURSOR)
    IS
    V_CURSOR T_CURSOR;
    V_SQL VARCHAR2(200);
    BEGIN
    IF p_contractid > 0 THEN
    V_SQL := 'SELECT '|| P_COLS || ' FROM CONTRACTS WHERE contract_id = ' || P_CONTRACTID ;
    ELSE
    V_SQL := 'SELECT '|| P_COLS || ' FROM CONTRACTS';
    END IF;
    OPEN V_CURSOR FOR V_SQL;
    IO_CURSOR := V_CURSOR;
    END GET_CONTRACT_BY_DYN_SQL;
    END CONTRACTS_PKG;
    ColdFusion (calling app code)
    =====================
    <cfstoredproc procedure="CONTRACTS_PKG.GET_CONTRACT_BY_ID" datasource="#REQUEST.dsn#">
         <cfprocparam cfsqltype="CF_SQL_INTEGER" type="in" value="1" variable="I_CONTRACTID">
         <cfprocresult name="qData" resultset="1">
    </cfstoredproc>
    <br>Single Contract:
    <cfdump var="#qData#" label="Single Contract">
    <cfstoredproc procedure="CONTRACTS_PKG.GET_CONRACTS" datasource="#REQUEST.dsn#">     
         <cfprocresult name="qDataAll" resultset="1">
    </cfstoredproc>
    <br>All Contracts:
    <cfdump var="#qDataAll#" label="All Contracts">
    <cfstoredproc procedure="CONTRACTS_PKG.GET_CONTRACT_BY_DYN_SQL" datasource="#REQUEST.dsn#">
         <cfprocparam cfsqltype="CF_SQL_INTEGER" type="in" value="1" variable="P_CONTRACTID">
         <cfprocparam cfsqltype="CF_SQL_VARCHAR" type="in" value="contract_number,contract_title,created_date" variable="P_COLS">
         <cfprocresult name="qDataDynSQL" resultset="1">
    </cfstoredproc>
    <br>Dynamic SQL Query:
    <cfdump var="#qDataDynSQL#" label="Dynamic SQL Query">
    Thanks,
    Hitesh Patel

  • Associative Array with subsripts(Index) as Varchar2

    Hi All,     
    I m using Oracle Version 10.1.0.2.0 - Production     
    I have the following requirement:     
    The Associative array which holds the value with the subscripts(Index) as database table column.
    Create table Period_master
    Period_code_c Varchar2(10),
    Period_frm_dt Date,
    Period_to_dt Date,
    Year_code_c     Varchar2(10)
    Insert into period_master values ('10',to_date('01/01/2012','dd/mm/rrrr'),to_date('31/01/2012','dd/mm/rrrr'),'2011-2012');
    Insert into period_master Values ('11',to_date('01/02/2012','dd/mm/rrrr'),to_date('29/02/2012','dd/mm/rrrr'),'2011-2012');
    Insert into period_master Values ('12',to_date('01/03/2012','dd/mm/rrrr'),to_date('31/03/2012','dd/mm/rrrr'),'2011-2012');
    Insert into period_master Values ('13',to_date('01/04/2012','dd/mm/rrrr'),to_date('30/04/2012','dd/mm/rrrr'),'2012-2013');
    Insert into period_master Values ('14',to_date('01/05/2012','dd/mm/rrrr'),to_date('31/05/2012','dd/mm/rrrr'),'2012-2013');
    Commit;
    SQL > Select * from Period_Master;
    Period_code --- Period_frm_dt --- Period_to_dt ---- Year_code_c
    10     ---     01/01/2012 ---     31/01/2012     --- 2011-2012
    11     ---     01/02/2012 ---     29/02/2012     --- 2011-2012
    12     ---     01/03/2012 ---     31/03/2012     --- 2011-2012
    13     ---     01/04/2012 ---     30/04/2012     --- 2012-2013
    14     ---     01/05/2012 ---     31/05/2012     --- 2012-2013     
    My Requirement is get the Period_frm_dt,period_end_dt and yearcode based on period_code (which is input parameters from my procedure) by using Collections.
    I have to create one PLSQL table type which having the subscripts(Index) as period_code which is Varchar2 type;
    I have written follwing code ,but it's not giving the desired output:
    Declare
    iv_period Varchar2(10);
    Cursor cur_prd(cp_period Varchar2) is select * from Period_Master Where Period_code_c = cp_period;
    TYPE PRD_REC_TY IS TABLE OF cur_prd%ROWTYPE INDEX BY PLS_INTEGER;
    lv_prd_data prd_rec_ty;
    lv_prd PERIOD_MASTER.period_code_c%TYPE ;
    lv_frm_dt PERIOD_MASTER.Period_frm_dt%TYPE ;
    lv_to_dt PERIOD_MASTER.Period_to_dt%TYPE ;
    lv_yr_code PERIOD_MASTER.Year_code_c%TYPE ;
    Begin
    iv_period := :period;
    Open Cur_prd(iv_period);
    Loop
    Fetch cur_prd BULK COLLECT into lv_prd_data;
    EXIT WHEN cur_prd%NOTFOUND;
    End Loop;
    Close Cur_Prd;
    If lv_prd_data.COUNT > 0 THEN
    For i IN lv_prd_data.FIRST .. lv_prd_data.LAST
    LOOP
    lv_prd := lv_prd_data(i).pERIOD_cODE_C;
    lv_frm_dt := lv_prd_data(i).Period_frm_dt;
    lv_to_dt := lv_prd_data(i).Period_to_dt;
    lv_yr_code := lv_prd_data(i).Year_Code_c;
    Dbms_output.Put_line('For Period code : '||lv_prd||' the Year code is : '||lv_yr_code);
    Dbms_output.Put_line('For Period code : '||lv_prd||' the Period_from_dt is : '||lv_frm_dt);
    Dbms_output.Put_line('For Period code : '||lv_prd||' the Period_to_dt is : '||lv_to_dt);
    END LOOP;
    End if;
    Exception
    When Others Then
    Dbms_output.Put_line('Here Error Found: '||SQLERRM);
    End;
    But My requirement is to get the FRM_DT,TO_DT and YEAR CODE as per the following:
    For Period Code :*11* -- the YearCode is --- *2011-2012*
    For Period Code :*11* -- the From Dt is --- *01/02/2012*
    For Period Code :*11* -- the To Dt is --- *29/02/2012*
    for Period Code : *14* -- the Yearcode is --- *2012-2013*
    For Period Code : *14* -- the From Dt is --- *01/05/2012*
    For Period Code : *14* -- the To Dt is --- *31/05/2012*
    So on...
    Like:
    lv_yr_code := lv_period_data(iv_period).Year_code_c;
    lv_frm_dt := lv_period_data(iv_period).Period_frm_dt;
    lv_to_dt := lv_period_data(iv_period).Period_to_dt;
    Dbms_output.Put_line('For Period code : '||iv_period||' the Year code is : '||lv_yr_code);
    Dbms_output.Put_line('For Period code : '||iv_period||' the Period_from_dt is : '||lv_frm_dt);
    Dbms_output.Put_line('For Period code : '||iv_period||' the Period_to_dt is : '||lv_to_dt);
    How do i resolve the above scenario.Please help me to resove the above scenario.
    Regards,
    Prasanta

    Hi, Pransanta,
    Prasanta wrote:
    ... My Requirement is get the Period_frm_dt,period_end_dt and yearcode based on period_code (which is input parameters from my procedure) by using Collections.Sorry, I don't understand.
    What is the porocedure you mentioned? Do you mean the anonymous block that you posted? If not, post the procedure. How is it related to the anonymous block? E.g., does the anonymous block need to call the procedure?
    I have to create one PLSQL table type which having the subscripts(Index) as period_code which is Varchar2 type;
    I have written follwing code ,but it's not giving the desired output:
    Declare
    iv_period Varchar2(10);Please format your code, and use \ tags to keep the formatting when you post it on this site.
    See the forum FAQ {message:id=9360002}
    Cursor cur_prd(cp_period Varchar2) is select * from Period_Master Where Period_code_c = cp_period;You're only looking for a single given period_code_c.  If you want to get all rows, lose the WHERE clause.  If you want to multiple rows, but not all rows, then use an appropriate WHERE clause.
    TYPE PRD_REC_TY IS TABLE OF cur_prd%ROWTYPE INDEX BY PLS_INTEGER;
    lv_prd_data prd_rec_ty;
    lv_prd PERIOD_MASTER.period_code_c%TYPE ;
    lv_frm_dt PERIOD_MASTER.Period_frm_dt%TYPE ;
    lv_to_dt PERIOD_MASTER.Period_to_dt%TYPE ;
    lv_yr_code PERIOD_MASTER.Year_code_c%TYPE ;
    Begin
    iv_period := :period;Post the code that declares and sets :period.
    Open Cur_prd(iv_period);
    Loop
    Fetch cur_prd BULK COLLECT into lv_prd_data;
    EXIT WHEN cur_prd%NOTFOUND;
    End Loop;
    Close Cur_Prd;
    If lv_prd_data.COUNT > 0 THEN
    For i IN lv_prd_data.FIRST .. lv_prd_data.LAST
    LOOP
    lv_prd := lv_prd_data(i).pERIOD_cODE_C;
    lv_frm_dt := lv_prd_data(i).Period_frm_dt;
    lv_to_dt := lv_prd_data(i).Period_to_dt;
    lv_yr_code := lv_prd_data(i).Year_Code_c;If the block is just supposed to do what it's doing now; then you don't need all these local variables.  It's simpler just to teference lv_prd_data.
    If you're planning to add some other code to the block later, then the local variables could be useful.
    Dbms_output.Put_line('For Period code : '||lv_prd||' the Year code is : '||lv_yr_code);
    Dbms_output.Put_line('For Period code : '||lv_prd||' the Period_from_dt is : '||lv_frm_dt);
    Dbms_output.Put_line('For Period code : '||lv_prd||' the Period_to_dt is : '||lv_to_dt);
    END LOOP;
    End if;
    Exception
    When Others Then
    Dbms_output.Put_line('Here Error Found: '||SQLERRM);Only use an EXCEPTION section when you need to.  The EXCEPTION section above is only hiding some information about the error.
    End;
    But My requirement is to get the FRM_DT,TO_DT and YEAR CODE as per the following:
    For Period Code :*11* -- the YearCode is --- *2011-2012*
    For Period Code :*11* -- the From Dt is --- *01/02/2012*
    For Period Code :*11* -- the To Dt is --- *29/02/2012*
    for Period Code : *14* -- the Yearcode is --- *2012-2013*
    For Period Code : *14* -- the From Dt is --- *01/05/2012*
    For Period Code : *14* -- the To Dt is --- *31/05/2012*
    So on...
    Like:
    lv_yr_code := lv_period_data(iv_period).Year_code_c;
    lv_frm_dt := lv_period_data(iv_period).Period_frm_dt;
    lv_to_dt := lv_period_data(iv_period).Period_to_dt;
    Dbms_output.Put_line('For Period code : '||iv_period||' the Year code is : '||lv_yr_code);
    Dbms_output.Put_line('For Period code : '||iv_period||' the Period_from_dt is : '||lv_frm_dt);
    Dbms_output.Put_line('For Period code : '||iv_period||' the Period_to_dt is : '||lv_to_dt);
    How do i resolve the above scenario.Please help me to resove the above scenario.
    Regards,
    PrasantaIf the problem is that you need to show all period_code_cs, not just one, then you can do this:DECLARE
    CURSOR cur_prd
    IS SELECT *
         FROM     period_master
         ORDER BY period_code_c;
    TYPE prd_rec_ty IS TABLE OF cur_prd%ROWTYPE INDEX BY PLS_INTEGER;
    lv_prd_data prd_rec_ty;
    BEGIN
    OPEN cur_prd;
    FETCH cur_prd BULK COLLECT into lv_prd_data;
    CLOSE cur_prd;
    IF lv_prd_data.COUNT > 0
    THEN
    FOR i IN lv_prd_data.FIRST .. lv_prd_data.LAST
         LOOP
         dbms_output.put_line ( 'For Period code : '
                        || lv_prd_data(i).period_code_c
                        || ' the Year code is : '
                        || lv_prd_data(i).year_code_c
         dbms_output.Put_line ( 'For Period code : '
                        || lv_prd_data(i).period_code_c
                        || ' the Period_from_dt is : '
                        || lv_prd_data(i).period_frm_dt
         dbms_output.put_line ( 'For Period code : '
                        || lv_prd_data(i).period_code_c
                        || ' the Period_to_dt is : '
                        || lv_prd_data(i).period_to_dt
         END LOOP;
    END IF;
    END;

  • VARRAY INDEX

    Hi,
    i've following problem:
    CREATE TYPE F_FLA_TYPE AS OBJECT (
    ABC          VARCHAR2(3),
    DEF VARCHAR2(7),
    GHI VARCHAR2(14),
    CREATE TYPE F_FLA_ARRAY AS VARRAY (999) OF F_FLA_TYPE
    CREATE TABLE IFC (
    ID NUMBER(12),
    STATUS VARCHAR2(1),
    FTA F_FLA_ARRAY,
    VERSION NUMBER(3),
    SOURCE VARCHAR2(100)
    i want to create an index on IFC.FTA.ABC
    how can i do this?
    thanks for response.

    I think you may not be able to create such an index on a named arrary type. Can you use a nested table instead, as shown below?
    scott@ORA92> CREATE OR REPLACE TYPE f_fla_type AS OBJECT
      2    (abc VARCHAR2(3),
      3       def VARCHAR2(7),
      4       ghi VARCHAR2(15));
      5  /
    Type created.
    scott@ORA92> SHOW ERRORS
    No errors.
    scott@ORA92> CREATE OR REPLACE TYPE f_fla_array AS TABLE OF f_fla_type;
      2  /
    Type created.
    scott@ORA92> SHOW ERRORS
    No errors.
    scott@ORA92> CREATE TABLE ifc
      2    (id     NUMBER(12),
      3       status     VARCHAR2(1),
      4       fta     f_fla_array,
      5       version NUMBER(3),
      6       source     VARCHAR2(100))
      7    NESTED TABLE fta STORE AS fta_nestedtab
      8  /
    Table created.
    scott@ORA92> CREATE INDEX nested_tab_ix ON fta_nestedtab (abc)
      2  /
    Index created.

  • Why do we need varrays ,index by table,pl/sql table etc when cursor is avai

    hi,
    Why do we need Composite data types like Index by Table, varrays etc when we have cursors and we can do all the things with cursor.
    Thanks
    Ram

    I would have to create a collection type for each column in the select statement.No.
    SQL> select count(*) from scott.emp ;
      COUNT(*)
            14
    1 row selected.
    SQL> DECLARE
      2      TYPE my_Table IS TABLE OF scott.emp%ROWTYPE;
      3      my_tbl my_Table;
      4  BEGIN
      5      SELECT * BULK COLLECT INTO my_tbl FROM scott.emp;
      6      dbms_output.put_line('Bulk Collect rows:'||my_tbl.COUNT) ;
      7  END;
      8  /
    Bulk Collect rows:14
    PL/SQL procedure successfully completed.
    SQL> disc
    Disconnected from Oracle9i Enterprise Edition Release 9.2.0.7.0 - Production
    With the Partitioning, OLAP and Oracle Data Mining options
    JServer Release 9.2.0.7.0 - Production
    SQL>Message was edited by:
    Kamal Kishore

  • Using a byte[] as a secondary index's key within the Collection's API

    I am using JE 4.1.7 and its Collections API. Overall I am very satisfied with the ease of using JE within our applications. (I need to know more about maintenance, however!) My problem is that I wanted a secondary index with a byte[] key. The key contains the 16 bytes of an MD5 hash. However, while the code compiles without error when it runs JE tell me
    Exception in thread "main" java.lang.IllegalArgumentException: ONE_TO_ONE and MANY_TO_ONE keys must not have an array or Collection type: example.MyRecord.hash
    See test code below. I read the docs again and found that the only "complex" formats that are acceptable are String and BigInteger. For now I am using String instead of byte[] but I would much rather use the smaller byte[]. Is it possible to trick JE into using the byte[]? (Which we know it is using internally.)
    -- Andrew
    package example;
    import com.sleepycat.je.Environment;
    import com.sleepycat.je.EnvironmentConfig;
    import com.sleepycat.persist.EntityStore;
    import com.sleepycat.persist.PrimaryIndex;
    import com.sleepycat.persist.SecondaryIndex;
    import com.sleepycat.persist.StoreConfig;
    import com.sleepycat.persist.model.Entity;
    import com.sleepycat.persist.model.PrimaryKey;
    import com.sleepycat.persist.model.Relationship;
    import com.sleepycat.persist.model.SecondaryKey;
    import java.io.File;
    @Entity
    public class MyRecord {
    @PrimaryKey
    private long id;
    @SecondaryKey(relate = Relationship.ONE_TO_ONE, name = "byHash")
    private byte[] hash;
    public static MyRecord create(long id, byte[] hash) {
    MyRecord r = new MyRecord();
    r.id = id;
    r.hash = hash;
    return r;
    public long getId() {
    return id;
    public byte[] getHash() {
    return hash;
    public static void main( String[] args ) throws Exception {
    File directory = new File( args[0] );
    EnvironmentConfig environmentConfig = new EnvironmentConfig();
    environmentConfig.setTransactional(false);
    environmentConfig.setAllowCreate(true);
    environmentConfig.setReadOnly(false);
    StoreConfig storeConfig = new StoreConfig();
    storeConfig.setTransactional(false);
    storeConfig.setAllowCreate(true);
    storeConfig.setReadOnly(false);
    Environment environment = new Environment(directory, environmentConfig);
    EntityStore myRecordEntityStore = new EntityStore(environment, "my-record", storeConfig);
    PrimaryIndex<Long, MyRecord> idToMyRecordIndex = myRecordEntityStore.getPrimaryIndex(Long.class, MyRecord.class);
    SecondaryIndex<byte[], Long, MyRecord> hashToMyRecordIndex = myRecordEntityStore.getSecondaryIndex(idToMyRecordIndex, byte[].class, "byHash");
    // END

    We have highly variable length data that we wish to use as keys. To avoid massive index sizes and slow key lookup we are using MD5 hashes (or something more collision resistant should we need it). (Note that I am making assumptions about key size and its relation to index size that may well inaccurate.)Thanks for explaining, that makes sense.
    It would be the whole field. (I did consider using my own key data design using the @Persistent and @KeyField annotations to place the MD5 hash into two longs. I abandoned that effort because I assumed (again) that lookup with a custom key design would slower than the built-in String key implementation.)A composite key class with several long or int fields will not be slower than a single String field, and will probably result in a smaller key since the UTF-8 encoding is avoided. Since the byte array is fixed size (I didn't realize that earlier), this is the best approach.
    --mark                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           

  • Constant declaration and the optimizer

    Assume there is a Plsql package A with a defined constant 'constA'
    Assume we have an sql query in PLSQL package B that references A.constA.
    Will the optimizer always give the same plan for the query whether I used the literal constant or the reference A.constA?
    I assume that replacement of references to A.constA would have to be don't before the optimizer begins it's evaluation. I assume that does not happen; therefore, using A.constA has prevented the optimizer from using the statistics on the table.
    Ie. It is true that use of literals may provide better performance than references to declared constants.

    Hi,
    Will the optimizer always give the same plan for the query whether I used the literal constant or the reference A.constA?Assuming bind peeking is not turned off and all other parameters influencing CBO are the same - yes.
    "The same plan" in this context means not "the same piece of memory in library cache", but "the same execution path", because query with literal and a constant will result in different SQL queries, hence different shareable parent cursors.
    It is true that use of literals may provide better performance than references to declared constants.Yes. If you have a constant to use in SQL, then it's better to use it as a literal rather than bind (using a PL/SQL constant in a query results in using bind variable - but maybe that behavior will be changed sometime).
    The main issue with using binds for constant is a case you use several constants for exactly the same query and there's data skew. CBO is not doing well with that until 11g (which introduced adaptive cursor sharing).

  • ORACLE TEXT INDEX ON VARCHAR2 COLUMN

    Hello All,
    I find a search in our application very slow so i thought of using ORACLE TEXT CTXCAT index based search but i find certain inconsistencies . How can this be avoided....The following query should not return result if i can replace with oracle text but i find few values....why is that...i have also given few sample results below....
    SELECT first_name
    FROM uc_partner_ms
    WHERE
    Upper(first_name) LIKE '%WIE%'
    minus
    SELECT first_name
    FROM uc_partner_ms
    WHERE CATSEARCH (first_name,'*wie*', null) > 0
    RESULTS ....
    Hans-Werner Mrowiec
    Heinz Oesterwiemann GmbH
    Helmut Froitzheim GmbH, Neuwied
    Heribert Schwies
    Hermann Twieling GmbH & Co. KG
    Horst Breitwieser
    Horst-Dieter Swie
    The script used for creating index is
    begin
    ctx_ddl.create_preference('mylex', 'BASIC_LEXER');
    ctx_ddl.set_attribute ( 'mylex', 'index_themes', 'NO');
    ctx_ddl.set_attribute ( 'mylex', 'mixed_case', 'NO');
    end;
    CREATE INDEX partner_index ON uc_partner_ms (first_name)
    INDEXTYPE IS CTXSYS.CTXCAT
    parameters ( 'LEXER mylex' );
    Where am i wrong i could not guess a trend in the results other than all being in lower case.....

    Catsearch does not support leading wildcards. As a workaround, you can use a query template with context grammar. Please see the reproduction and solution below.
    SCOTT@orcl_11g> -- test environment:
    SCOTT@orcl_11g> CREATE TABLE uc_partner_ms
      2    (first_name  VARCHAR2 (60))
      3  /
    Table created.
    SCOTT@orcl_11g> SET DEFINE OFF
    SCOTT@orcl_11g> INSERT ALL
      2  INTO uc_partner_ms VALUES ('Hans-Werner Mrowiec')
      3  INTO uc_partner_ms VALUES ('Heinz Oesterwiemann GmbH')
      4  INTO uc_partner_ms VALUES ('Helmut Froitzheim GmbH, Neuwied')
      5  INTO uc_partner_ms VALUES ('Heribert Schwies')
      6  INTO uc_partner_ms VALUES ('Hermann Twieling GmbH & Co. KG')
      7  INTO uc_partner_ms VALUES ('Horst Breitwieser')
      8  INTO uc_partner_ms VALUES ('Horst-Dieter Swie')
      9  SELECT * FROM DUAL
    10  /
    7 rows created.
    SCOTT@orcl_11g> begin
      2    ctx_ddl.create_preference('mylex', 'BASIC_LEXER');
      3    ctx_ddl.set_attribute ( 'mylex', 'index_themes', 'NO');
      4    ctx_ddl.set_attribute ( 'mylex', 'mixed_case', 'NO');
      5  end;
      6  /
    PL/SQL procedure successfully completed.
    SCOTT@orcl_11g> CREATE INDEX partner_index ON uc_partner_ms (first_name)
      2  INDEXTYPE IS CTXSYS.CTXCAT
      3  parameters ( 'LEXER mylex' )
      4  /
    Index created.
    SCOTT@orcl_11g> -- reproduction:
    SCOTT@orcl_11g> SELECT first_name
      2  FROM uc_partner_ms
      3  WHERE
      4  Upper(first_name) LIKE '%WIE%'
      5  minus
      6  SELECT first_name
      7  FROM uc_partner_ms
      8  WHERE CATSEARCH (first_name,'*wie*', null) > 0
      9  /
    FIRST_NAME
    Hans-Werner Mrowiec
    Heinz Oesterwiemann GmbH
    Helmut Froitzheim GmbH, Neuwied
    Heribert Schwies
    Hermann Twieling GmbH & Co. KG
    Horst Breitwieser
    Horst-Dieter Swie
    7 rows selected.
    SCOTT@orcl_11g> -- solution:
    SCOTT@orcl_11g> SELECT first_name
      2  FROM uc_partner_ms
      3  WHERE
      4  Upper(first_name) LIKE '%WIE%'
      5  minus
      6  SELECT first_name
      7  FROM   uc_partner_ms
      8  WHERE  CATSEARCH
      9             (first_name,
    10              '<query>
    11              <textquery grammar="CONTEXT">
    12                %wie%
    13              </textquery>
    14            </query>',
    15              null) > 0
    16  /
    no rows selected
    SCOTT@orcl_11g>

  • How to determine Secure Channel key set index or version within applet

    Hi,
    Is there any way to determine from within the applet the used key set index or key set version?
    The ProviderSecurityDomain object does not contain such a property to my understanding.
    b.r.
    Fabe

    No there is not. There are API's to ask the security domain to do crypto operations using the current secure channel session keys and GP says that the security domain needs to be aware of what keys to use for this.
    The key information is not exposed to the applet as it is not generally required and for security reasons.
    Cheers,
    Shane

Maybe you are looking for

  • Read From Spreadsheet File help

    I am saving all my data to a text file (See attached file). The problem is that when I try and use the Read From Spreadsheet File.vi I am unclear on how to make it show all my data. Does anyone know a away for me to read the whole file and display it

  • Streaming to smart tv

    Hello All, Hoping someone can help us out. We recently purchased a Samsung SmartTV (which we love) and got rid of our huge cable bill. I also have purchased the adaptor for my 2009 MacBook and the appropriate HDMI cable for the adaptor and the tv. I

  • Syncing movies on iPad without removing music and books?

    I have an iPad loaded with music, books, apps and some movies, which I normally sync to my iMac. I am travelling and have a laptop with some movies that I want to sync to my iPad. Even if I just select the movies though and don't select any other syn

  • How do i get  my icloud to backup my photos from my ipad

    hello i have signed into my icloud online but my photos are not on there, how do i back them up. please can someone help i thought it would automatically do this.

  • Where is my Build Location

    I can't burn a dvd because I get a message that says "The Build Location folder contains a HVDVD_TS folder(HD DVD content). You must remove the HVDVD_TS folder from the Build Location in order to proceed with Build/Format of a Standard DVD project."