Initialize a constant which is a user-defined record type

Hi all

This may be a simple question, but I'm hard-pressed to find a solution.

The PL/SQL documentation says I can declare a constant from a defined record type previously. But how to initialize in the declaration? For example.

create or replace package my_package as
type my_type is record (varchar2 (10) Field1, Field2 varchar2 (10));
c_myconst constant my_type: = < what? >;
end my_package;

I tried the initialization function that does nothing more to return one my_type with the fields defined and which works except that PL/SQL has a restriction that this feature cannot be in the same package that the constant that will make my packages appear disorganized - I would be just as quickly initialize the constant online so down the line , programmers are not wondering why I call this function only in its own packaging.

Is a syntax that will allow me to provide values for the c_myconst must in the declaration?

Thank you
John

I checked - declare the INIT_ERR() function before using it to fill the constant makes no difference: it precipitates again PLS - 492.

so the SQL Types seem the way to go...

SQL> create or replace type err_type as object
  2      (err_num number(5,0),  err_msg varchar2(200));
  3  /

Type created.

SQL>
SQL>
SQL> create or replace package app_errs as
  2
  3      function init_err(p_err_num in pls_integer, p_err_msg in varchar2)
  4          return err_type;
  5
  6      c_bad_id constant err_type := err_type(-20000, 'Invalid ID');
  7
  8      procedure raise_err(p_err_num in pls_integer, p_err_msg in varchar2);
  9
 10  end app_errs;
 11  /

Package created.

SQL>

Cheers, APC

blog: http://radiofreetooting.blogspot.com

Tags: Database

