Plsql object type polymorphism
Hi everyone.
Is adhoc polymorphism possible in pl/sql using Oracle's object types? Here is some sample code that I tried on an Oracle 10.2.0.3 64-bit database running on Solaris.
Connected.
09:58:58 SQL> create type root_ty as object (
09:59:03 2 a1 varchar2(32 char)
09:59:03 3 ) not final
09:59:03 4 /
Type created.
Elapsed: 00:00:00.17
09:59:05 SQL> create type sub_ty under root_ty (
09:59:10 2 a2 varchar2(32 char)
09:59:10 3 , constructor function sub_ty(str in varchar2) return self as resul
09:59:10 4 , member procedure display_a2
09:59:10 5 ) final
09:59:10 6 /
Type created.
Elapsed: 00:00:00.06
09:59:12 SQL> create or replace type body sub_ty is
09:59:18 2 constructor function sub_ty(str in varchar2)
09:59:18 3 return self as result
09:59:18 4 is
09:59:18 5 begin
09:59:18 6 self.a2 := str;
09:59:18 7
09:59:18 8 return;
09:59:18 9 end;
09:59:18 10
09:59:18 11 member procedure display_a2
09:59:18 12 is
09:59:18 13 begin
09:59:18 14 dbms_output.put_line('a2 value is .... '||a2);
09:59:18 15 end;
09:59:18 16 end;
09:59:18 17 /
Type body created.
Elapsed: 00:00:00.04
09:59:20 SQL> set serveroutput on
10:00:31 SQL> declare
10:00:35 2 l_ty root_ty;
10:00:35 3 begin
10:00:35 4 l_ty := new sub_ty('Woot!');
10:00:35 5
10:00:35 6 l_ty.display_a2();
10:00:35 7 end;
10:00:35 8 /
l_ty.display_a2();
ERROR at line 6:
ORA-06550: line 6, column 8:
PLS-00302: component 'DISPLAY_A2' must be declared
ORA-06550: line 6, column 3:
PL/SQL: Statement ignored
Elapsed: 00:00:00.06
10:00:37 SQL> declare
10:00:53 2 l_ty root_ty;
10:00:53 3 begin
10:00:53 4 l_ty := new sub_ty('Woot!');
10:00:53 5
10:00:53 6 -- l_ty.display_a2();
10:00:53 7 end;
10:00:53 8 /
PL/SQL procedure successfully completed.
Elapsed: 00:00:00.01
10:00:53 SQL> declare
10:01:30 2 l_ty sub_ty;
10:01:30 3 begin
10:01:30 4 l_ty := new sub_ty('Woot!');
10:01:30 5
10:01:30 6 l_ty.display_a2();
10:01:30 7 end;
10:01:30 8 /
a2 value is .... Woot!
PL/SQL procedure successfully completed.Certainly seems like this should be possible ... Am I missing something simple?
Thanks for any input.
- KR
Here is an example of what polymorphism is supposed to do:
SQL> create type bird as object
2 (name varchar2 (30)
3 , member function fly return varchar2
4 , member function make_a_noise return varchar2)
5 not final
6 /
Type created.
SQL>
SQL> create type birds_nt as table of bird;
2 /
Type created.
SQL>
SQL>
SQL> create or replace type body bird as
2
3 member function fly return varchar2
4 is
5 begin
6 return 'my name is '||self.name;
7 end;
8
9 member function make_a_noise return varchar2
10 is
11 begin
12 return 'generic twitter';
13 end;
14
15 end;
16 /
Type body created.
SQL>
SQL>
SQL> create type duck under bird (
2 overriding member function make_a_noise return varchar2
3 , member procedure waddle
4 );
5 /
Type created.
SQL>
SQL> create or replace type body duck as
2
3
4 overriding member function make_a_noise return varchar2
5 is
6 begin
7 return 'quack!';
8 end;
9
10 member procedure waddle
11 is
12 begin
13 null;
14 end;
15
16
17 end;
18 /
Type body created.
SQL>
SQL>
SQL>
SQL> create type chicken under bird (
2 overriding member function make_a_noise return varchar2
3 , member procedure peck
4 )
5 not final;
6 /
Type created.
SQL>
SQL> create or replace type body chicken as
2
3
4 overriding member function make_a_noise return varchar2
5 is
6 begin
7 return 'cluck!';
8 end;
9
10 member procedure peck
11 is
12 begin
13 null;
14 end;
15
16
17 end;
18 /
Type body created.
SQL>
SQL> create type canary under bird (
2 overriding member function make_a_noise return varchar2
3 );
4 /
Type created.
SQL>
SQL> create or replace type body canary as
2
3
4 overriding member function make_a_noise return varchar2
5 is
6 begin
7 return 'I taught I taw a puddy tat!!!';
8 end;
9
10
11 end;
12 /
Type body created.
SQL>
SQL> create type rooster under chicken (
2 overriding member function make_a_noise return varchar2
3 )
4 ;
5 /
Type created.
SQL>
SQL> create or replace type body rooster as
2
3
4 overriding member function make_a_noise return varchar2
5 is
6 begin
7 return 'That''s a joke... I say, that''s a joke, son.';
8 end;
9
10
11 end;
12 /
Type body created.
SQL>
SQL>
SQL>
SQL>
SQL> declare
2 my_aviary birds_nt := birds_nt();
3 begin
4 my_aviary.extend(5);
5 my_aviary(1) := duck('Donald');
6 my_aviary(2) := chicken('Chicken Little');
7 my_aviary(3) := canary('Tweetie Pie');
8 my_aviary(4) := rooster('Foghorn Leghorn');
9 my_aviary(5) := bird('?');
10 for idx in my_aviary.first()..my_aviary.last()
11 loop
12 dbms_output.put_line( my_aviary(idx).fly() );
13 dbms_output.put_line( my_aviary(idx).make_a_noise() );
14 end loop;
15 end;
16 /
my name is Donald
quack!
my name is Chicken Little
cluck!
my name is Tweetie Pie
I taught I taw a puddy tat!!!
my name is Foghorn Leghorn
That's a joke... I say, that's a joke, son.
my name is ?
generic twitter
PL/SQL procedure successfully completed.
SQL>Now, in that loop woudl it make sense to execute a peck() on all of those entries? Nope. Furthermore as far as I can tell it is not possible to find out what sub-type an object is from with PL/SQL, so you couldn't even use Padders's TREAT ploy.
So: if you want to do something generic use a super-type. If you want to do something specific use a sub-type.
Cheers, APC
blog: http://radiofreetooting.blogspot.com
Similar Messages
-
I have a plsql object which is a subclass of a super class. How do I exactly determine the instance of the object?
SYS_TYPEID function can be used in a query to return the typeid of the most specific type of the object instance passed to the function as an argument.
See how to get the text name of an object's type:
http://www.toadworld.com/Knowledge/DatabaseKnowledge/DatabaseTips/OracleTips/tabid/311/Default.aspx
categories "PL/SQL 2006": "How to get the text name of an object's type"
Regards,
Zlatko -
Difference between MAP member and ORDER member method in PLSQL Object Type
Hi all,
I need to know clear explanation about the MAP and ORDER member method and its Difference.Please share if you know.
thanks in advance.
regards,
Lokesh
Edited by: 972864 on Dec 10, 2012 1:50 AMhttp://docs.oracle.com/cd/B28359_01/appdev.111/b28371/adobjbas.htm#autoId13
-
How to define object type in plsql
I create a type...
CREATE OR REPLACE TYPE t_Archive_Data_Obj AS OBJECT
(Archive_Name VARCHAR2(40), Archive_Data CLOB);
I create a type in plsql.....
TYPE tt_Archive_Data IS TABLE OF t_Archive_Data_Obj;
Can I, instead of creating the object type as a database object, some how define the same in plsql and then create a table type and use.
Thanks & Regards.coz I'm using it as an out parameter in plsql procedure and this procedure is called by a java application.
Now to access this type in java to get the returned value I used Jpublisher to generate a class, this class is being used in java application.
I'm sorry I have not check one thing that now if I instead used record in plsql and try to access the returned value using the same class will it work or not. I should have tested then asked questions on forum.
Regards. -
Can plsql return table of object type
Dear All,
I am trying to return a set of data using object type.
But i am able to return only a single row but I want to return multiple rows.
I am trying to create the procedure which will return the table of object type but I am not able to assign value to table of object type.
Any ideas will be appreciated.
Regards
AbhishekArchitectView wrote:
The intention is to create a tree structure of data.Is this structure stored in the database? If so, then what data model is used? Relational? Hierachical? Object?
Each of these have pros and cons. The object model has many when persisted in a database as it nowhere near as flexible and robust as relational. Simple example, you can define an object class called Address. You can define a collection class called addressList. You can make that collection class a column in the Customers table. This allows you to store multiple addresses for a customer - as part of the same row for a customer.
However, there is a data modeling issue here. How do you index the region code in the address to do region based sales and marketing queries? There is a performance issue here - every time a customer row is read, the Addresses column is also read and this column contains a collection of addresses... Expensive I/O wise.
If relational data model was used, there would have been an Addresses table. It would have had a region index. And every time you read a customer row, all the addresses of that customer is not automatically read into memory too.
This Pl/SQL is to be called by another program which will accept the tree structure.So PL/SQL is to deliver a tree structure class?
You have mentioned about the design being not optimal, please elaborate.
I am doing these steps to improve performance.
i already have a java code which creates the data in the tree form {common data model - XML} .
I am thinking that if I create the structure in database , it will be better for performance.What makes sense to me (performance, usability and data modeling wise) is to use a relational design to store the tree data in Oracle. Each tree item will have a unique identifier and an optional parent identifier. The latter will be a foreign key constraint to the unique identifier.
The PL/SQL procedure can use a hierachical SQL to select the relevant root nodes from the tree table (i.e. start with tree items that have null parent identifiers) and transform this into a XML and supply XML output.
This allows Java to call this PL/SQL procedure, and get XML in response.
An alternative would be to not use XML, but instead define the tree structure as Java expects it, using SQL advance data types (i.e. classes). But instead of using that for store of the tree's data, the PL/SQL proc uses it to transform the tree data (selected via a hierarchical query) into this class object structure.
The Java client then needs to have wrapper classes for these SQL classes - and when it calls the PL/SQL proc, it gets a class structure returned that it can natively use on its side.
This a tad more complex to do than the XML interface - but could be faster as the Java layer does not need to transform the XML into a local data structure... it gets an equivalent data structure directly from PL/SQL.
The only issue ito performance I can see, is attempting to use such an object structure also as data storage (Oracle table) structure. This is usually less than optimal. Fair to say, that relational data modeling still reigns supreme ito usability, integrity and performance. (at least within RDBMS products, like Oracle) -
How to handle plsql Object and Table type inside BPEL
Hi All,
I have a procedure with 5 IN and 4 OUT parameters. Out of 4, One is Object type and remaining 3 are Table type. Now in my bpel, i am calling this proc from DB Adapter. The DB Adapter wizard created XSD with proper structure. But when i am testing this i am not getting these out parameters values in the payload of Invoke DBAdapter activity. I am neither getting errors nor output.
What could be the issue.?
Thanks in advance,
SudheerArik,
JDev is not creating any wrapper packages as such. It simply created a XSD with same as my procedure name.
My XSD looks like this...
<element name="OutputParameters">
<complexType>
<sequence>
<element name="P_OBJ_H_INFO_O" type="db:APPS.H_OBJ_TYPE" db:index="6" db:type="Struct" minOccurs="0" nillable="true"/>
<element name="P_TAB_L_INFO_O" type="db:APPS.L_TAB_TYPE" db:index="7" db:type="Array" minOccurs="0" nillable="true"/>
<element name="P_TAB_M_INFO_O" type="db:APPS.M_TAB_TYPE" db:index="8" db:type="Array" minOccurs="0" nillable="true"/>
<element name="P_TAB_A_INFO_O" type="db:APPS.A_TAB_TYPE" db:index="9" db:type="Array" minOccurs="0" nillable="true"/>
</sequence>
</complexType>
</element>
And again the 3 table types internally referring object types.
Thanks for reply. Awaiting response...
Sudheer -
Require help on Array of Nested tables and Oracle Object type
Hi All,
I have a scenario where I have some millions of records received from a flat file and the record is stored in Table as below:
Tablename: FILE_RECORD
Rows:
FILE_REG_ID = 1
RECORD_NBR = 1
PROCESSED_IND = U
RECORD= 00120130326006A
FILE_REG_ID = 1
RECORD_NBR = 2
PROCESSED_IND = U
RECORD= 00120130326003
1) I have to read these records at once and
a) Split the RECORD column to get various other data Eg: Fld1=001, Fld2=20130326, Fld3 = 003
b) send as an Array to Java.
2) Java will format this into XML and sent to other application.
3) The other application returns a response as Successful or Failure to Java in XML
4) Java will send RECORD_NBR and the corresponding response as Success or Failure back to PLSQL
5) PLSQL should match the RECORD_NBR and update the PROCESSED_IND = P.
I 'm able to achieve this using SQL Table type by creating a TYPE for Each of the fields (Flds) however the problem is Java cannot Access the parameters as the TYPE are of COLUMN Types
Eg: For RECORD_NBR
SUBTYPE t_record_nbr IS FILE_RECORD.T010_RECORD_NBR%TYPE;
Can you please let me know how I can achieve this to support Java, I know one way that is by creating an OBJECT TYPE and a TABLE of the OBJECT TYPE.
Eg: T_FILE_RECORD_REC IS OBJECT
FILE_REG_ID number(8), RECORD_NBR number (10), PROCESSED_IND varchar2(1), RECORD varchar(20)
Create type T_FILE_RECORD_TAB IS TABLE OF T_FILE_RECORD_REC
However I'm facing a problem to populate an Array of records, I know I'm missing something important. Hence please help.
It would be helpful to provide some guidelines and suggestions or Pseudo or a Code to achieve this. Rest all I can take up further.
Thanks in advance,I know once way that is creating a OBJECT TYPE and a TABLE of OBJECT TYPE, howeve I feel I'm missing something to achieve this.You're right, you need SQL object types created at the database level. Java doesn't know about locally defined PL/SQL types
However you can do without all this by creating the XML directly in PL/SQL (steps 1+2) and passing the document to Java as XMLType or CLOB.
Are you processing the records one at a time? -
i have problem with using or calling the methods declared in object type body
how to call a method which is part of database object
from form 6i
i can use it in PLsql but HOW i can do it inside form
its important to me
r there any 1 can helpcursor 4_emp_obj
select emp_obj( from_table_l_name, from_table_l_no, from_table_l_salary)
from table
where will_ok = 'I hope so';
FETCH 4_emp_obj BULK COLLECT INTO emp_obj_array LIMIT 1000 ;
... so quick ... -
How can I obtain an object-type variable in Forms 6i?
i create an object-type in oracle 8i database like this:
TYPE OBJ_TYPE_NUMBER AS OBJECT
FIELD1 NUMBER,
MEMBER PROCEDURE INIT, ...
i create a variable of this object-type in a stored procedure in Oracle 8i:
v_Number OBJ_TYPE_NUMBER(10);
and then call it's method:
v_Number.INIT;
it work's!
But when I try to compile a previous variable declaration
(v_Number OBJ_TYPE_NUMBER;) in Oracle Forms 6i I see only an error message.
So my question is How can I declare and use an object-type variable in Forms 6i?Hi,
the release after Forms 6i is Forms9i. Forms9i does have the PLSQL engine of Oracle 9.0.0.2 database which means that it should knwo how to handle object types in PLSQL.
Frank -
Invoking stored procedure that returns array(oracle object type) as output
Hi,
We have stored procedures which returns arrays(oracle type) as an output, can anyone shed some light on how to map those arrays using JPA annotations? I tried using jdbcTypeName but i was getting wrong type or argument error, your help is very much appreciated. Below is the code snippet.
JPA Class:
import java.io.Serializable;
import java.sql.Array;
import java.util.List;
import javax.persistence.Entity;
import javax.persistence.Id;
import org.eclipse.persistence.annotations.Direction;
import org.eclipse.persistence.annotations.NamedStoredProcedureQuery;
import org.eclipse.persistence.annotations.StoredProcedureParameter;
* The persistent class for the MessagePublish database table.
@Entity
@NamedStoredProcedureQuery(name="GetTeamMembersDetails",
procedureName="team_emp_maintenance_pkg.get_user_team_roles",
resultClass=TeamMembersDetails.class,
returnsResultSet=true,
parameters={
@StoredProcedureParameter(queryParameter="userId",name="I_USER_ID",direction=Direction.IN,type=Long.class),
@StoredProcedureParameter(queryParameter="employeeId",name="I_EMPLOYEEID",direction=Direction.IN,type=Long.class),
@StoredProcedureParameter(queryParameter="TEAMMEMBERSDETAILSOT",name="O_TEAM_ROLES",direction=Direction.OUT,jdbcTypeName="OBJ_TEAM_ROLES"),
@StoredProcedureParameter(queryParameter="debugMode",name="I_DEBUGMODE",direction=Direction.IN,type=Long.class)
public class TeamMembersDetails implements Serializable {
private static final long serialVersionUID = 1L;
@Id
private long userId;
private List<TeamMembersDetailsOT> teamMembersDetailsOT;
public void setTeamMembersDetailsOT(List<TeamMembersDetailsOT> teamMembersDetailsOT) {
this.teamMembersDetailsOT = teamMembersDetailsOT;
public List<TeamMembersDetailsOT> getTeamMembersDetailsOT() {
return teamMembersDetailsOT;
Procedure
PROCEDURE get_user_team_roles (
i_user_id IN ue_user.user_id%TYPE
, o_team_roles OUT OBJ_TEAM_ROLES_ARRAY
, i_debugmode IN NUMBER :=0)
AS
OBJ_TEAM_ROLES_ARRAY contains create or replace TYPE OBJ_TEAM_ROLES_ARRAY AS TABLE OF OBJ_TEAM_ROLES;
TeamMembersDetailsOT contains the same attributes defined in the OBJ_TEAM_ROLES.A few things.
You are not using a JDBC Array type in your procedure, you are using a PLSQL TABLE type. An Array type would be a VARRAY in Oracle. EclipseLink supports both VARRAY and TABLE types, but TABLE types are more complex as Oracle JDBC does not support them, they must be wrapped in a corresponding VARRAY type. I assume your OBJ_TEAM_ROLES is also not an OBJECT TYPE but a PLSQL RECORD type, this has the same issue.
Your procedure does not return a result set, so "returnsResultSet=true" should be "returnsResultSet=false".
In general I would recommend you change your stored procedure to just return a select from a table using an OUT CURSOR, that is the easiest way to return data from an Oracle stored procedure.
If you must use the PLSQL types, then you will need to create wrapper VARRAY and OBJECT TYPEs. In EclipseLink you must use a PLSQLStoredProcedureCall to access these using the code API, there is not annotation support. Or you could create your own wrapper stored procedure that converts the PLSQL types to OBJECT TYPEs, and call the wrapper stored procedure.
To map to Oracle VARRAY and OBJECT TYPEs the JDBC Array and Struct types are used, these are supported using EclipseLink ObjectRelationalDataTypeDescriptor and mappings. These must be defined through the code API, as there is currently no annotation support.
I could not find any good examples or doc on this, your best source of example is the EclipseLink test cases in SVN,
http://dev.eclipse.org/svnroot/rt/org.eclipse.persistence/trunk/foundation/eclipselink.core.test/src/org/eclipse/persistence/testing/tests/plsql/
http://dev.eclipse.org/svnroot/rt/org.eclipse.persistence/trunk/foundation/eclipselink.core.test/src/org/eclipse/persistence/testing/tests/customsqlstoredprocedures/
James : http://www.eclipselink.org -
Support for unit testing object types
There's a Feature Request that suggests expanding the unit test tool to object types:
Title
Provide object type support for unit tests
Description
In the current version (2.1.0.63) I can perform only unit test for packages, function and procedures. But we use a lot of object types in the database and would like to test them. When is a support for object types scheduled?
Average Rating
10
Development Comment
This is planned for the next release.
Status
Scheduled for 3.0
Although the status suggests inclusion in v3, in my current version 3.2.20.09 there is nothing.
This is clearly an important issue for those who have voted for it as it scores a perfect 10 on average rating.
Is there any sign of object types being supported in the 4.0EA1 release? There is a strong desire within my organisation to move to a more object-based approach to PL/SQL coding but until we are able to unit test easily there will be no real progress.If you are ready to learn a little bit of Ruby then you can try [PL/SQL unit testing with Ruby|http://blog.rayapps.com/2009/11/27/oracle-plsql-unit-testing-with-ruby/]. ruby-plsql library [supports also PL/SQL object types|http://blog.rayapps.com/2009/11/25/more-oracle-data-types-supported-by-ruby-plsql-gem/] as input and output parameters and return values.
-
In the current version (2.1.0.63) I can perform only unit test for packages, function and procedures. But we use a lot of object types in the database and would like to test them. Is there any support for object types scheduled?
You can also use the original UT PLSQL package from sourceforge.
I have used this in the past for testing with file comparisons, table object output from procedures, etc.
We've also used the same setup for Oracle Forms code testing.
Dennis -
Oracle 10.2.0.5.0
Using Pl/SQL Developer
Hi I'm new to collections, object types etc, so I aologize for any poor wording and missed concepts...
I need to output a ref cursor from my package (for a summary report in SQL Server Reporting Services 2005). The summary report has two fields that come from the database table and 5 calculated fields. My idea for creating the ref cursor is as follows:
1. Define an object type at the schema level
2. Define a table (collection) type at the schema level
3. Define a ref cursor at the package level
4. Using dynamic SQL create a sql statement creating virtual columns for the 5 calculated fields
5. Fetch cursor with dynamic sql into object type one record at a time
6. Calculate the other five field values and update the object for each record processed
7. Add the object 'record' to the table (collection) after each record is processed
8. After the fetch is complete, convert the table to a ref cursor for returning to my application
Here is what I have so far. I have cut out several of the calculated fields for simplicities sake. It is not complete and I don't know how to fetch the database row into the object, nor convert the collection to a ref cursor.
Any help would be greatly appreciated.
create or replace type dlyout.srvCtr_sum_rec_type as object (
zoneNo number,
zonetx varchar2(15),
distNo varchar2(4),
distTx varchar2(30),
numOccr number,
MEError varchar2(1));
create or replace type dlyout.srvCtr_sum_tbl_of_recs is table of srvCtr_sum_rec_type;
CREATE OR REPLACE PACKAGE DLYOUT.REPORTS_PKG is
TYPE CUR IS REF CURSOR;
PROCEDURE testABC(startDate IN date,
endDate IN date,
startTime IN varchar2,
endTime IN varchar2,
zoneNo IN dlyout.loc.zone_no%type,
distNo IN dlyout.loc.dist_cd%type,
CUROUT OUT CUR);
END;
CREATE OR REPLACE PACKAGE BODY DLYOUT.REPORTS_PKG IS
PROCEDURE testABC(startDate IN date,
endDate IN date,
startTime IN varchar2,
endTime IN varchar2,
zoneNo IN dlyout.loc.zone_no%type,
distNo IN dlyout.loc.dist_cd%type,
CUROUT OUT CUR) as
startDateTimeStr varchar2(10) := to_Char(startDate, 'MM/DD/YYYY') ;
endDateTimeStr varchar2(10) := to_Char(endDate, 'MM/DD/YYYY');
startDateTime date := to_date(startDateTimeStr || ' ' || startTime, 'MM/DD/YYYY HH24:MI:SS');
endDateTime date := to_date(endDateTimeStr|| ' ' || endTime, 'MM/DD/YYYY HH24:MI:SS');
distClause varchar2(1000);
sqls varchar2(2000);
zoneClause varchar2(1000) :='';
idx number :=0;
curSrvCtr cur;
srvCtrRec srvCtr_sum_rec_type;
srvCtrTbl srvCtr_sum_tbl_of_recs :=srvCtr_sum_tbl_of_recs();
BEGIN
if zoneNo <> 9999 then
zoneClause := ' and zone_no member of dlyout.reports_common_stuff_pkg.convert_to_collection(zoneNo)';
end if;
if distNo <> '9999' then
distClause := ' and dist_cd member of dlyout.reports_common_stuff_pkg.convert_to_collection(distNo) ';
end if;
sqls := 'select distinct l.zone_no zoneNo, l.zone_tx zoneTx,
l.dist_cd distCd , l.dist_tx distTx, 0 numOccr, '''' MEError
from dlyout.loc l
where l.ts between :startts and :endts ' ||
zoneClause ||
distClause ||
' order by l.zone_no, l.dist_tx ';
open curSrvCtr for sqls using startDateTime, endDateTime;
LOOP
FETCH curSrvCtr INTO srvCtrRec; --ORA:00932 inconsistent datatype expected - got -
EXIT WHEN curSrvCtr%NOTFOUND;
--call other functions to get calculated fields
srvCtrRec.numOccr := dlyout.reports_common_stuff_pkg.Num_Loc_Exc_Mom(startDateTimeStr, endDateTimeStr, starttime, endTime, srvctrRec.distno);
srvCtrRec.MEError := dlyout.reports_common_stuff_pkg.ME_Error(startDateTimeStr, endDateTimeStr, starttime, endTime, srvCtrRec.distNo, null);
dbms_output.put_line(srvCtrRec.distTx || ' ' || srvCtrRec.numoccr|| ' ' || srvCtrRec.MEError);
end loop;
end testABC;
END;
Then I need to add the object to the table. Something like this?
-- add object 'record' to table
srvCtrTbl.extend;
srvCtrTbl.last := srvCtrRec;
Then I am not sure how to do the cast to get the table to a ref cursor. Something like this?
open curout for SELECT *
FROM TABLE (CAST (srvCtrTbl AS srvCtr_sum_tbl_of_recs))
ORDER BY zoneNo, distTx;Ok, so after more research if seems that in 10.2 you cannot assign an object (SQL) type to a ref cursor (PLSQL). SO i changed my direction and used a global temp table - created at the schema level.
Create global temporary table dlyout.srvCtr_summary (
zoneNo number,
zonetx varchar2(15),
distNo varchar2(4),
distTx varchar2(30),
numOccr number,
MEError varchar2(1)
) on commit delete rows;Here is what the procedure looks like now.
PROCEDURE testABC(startDate IN date,
endDate IN date,
startTime IN varchar2,
endTime IN varchar2,
zoneNo IN dlyout.location.zone_no%type,
distNo IN dlyout.location.dist_cd%type,
CUROUT OUT CUR) as
startDateTimeStr varchar2(10) := to_Char(startDate, 'MM/DD/YYYY') ;
endDateTimeStr varchar2(10) := to_Char(endDate, 'MM/DD/YYYY');
startDateTime date := to_date(startDateTimeStr || ' ' || startTime, 'MM/DD/YYYY HH24:MI:SS');
endDateTime date := to_date(endDateTimeStr|| ' ' || endTime, 'MM/DD/YYYY HH24:MI:SS');
distClause varchar2(1000);
sqls varchar2(2000);
zoneClause varchar2(1000) :='';
curSrvCtr cur;
--Still need the PLSQL record type to put in the cursor for the dynamic SQL
type srvCtr_sum_rec_type is record (zoneNo dlyout.location.zone_no%type,
zonetx dlyout.location.zone_tx%type,
distNo dlyout.location.dist_cd%type,
distTx dlyout.location.dist_tx%type,
numOccr number,
MEError varchar2(1));
srvCtrRec srvCtr_sum_rec_type;
BEGIN
--create clauses for dynamic sql by calling other functions
if zoneNo <> 9999 then
zoneClause := ' and zone_no member of dlyout.reports_common_stuff_pkg.convert_to_collection(zoneNo)';
end if;
if distNo <> '9999' then
distClause := ' and dist_cd member of dlyout.reports_common_stuff_pkg.convert_to_collection(distNo) ';
end if;
--here is the dynamic sql
sqls := 'select distinct l.zone_no, l.zone_tx,
l.dist_cd , l.dist_tx, 0, 0,
0, 0, ''''
from dlyout.location l
where l.enrgz_ts between :startts and :endts ' ||
zoneClause ||
distClause ||
' order by l.zone_no, l.dist_tx ';
open curSrvCtr for sqls using startDateTime, endDateTime;
LOOP
--fetch in part of the record
FETCH curSrvCtr INTO srvCtrRec;
EXIT WHEN curSrvCtr%NOTFOUND;
--do the calculations to get the other field values
srvCtrRec.numOccr := dlyout.reports_common_stuff_pkg.Num_Loc_Exc_Mom(startDateTimeStr, endDateTimeStr, starttime, endTime, srvctrRec.distno);
srvCtrRec.MEError := dlyout.reports_common_stuff_pkg.MEC_Error(startDateTimeStr, endDateTimeStr, starttime, endTime, srvCtrRec.distNo, null);
dbms_output.put_line(srvCtrRec.distTx || ' ' || srvCtrRec.numoccr|| ' ' || srvCtrRec.MEError);
--add record to GTT
insert into dlyout.srvCtr_summary(zoneNo, zoneTx, distNo, distTX, numOccr, MEError )
values(srvCtrRec.zoneNo, srvCtrRec.zoneTx, srvCtrRec.distNo, srvCtrRec.distTX, srvCtrRec.numOccr, srvCtrRec.MEError);
end loop;
--open GTT and return ref cursor to app
open curout for SELECT *
FROM srvCtr_summary
ORDER BY zoneNo, distTx;
end testABC; -
This is on 10g R2.
How can I derive auditing information from sys.aud$ specifically for PLSQL objects (function, stored procs, packages)
In other words, what are columns or values in rows in sys.aud$ table, that gives this information.
Thanks
RSQL> desc aud$
Name Null? Type
SESSIONID NOT NULL NUMBER
ENTRYID NOT NULL NUMBER
STATEMENT NOT NULL NUMBER
TIMESTAMP# DATE
USERID VARCHAR2(30)
USERHOST VARCHAR2(128)
TERMINAL VARCHAR2(255)
ACTION# NOT NULL NUMBER
RETURNCODE NOT NULL NUMBER
OBJ$CREATOR VARCHAR2(30)
OBJ$NAME VARCHAR2(128)
AUTH$PRIVILEGES VARCHAR2(16)
AUTH$GRANTEE VARCHAR2(30)
NEW$OWNER VARCHAR2(30)
NEW$NAME VARCHAR2(128)
SES$ACTIONS VARCHAR2(19)
SES$TID NUMBER
LOGOFF$LREAD NUMBER
LOGOFF$PREAD NUMBER
LOGOFF$LWRITE NUMBER
LOGOFF$DEAD NUMBER
LOGOFF$TIME DATE
COMMENT$TEXT VARCHAR2(4000)
CLIENTID VARCHAR2(64)
SPARE1 VARCHAR2(255)
SPARE2 NUMBER
OBJ$LABEL RAW(255)
SES$LABEL RAW(255)
PRIV$USED NUMBER
SESSIONCPU NUMBER
NTIMESTAMP# TIMESTAMP(6)
PROXY$SID NUMBER
USER$GUID VARCHAR2(32)
INSTANCE# NUMBER
PROCESS# VARCHAR2(16)
XID RAW(8)
AUDITID VARCHAR2(64)
SCN NUMBER
DBID NUMBER
SQLBIND CLOB
SQLTEXT CLOB
OBJ$EDITION VARCHAR2(30) -
Describe Object Type / Difference between desc & USER_TYPE_ATTRS ?
Hi,
1)Can someone show me how to use the sql+ 'desc' functionality in plsql? I need
to descrive Object Types in a plsql procedure.
2)What is the difference between using the 'describe' function - for describing an object type-and doing a select on USER_TYPE_ATTRS etc..?
Sometimes desc gives an error while querying user_type_attrs works fine!
db.version: 8.1.7.4
best regards
B.describe instruction is a SQL*Plus feature not PL/SQL
Rgds.
Maybe you are looking for
-
This started yesterday night. I tried to restore firefox to yesterday morning's time machine version, but no dice. No idea what's causing it, I haven't installed anything. The refusing to submit my crash reports really confuses. I don't know if it's
-
Error in xml to abap internal table transformation using xslt_tool
Hi friends, When i am trying to convert xml data into internal table it is going to dump because of empty elements. Can any body help to delete the empty tags from xml before processing through xslt_tool. example <Activity> <ID>add12095</ID> <Start>0
-
IPhoto 6 - Photoshop Elements 4.0 Synergy
I bought PE 4.0 at the Apple store based on the Machead's assurance of compatability (synergy) with iPhoto. I'm either doing something wrong, or the techie-type was off the mark. In iPhoto, I've renamed (via batch control) a series of photos from the
-
Getting started with illustrator
hi, i dont know the first thing about illustrator, but i know a little about photoshop. can someone tell me how to learn about illustrator. thanks dustin
-
I updated my soft wear and now cant open my e-mails
I updated my soft wear and now I cannot open my e-mails it keeps saying it can't open in the new version