Custom DataType in Oracle Database.

Oracle provides the predefined types which developer can use in the PL/SQL. Those types are like NUMBER, ARRAYOFNUMBERS, VARCHAR2 and many more. 

Developer who consumes PL/SQL from JAVA can easily use those types in case of normal scenario. But consider a scenario where, developer want to send collections to PL/SQL, then how that would be possible. So, oracle have provided an option to create own custom types as per requirement and use that types in PL/SQL. That custom type support essay access to data types from JAVA and speed up execution and developer can achieve performance too.

Syntax of creation of custom type:-

#1 TABLEOF3STRINGS:-
create or replace TYPE "TRIPLETOFSTRINGS" as object (field1 varchar2(20), field2 varchar2(20), field3 varchar2(20));
create or replace TYPE "TABLEOF3STRINGS" as table of TripletOfStrings;

#2 Structure with number field:-
create or replace TYPE "LINEITEM" as object (item_name varchar2(30),quantity number, unit_price number(12,2) );

Once the above type are created in oracle then developer needs to build the collection accordingly and needs to send to PL/SQL. 

In Case of tableof3number, "Collection.toArray(new String[Collection.size()][2]);" would be the call to send data to PL/SQL function or procedure call. 

Developer needs to have own JDBCType implementation for that new custom data types. Existing implementation from JDBCType will be helpful to implement that custom datatype in JAVA. 



  

Comments

Popular posts from this blog

Reverse String, Unchanged position of special characters.

Java 8 Questions.