Similar Questions

  • How to get user defined Native Types is displayed

    I added a new user defined native Type using type Admin

    Define Custom Type.png

    I saved, closed and then reopened the Data Modeler, but he does not appear in the Source Type drop-down list when I define a column in the relational model. I've defined the relational model to use 12 c as the Site of RDBMS. Am I missing a step in the installer?

    I use 4.1.3 on a Mac.

    Hello Kent,

    the native DB types never appear in the column definition. You need to create the new type of logical data and map it to the native type or change the mapping of logical type existing. The steps are confusing because it's like the problem or chicken (which is the first), you you will be defined first:

    (1) define the native type - save definitions - defined by the user of the native types had to be saved in order to be available for native types logic mapping

    (2) identify the type of logic - probably VARIANT in your case, define the mapping of native type logic

    (3) in native type definition define the mapping of native code to the logical type (it is mapped on the CLOB type on your photo - probably you will change it)

    (4) save the definitions

    Philippe

  • PROGRAMMER (USER) DEFINED RECORDS

    Hi all;


    I do self - study of PL/SQL concepts for user-defined folders.

    I get the error.


    SQL > desc emp;

    Name                                      Null?    Type

    ----------------------------------------- -------- ----------------------------

    EID                                               NUMBER

    ENAME VARCHAR2 (15)

    VARCHAR2 (10) EQUAL

    ESALARY VARCHAR2 (15)

    ECITY VARCHAR2 (15)


    SQL > select count (*) from emp;

    COUNT (*)

    2


    PROGRAMMER (USER) DEFINED RECORDS


    SQL > DECLARE

    2 C_cr CURSOR IS

    3. Select ename, equality, esalary, eid, ecity emp;

    4 EMP_DETAILS RECORD TYPE IS

    5 (e_id emp.eid%TYPE,

    6 e_name emp.ename%TYPE,

    7 e_qual emp.equal%TYPE,

    8 e_salary emp.esalary%TYPE,

    e_city 9 emp.ecity%TYPE);

    10 emp_detail e1;

    BEGIN 11

    12 C_cr OPEN;

    LOOP 13

    14 C_cr FETCH in emp_detail;

    15 WHEN OUT C_cr % NOTFOUND;

    16 DBMS_OUTPUT. Put_line (emp_detail.e_id | emp_detail.e_name | emp_detail.e_q ual | emp_detail.e_salary | emp_detail.ecity);

    17 END OF LOOP;

    18 DBMS_OUTPUT. Put_line (C_cr % ROWCAMOUNT);

    19 CLOSE C_cr;

    20 END;

    21.

    emp_detail e1;

    *

    ERROR on line 10:

    ORA-06550: line 10, column 12:

    PLS-00201: identifier "E1" must be declared.

    ORA-06550: line 10, column 12:

    PL/SQL: Ignored Element

    ORA-06550: line 14, column 17:

    PLS-00320: the declaration of the type of the expression is incomplete or

    Malformed

    ORA-06550: line 14, column 1:

    PL/SQL: SQL statement ignored

    ORA-06550: line 16, column 22:

    PLS-00320: the declaration of the type of the expression is incomplete or

    Malformed

    ORA-06550: line 16, column 1:

    PL/SQL: Statement ignored



    SQL > select * from v version $;

    BANNER

    ----------------------------------------------------------------

    Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Prod

    PL/SQL Release 10.2.0.1.0 - Production

    CORE 10.2.0.1.0 Production

    AMT for Linux: Version 10.2.0.1.0 - Production

    NLSRTL Version 10.2.0.1.0 - Production

    Thank you all;

    MY QUESTION IS: type_name, record_type must be the same?

    It is not necessary to be the same. Once you create a record type, then it might be assigned to different variables, such as:

    SQL > DECLARE

    2 C_cr CURSOR IS

    3. Select ename, equality, esalary, eid, ecity emp;

    4 TYPE EMP_DETAILS IS RECORD

    5 (e_id emp.eid%TYPE,

    6 e_name emp.ename%TYPE,

    7 e_qual emp.equal%TYPE,

    8 e_salary emp.esalary%TYPE,

    e_city 9 emp.ecity%TYPE);

    10 emp_detail EMP_DETAILS;

    11 emp_detail_2 EMP_DETAILS;

    12 emp_detail_3 EMP_DETAILS;

    13 l_id NUMBER;


    Now, he becomes similar to a variable_type of variable_name in the declaration section. Emp_detail or emp_detail_2 is a variable of type EMP_DETAILS, like the variable l_id that can hold values of type numbers.

  • How to read my ref cursor return user defined cursor type

    Hello
    I have the types defined as follows:
    TYPE MY_RECORD IS RECORD (
    COL1 TABLE1.COL1%TYPE,
    COL2 TABLE1.COL2%TYPE
       );
    
    TYPE MY_CURSOR IS REF CURSOR
    RETURN MY_RECORD;
    It is used as a return type in a stored procedure.
    I have a pl/sql block, where I make a call to MS that returns this cursor.
    How to read individual values for SP?
    SQL> create or replace package pkg
    as
       type my_record is record (col1 emp.empno%type, col2 emp.ename%type);
    
       type my_cursor is ref cursor
          return my_record;
    
       procedure p (cur out my_cursor);
    end pkg;
    /
    Package created.
    
    SQL> create or replace package body pkg
    as
       procedure p (cur out my_cursor)
       as
       begin
          open cur for
             select   empno, ename
               from   emp
              where   rownum <= 2;
       end p;
    end pkg;
    /
    Package body created.
    
    SQL> declare
       cur     pkg.my_cursor;
       e_rec   pkg.my_record;
    begin
       pkg.p (cur);
    
       loop
          fetch cur into   e_rec;
    
          exit when cur%notfound;
          dbms_output.put ('Empno: ' || e_rec.col1);
          dbms_output.put_line ('; Ename: ' || e_rec.col2);
       end loop;
    
       close cur;
    end;
    /
    Empno: 7369; Ename: SMITH
    Empno: 7499; Ename: ALLEN
    PL/SQL procedure successfully completed.
    
  • Querying the user-defined types

    I have a chart in which one of the columns is a user-defined data type:
    SQL> describe my_table
    ...
    USER_DATA    MYTYPE
    The type 'MYTYPE' is a simple object that contains a field: a CLOB called MESSAGE:
    SQL> describe mytype
    Name       Null?    Type
    ------     -----    ----
    MESSAGE          CLOB
    When I do a "select *...» "in this table, the USER_DATA column appears as"MYTYPE (oracle.sql.CLOB@898c2d).

    I know that for CLOB and BLOB fields, Developer SQL let me double click on the value and display the content. But for type like this defined by the user that contains a field, I can't navigate the data members of type. I find myself wanting to do something like a 'select user_data.message from my_table", but this is not a valid syntax. Is there a way to query a given specific member of this type defined by the user with the rest of the columns in the table, I can display the CLOB member instead of a representation of the object? If not, is it possible to configure SQL Developer to allow me to browse the data members of types defined by the user? TOAD has a feature like that but I would only use SQL Developer and it is a table that I work with on a regular basis.

    csimons,

    Try this:

    select  t1.user_data.message
    from    eimgr.aq_rtv_docs_out_table t1
    where   rownum = 1;
    

    See you soon

    Edited by: Frenchwood on September 22, 2009 22:38

  • Collections and user-defined objects

    Hello

    I try to use collections of user-defined object type, I am facing a problem here.

    The code below works well with the object varray straight forward.

    declare
    Typ_derv1 TYPE is varray (2) of varchar2 (100);

    v_test1 typ_derv1: = typ_derv1();
    Start

    v_test1.extend (1);

    v_test1 (1): = ' ID' 1 ';

    dbms_output.put_line (v_test1 (1));
    end;
    /

    CREATE OR REPLACE TYPE TYP_TEST1 AS OBJECT)
    ATTR_ID VARCHAR2 (10),
    ATTR_NAME VARCHAR2 (20)
    )
    /

    «The script below gives ' ORA-06530: composite unitialized reference "error message to the statement" v_test1 (1).» ATTR_ID: = ' ID' 1 ';

    declare
    Typ_derv1 TYPE is varray (2) of TYP_TEST1; GOLD TYPE typ_derv1 is table of the TYP_TEST1;

    v_test1 typ_derv1: = typ_derv1();
    Start

    v_test1.extend (1);

    v_test1 (1). ATTR_ID: = ' ID' 1 ';
    v_test1 (1). ATTR_NAME: = "Name1"


    dbms_output.put_line (v_test1 (1).) ATTR_ID | ', ' || v_test1 (1). ATTR_NAME);
    end;
    /

    But, when I give something like that, it works well, but is not a real collector's item so, it maintains just a variable with attributes structure.

    declare
    v_test1 TYP_TEST1: = TYP_TEST1 ("ID 1', 'Name1');
    Start

    dbms_output.put_line (v_test1. ATTR_ID | ', ' || v_test1. ATTR_NAME);
    end;
    /

    I tried like this, it gives me the same ' ORA-06530: reference to the composite unitialized' error in the statement "v_test1 (1).» ATTR_ID: = ' ID' 1 ';

    CREATE OR REPLACE TYPE TYP_COLL_TEST1 AS TABLE TYP_TEST1;

    declare
    v_test1 TYP_COLL_TEST1: = TYP_COLL_TEST1();
    Start

    v_test1.extend (1);

    v_test1 (1). ATTR_ID: = ' ID' 1 ';
    v_test1 (1). ATTR_NAME: = 'NAME 1';

    dbms_output.put_line (v_test1 (1).) ATTR_ID | ', ' || v_test1 (1). ATTR_NAME);
    end;
    /

    I tried something like this and it works,

    declare
    v_test1 TYP_COLL_TEST1;
    Start

    v_test1: = TYP_COLL_TEST1 (TYP_TEST1 ("ID 1', '1 NAME'), TYP_TEST1 ("ID 2', '2 NAME'));

    dbms_output.put_line (v_test1 (1).) ATTR_ID);
    dbms_output.put_line (v_test1 (1).) ATTR_NAME);

    dbms_output.put_line (v_test1 (2).) ATTR_ID);
    dbms_output.put_line (v_test1 (2).) ATTR_NAME);

    end;
    /

    But when I want to use something like that, I couldn't do it, I'm going in circles.

    vtest1.extend; _

    vtest1 (3): = TYP_COLL_TEST1 (TYP_TEST1 ("ID 'NAME 3' 3')); _

    vtest1 (3). ATTR_ID: = ' ID 3'; " _
    vtest1 (3). ATTR_NAME: = "NAME 3';" _

    Please give me some examples about handling this requirement, in particular objects defined by the user with collections as a VARRAY, nested Table and associative arrays, thank you.

    Frank Kulash, it would be better if you could give some explanations and examples.

    Only can Frank help? Or I'll make?

    Try

    declare
    v_test1 TYP_COLL_TEST1 := TYP_COLL_TEST1();
    begin
    
    v_test1.extend(1);
    v_test1(1) := typ_test1('ID 1', 'NAME 1');
    /*v_test1(1).ATTR_ID := 'ID 1';
    v_test1(1).ATTR_NAME := 'NAME 1';*/
    
    dbms_output.put_line(v_test1(1).ATTR_ID || ', ' || v_test1(1).ATTR_NAME);
    end;
    / 
    

    or

    declare
    v_test1 TYP_COLL_TEST1 := TYP_COLL_TEST1();
    begin
    
    v_test1.extend(1);
    v_test1(1) := typ_test1(null,null);
    v_test1(1).ATTR_ID := 'ID 1';
    v_test1(1).ATTR_NAME := 'NAME 1';
    
    dbms_output.put_line(v_test1(1).ATTR_ID || ', ' || v_test1(1).ATTR_NAME);
    end;
    / 
    

    Published by: Paul Horth on March 8, 2012 07:01

  • MS Intellimouse Explorer 2.0 has user programmable buttons, but this mouse is very hard to find. Is there an another wireless mouse which has programmable buttons user-defined?

    MS Intellimouse Explorer 2.0 has user programmable buttons, but this mouse is very hard to find. Is there an another wireless mouse which has programmable buttons user-defined?

    Thank you

    OOPS - I just read the description of the site and realize that this is the wrong forum for my questions.

    I'm sorry.

  • When I print my paper to "user-defined" size in Thunderbird by default instead of "letter". Have to change manually, but does not.

    I use a printer Brother HL-6180DW and the paper size to default printer to 'letter' 8 1/2 x 11 on everything, except
    When you try to print an email from Thunderbird. If I manually change the paper size in Thunderbird to the letter, it maintains for that impression, then default to "user-defined" which is 3.0 x 5.0. How to make the default format letter? Thank you.

    I have answered hundreds of posts here every month. Most of the time I don't know who or what 5 seconds after I'm done.

    I did not add... I said to delete. You can remove all in printers and when you restart Thunderbird and try and print with the selected printer is the will add stuff if needed. So bite the bullet and simply delete away.

  • Use of user defined function in mathscript containing a structure

    Hi, I am a novice user of LabView MathScript module,

    I have the following problem when integrating my code MATLAB, LabView, for HMM: in my program, I tried to call a MATLAB called "mixgaussinit.m" user-defined function, it shows this error...

    "

    I just noticed that these files appear to be copyrighted. My first question is do you have author permissions to post them in a public forum? If this isn't the case, then you can remove them. That being said, I have reviewed the code and it seems easy enough to work around your problems (provided that you have the copyright permissions). How to bypass the problems is to replace the fields of the struct with variables. There is of course allows you to change some definitions of functions for input and output the necessary variables which I think was the best 5 variables. You will also need to redo the code that uses a table of error checking cell. In total, I estimated about 30 minutes of work. I would have given you work around these files had not been protected by copyright. So, unfortunately, you will need to implement the work around you.

  • variables of user-defined data transfer

    Hello

    I use the etherCAT 9144 chassis and is only supported by this hardware FIFO range target. After a search, I realized that the only way to transfer data from FPGA to the host by using user-defined variables. But these variables do not support the notion of FIFO. So which is the best practice to transfer data after measures (provable 10 Hz measurement of 15 values) to host VI?

    Thank you

    As mentioned, the 9144 only supports the analytical engine.

    In regards to what you do, it really depends on the entire application. For example, what is the master? Are there other systems at issue here? Etc. It's a good read, in general, although it might not help this second right: http://www.ni.com/white-paper/14151/en/

    A high level, you need to decide what you need. If you have need for deterministic communication, low-latency over long distances from a RT controller, the 9144 is probably the right choice. If you need low latency + streaming over short distances to a RT controller, you should look into the RIO MXI chassis. If you need mainly not deterministic low speed (10 hz) data mixed with low flow continuous over long distances to a windows or host RT, then ethernet expansion rio (9146,7,8,9) is probably the right choice. If you need high speed continuous with low control latency over long distances to a windows or RT host, you need a full cRIO controller. Based on what you've posted so far, its uncertain is the right person.

    Lets say you're stuck with the 9144 for now. As you can easily hit 1 kHz scanning cycles, it should be perfectly possible to data 'stream' to 10 Hz. If you run the scan at 1 kHz engine, then you are 100 x oversampling. Where it gets complicated is this requirement of sync. By default, acquisition input/output is synchronized to the clock of the scan (and you can see when the clock of scan is set by a knot of e/s FPGA). However, you can take complete control of a module in the FPGA and read inputs and outputs at any time if you please. In other words, you can set up so when DIO0 goes high you immediately enjoy all the values of AI 15. You can then transfer these values HAVE switched to the host using the user-defined variables.

  • How to create user defined groups and users with custom permissions as only open and export in obiee 11 g?

    Hello

    I want to give as open & export to the level of permissions.

    How to create user defined groups and users with custom permissions as only open and export in obiee 11 g?

    For example, if the group permissions, inturn should reflect on the users.

    Please help me.

    Thanks in advance,

    A.Kavya.

    Your question is quite broad and fuzzy then I suggest the security catalog presentation to read documentation: http://docs.oracle.com/middleware/1221/biee/BIESC/mgrgrpsusers.htm#CIHIBJGD

    And I think that you mix you two things which are managed in different places:

    ) an object as read access permissions, write, delete... which control you through the object "Permissions" dialog box

    (b) functional privileges controlled through "Manage privileges" under "Administration".

  • Extracts &amp; user defined Variables

    After ~ 5 years not working not with any what HAT, I started a new post on 28/03/2016 and put back the trial HR 2015 a spin. I'm very excited by what I see and were able to do so far.

    I have 3 'entities' to write and I created 3 pages, one page per entity.

    Each of these presentation pages, I have this first line:

    |

    This section describes how to enter and manage [entity].

    |

    I set each [entity] as a user-defined variable. Each page with this sentence I hard-coded and added a reference to the user defined Variable and then produced output. Works great.

    Now, I'm going 'down' a level. What I want to know is how to

    |

    "This section describes how enter and manage."

    |

    be a code snippet. I want it to be an excerpt because when I write a sentence better, I don't have to make the same change on each of these presentation pages. Finally, there are 19 pages of presentation.


    Anyone who structure their content like this?


    What I want to avoid doing several manual changes. For example, if the following examples have been in a RoboHelp project, on https://support.assessment.pearson.com/x/N4Dy, there is this sentence:


    This section shows you how to manage user accounts.


    On this page - support to manage test paper - next to PearsonAccess online User Guide - Pearson Assessment - it is this sentence:


    This section covers all the unique aspects of the test paper.


    What I'm trying to do, is to have an extract which is defined as:


    This section tells you how to


    and refer to it on both pages.

    On the first page, it looks like

    from <>this section tells you how to< / endSnippet >

    user accounts < beginUserDefinedVariable >< / endUserDefinedVariable >.

    Then on the second page, I would say this:

    extract < code > This section tells you how to < / endSnippet >

    < beginUserDefinedVariable > manage paper test < / endUserDefinedVariable >.

    |

    The reason why I want it as a snippet of code is because I don't want to have to maintain "this section tells you how to" text hardcoded on each of these presentation pages. I would like to take advantage of the functionality of content reuse to avoid a bunch of copy / paste or even find / replace.

    Thanks for any help!

    Paul Hanson

    RoboHelp MVP of looonnngggg a long time ago...

    But what you might want to consider, is another variable to contain the desired text in the code snippet. This could be inserted inline. Then update you only in the variable.

    Just thinking out loud a bit.

    See you soon... Rick

  • registration of user-defined presets error

    I transferred all my programs to my new computer, Windows 10 using Zinstall. All the programs work very well except for Illustrator. When I close it, I get two errors: -.

    User-defined Favorites registration error

    Presets contours registration error

    I uninstalled and reinstalled but the error is still there.

    Thanks a lot for your suggestions

    Giroux,

    I think that the good order/way is to update the operating system, and then reinstall the applications. Which was how you did it?

    It may be best to reinstall using the way complete three steps (the otherwise strange things may persist):

    (1) uninstall (check the box to delete the preferences),

    (2) run the cleanup tool, see the link below,

    (3) reinstall.

    http://www.Adobe.com/support/contact/cscleanertool.html

  • user-defined types

    Hi all

    I have a function that returns a type defined by the user in my sql environment. The type consists of 5 different columns. I pass a ref_id to my function, on the basis of which he does some calculations and returns me the type.

    create or replace type my_type

    (

    number of col1,

    col2 varchar2 (100),

    COL3 varchar2 (10),

    number of COL4,

    number of col5

    )

    create or replace function fun (number in_id) return my_type

    as

    Start

    -code1

    -code2

    Return (my_type)

    end;

    In my sql environment, I have a table which is the following structure

    create table tab1

    (

    number of emeline

    upgvc varchar2 (100),

    number of Ref_ID, - this ref_id when it is passed to the function above will return a populated user-defined type values.

    number of col1,

    col2 varchar2 (100),

    COL3 varchar2 (10),

    number of COL4,

    number of col5

    )

    I have a table tab2, using which i will be filling of the columns of the table tab1, tab2 table structure is as below

    create table tab2

    (

    number of emeline

    upgvc varchar2 (100),

    number of Ref_ID)

    now I have to fill each column in table tab1, tab2 table and my pleasure to feature.

    something like

    Insert into tab1

    Select emeline,

    upgvc,

    Ref_ID,

    Rest of the values must be completed by calling the function using the ref_id and fill in the values. What would be the best way to do it? I have millions of records with it. I tried to use this with the function of REGAL and tried fill lines, but its slow.  All of the suggestions.

    Note: apologies for not sticking scripts and the original code since it will take days

    Thank you

    Rahul

    PetervdZwan wrote:

    Hello

    I agree that you shouldn't calc function for each attribute. But you don't need an extra table for this type.

    See below:

    Not sure what you mean:

    SQL > set serveroutput on
    SQL > select a.deptno,.
    2 a.f.col1 col1,
    a.f.col2 3 col2,
    4 a.f.col3 col3,
    5 a.f.col4 col4,
    6 a.f.col5 col5
    7 of)
    8. Select wagneur, f1 (deptno) f
    scott.dept 9 d
    10          ) a
    11.

    DEPTNO COL1 COL2 COL3 COL4 COL5
    ---------- ---------- ---------- ---------- ---------- ----------
    10         10 A          B                   2          3
    20         20 A          B                   2          3
    30         30 A          B                   2          3
    40         40 A          B                   2          3

    Call to F1
    Call to F1
    Call to F1
    Call to F1
    Call to F1
    Call to F1
    Call to F1
    Call to F1
    Call to F1
    Call to F1
    Call to F1
    Call to F1
    Call to F1
    Call to F1
    Call to F1
    Call to F1
    Call to F1
    Call to F1
    Call to F1
    Call to F1
    SQL >

    As you can see, function runs again 5 times by each line. You need to materialize in line of sight. It can be done using NO_MERGE:

    SQL > select a.deptno,.
    2 a.f.col1 col1,
    a.f.col2 3 col2,
    4 a.f.col3 col3,
    5 a.f.col4 col4,
    6 a.f.col5 col5
    7 of)
    8 select / * + no_merge * /.
    wagneur, f1 (deptno) 9 f
    scott.dept 10 d
    11          ) a
    12.

    DEPTNO COL1 COL2 COL3 COL4 COL5
    ---------- ---------- ---------- ---------- ---------- ----------
    10         10 A          B                   2          3
    20         20 A          B                   2          3
    30         30 A          B                   2          3
    40         40 A          B                   2          3

    Call to F1
    Call to F1
    Call to F1
    Call to F1
    Call to F1
    Call to F1
    SQL >

    However, I have and I know not why, the function is called not 4 but 6 times, using the type of collection (as in my first response) causes function calls only 4 - one per each line.

    SY.

  • Using java user-defined aggregate function

    Hello

    I'm trying to implement a with Java user-defined aggregate function.

    Here's the Code Javaclass:

    Import Java.util;
    Oracle.sql import. *;
    import java.sql. *;
    import Java.Math.BigDecimal;
    Oracle import. CartridgeServices.*;

    stored the context type

    public class StoredCtx_SecMax
    {
    private BigDecimal b_max;
    private BigDecimal b_secmax;

    public StoredCtx_SecMax()
    {
    b_max = new BigDecimal (0);
    b_secmax = new BigDecimal (0);
    }

    public void SchreibeMax (entry BigDecimal)
    {
    b_max = entry;
    }

    public void SchreibeSecMax (entry BigDecimal)
    {
    b_secmax = entry;
    }

    public BigDecimal LeseMax()
    {
    Return b_max;
    }

    public BigDecimal LeseSecMax()
    {
    Return b_secmax;
    }
    }

    implementation type

    / public class SecondMax_j implements SQLData
    {
    BigDecimal private key;

    Ultimate SUCCESS of static BigDecimal = new BigDecimal (0);
    Final static BigDecimal ERROR = new BigDecimal (1);


    Implement the SQLData interface.

    String sql_type;
    public String getSQLTypeName() throws SQLException
    {
    Return sql_type;
    }

    ' Public Sub readSQL (SQLInput stream, string typeName) throws SQLException
    {
    sql_type = typeName;
    key = stream.readBigDecimal ();
    }

    Public Sub writeSQL (SQLOutput stream) throws SQLException
    {
    stream.writeBigDecimal (key);
    }


    methods of the type that implements ODCITable interface

    public static BigDecimal ODCIAggregateInitialize (oracle.sql.STRUCT [] sctx)
    throws SQLException
    {
    Connection Conn = DriverManager.getConnection("jdbc:default:connection:");

    create a stored environment and store the result set in it
    StoredCtx_SecMax ctx = new StoredCtx_SecMax();

    context of registry stored with cartridge services
    Touch int;
    try {}
    key = ContextManager.setContext (ctx);
    } catch {} (EC CountException)
    error return;
    }

    Create an instance of StockPivotImpl and store the key of
    Object [] impAttr = new Object [1];
    impAttr [0] = new BigDecimal (key);
    StructDescriptor sd = new StructDescriptor ("SECONDMAX_J", conn);
    SCTX [0] = new STRUCT(sd,conn,impAttr);

    return a SUCCESS;
    }

    public BigDecimal ODCIAggregateIterate (BigDecimal input)
    throws SQLException
    {
    retrieve the context stored with the key
    CTX StoredCtx_SecMax;
    try {}
    CTX = (StoredCtx_SecMax) ContextManager.GetContext (Key.intValue ());
    } catch (InvalidKeyException ik) {}
    error return;
    }

    BigDecimal b_max;
    BigDecimal b_secmax;

    b_max = ctx. LeseMax();
    b_secmax = ctx. LeseSecMax();

    If (eingabe.compareTo (b_max) == 1)
    {
    CTX. SchreibeSecMax (b_max);
    CTX. SchreibeMax (input);
    }
    on the other
    {
    If (eingabe.compareTo (b_secmax) == 1)
    {
    CTX. SchreibeSecMax (input);
    }
    }

    return a SUCCESS;
    }

    public BigDecimal ODCIAggregateTerminate (double [] returnValue, int flags) throws SQLException {}

    retrieve the context stored with the key
    CTX StoredCtx_SecMax;
    try {}
    CTX = (StoredCtx_SecMax) ContextManager.clearContext (Key.intValue ());
    } catch (InvalidKeyException ik) {}
    error return;
    }

    returnValue [0] = ctx. LeseSecMax () .doubleValue ();

    CTX = null;

    return a SUCCESS;
    }


    public BigDecimal ODCIAggregateMerge (oracle.sql.STRUCT ctx2) throws SQLException {}


    return a SUCCESS;
    }
    }


    To implement this in the database, I use the following script:

    CREATE OR REPLACE TYPE IMPROG. SECONDMAX_J as object

    (
    INTEGER key,

    public static function ODCIAggregateInitialize (sctx IN OUT SECONDMAX_J)

    Return number
    IN THE JAVA LANGUAGE
    NAME "Java.Math.BigDecimal return from SecondMax_j.ODCIAggregateInitialize (oracle.sql.STRUCT []).
    ,



    Member ODCIAggregateIterate (self IN OUT SECONDMAX_J function,

    Number return value)
    IN THE JAVA LANGUAGE
    NAME "Java.Math.BigDecimal SecondMax_j.ODCIAggregateIterate return (Java.Math.BigDecimal).
    ,



    Member ODCIAggregateTerminate (self IN SECONDMAX_J function,

    Return returnValue NUMBER, flags in number number)
    IN THE JAVA LANGUAGE
    NAME "Java.Math.BigDecimal return of SecondMax_j.ODCIAggregateTerminate (double [], int).
    ,



    Member ODCIAggregateMerge (self IN OUT SECONDMAX_J function,

    CTX2 IN SECONDMAX_J) return number
    IN THE JAVA LANGUAGE
    NAME "Java.Math.BigDecimal SecondMax_j.ODCIAggregateMerge return (oracle.sql.STRUCT)".
    );
    /

    CREATE OR REPLACE FUNCTION F_SECONDMAX_J (NUMBER value) RETURN NUMBER

    PARALLEL_ENABLE

    AGGREGATION to the HELP of SecondMax_j;
    /



    When I now use the F_SECONDMAX_J function.

    "(Columnname) select F_SECONDMAX_J from Tablename t;

    It works perfectly and shows me the right result.

    Then I tried to implement the fusion part as follows:

    public BigDecimal ODCIAggregateMerge (oracle.sql.STRUCT ctx2) throws SQLException {}

    BigDecimal Key2 = null;

    BigDecimal ctx_max = null;
    BigDecimal ctx_secmax = null;

    BigDecimal ctx2_max = null;
    BigDecimal ctx2_secmax = null;

    retrieve the context stored with the key
    StoredCtx_SecMax ctx = null;
    try {}
    CTX = (StoredCtx_SecMax) ContextManager.GetContext (Key.intValue ());
    } catch (Exception e) {}

    }

    Object [] impAttr = ctx2.getAttributes ();

    Key2 = (BigDecimal) impAttr [0];

    retrieve the second context stored using the key2
    StoredCtx_SecMax ctx_sec = null;
    try {}
    ctx_sec = (StoredCtx_SecMax) ContextManager.GetContext (key2.intValue ());
    } catch (Exception e) {}

    }

    ctx_max = ctx. LeseMax();
    ctx_secmax = ctx. LeseSecMax();

    ctx2_max = ctx_sec. LeseMax();
    ctx2_secmax = ctx_sec. LeseSecMax();

    If (ctx2_max.compareTo (ctx_max) == 1)
    {
    If (ctx2_secmax.compareTo (ctx_secmax) == 1)
    {
    CTX. SchreibeSecMax (ctx2_secmax);
    }
    on the other
    {
    CTX. SchreibeSecMax (ctx_max);
    }
    CTX. SchreibeMax (ctx2_max);
    }
    on the other
    {
    If (ctx2_max.compareTo (ctx_secmax) == 1)
    {
    CTX. SchreibeSecMax (ctx2_max);
    }
    }

    return a SUCCESS;
    }

    When I now try the function

    "Select / * + parallel (t 4) * / F_SECONDMAX_J (Columnname) of Tablename t;

    I always get a pointer NULL-error because the variable key2 is always 0 and therefore the functions LeseMax() and LeseSecMax()
    in the second context 'ctx_sec' produce this error NULL pointer.

    To me it seems that each parallel process is the construction of an additional class for himself, which is not available are my main process.

    My question is now how it is possible to access the context of stored of the parallel process, so that I can combine the results.

    Thank you very much

    Josef

    Hi Josef,

    just guess that I've never implemented with java user-defined aggregate functions or support parallel execution:

    Maybe you have to implement ODCIAggregateWrapContext?

    + Application of ODCIAggregateWrapContext is optional. It should be implemented only when the external memory is used to hold the aggregative, context and the user-defined aggregate is evaluated in parallel (which is, stated as PARALLEL_ENABLE). If the user-defined aggregate is not evaluated in parallel, ODCIAggregateWrapContext is not necessary. +
    [http://docs.oracle.com/cd/B12037_01/appdev.101/b10800/dciaggfns.htm#i1004974]

    Report it to progress and success.

    Good luck
    Rainer Stenzel

Maybe you are looking for