Object not supported in this context while Creating the package in Oracle - oracle

Hi I am trying to execute below statements for creating a package , but i am getting an error saying
Error(3,1): PLS-00540: object not supported in this context.
When trying to change it to RECORD i am getting another error
Error(3,32): PLS-00103: Encountered the symbol "RECORD" when expecting one of the following:
object opaque The symbol "object was inserted before "RECORD" to continue.
package Definition trying to execute
CREATE OR REPLACE PACKAGE "PKG_LOAN_LOGIC_SERVICE_V2" AS
TYPE LOAN_LOGIC_RESULT_TYPE AS OBJECT (
loanid NUMBER,
ret_value varchar2(500),
xPath varchar2(200)
);
TYPE LOAN_LOGIC_RESULTS_TABLE IS TABLE OF LOAN_LOGIC_RESULT_TYPE;
procedure PR_CORAL_LOAN_LOGIC(
in_loan_id IN wcts.loans.loan_id%TYPE,
in_trans_id IN wcts.loans.loan_id%TYPE,
as_errm out varchar2,
out_order_contents_tab out LOAN_LOGIC_RESULTS_TABLE
);
END PKG_LOAN_LOGIC_SERVICE_V2;
When i am trying to execute the user defined types in another standalone SQL Developer Window , its executing successfully .
CREATE OR REPLACE TYPE LOAN_LOGIC_RESULT_TYPE AS OBJECT (
loanid NUMBER,
ret_value varchar2(500),
xPath varchar2(200)
);
CREATE OR REPLACE TYPE LOAN_LOGIC_RESULTS_TABLE AS TABLE OF LOAN_LOGIC_RESULT_TYPE;
Why its not allowing me to run inside package ? or how i will create these types inside a package
Update:
create or replace procedure PR_CORAL_LOAN_LOGIC(
in_loan_id IN wcts.loans.loan_id%TYPE,
in_trans_id IN wcts.loans.loan_id%TYPE,
as_errm out varchar2,
out_order_contents_tab out LOAN_LOGIC_RESULTS_TABLE
)
is
begin
for o in (SELECT xpath_name FROM loan_logic WHERE attribute =
upper(TRIM('STATUS_0')))
loop
-- How i will get the user defined type here tp assign the values
--Assign the column values while iterating
END LOOP;
end PR_CORAL_LOAN_LOGIC;

According to Oracle documentation
You must define object types using the SQL statement CREATE TYPE
EDIT
For example
create or replace procedure PR_CORAL_LOAN_LOGIC(out_order_contents_tab out LOAN_LOGIC_RESULTS_TABLE)
is
obj LOAN_LOGIC_RESULT_TYPE;
begin
obj := LOAN_LOGIC_RESULT_TYPE(2, 'return value', 'some/path');
out_order_contents_tab := LOAN_LOGIC_RESULTS_TABLE();
out_order_contents_tab.extend;
out_order_contents_tab(1) := obj;
There are lots of examples available online, including Working with Collections. Not to mention the Oracle documentation.

Related

ORA-06530: Reference to uninitialized composite - Similar questions reviewed but still unclear

I'm getting this error:
Error while executing the procedure : ORA-06530: Reference to uninitialized composite
This is probably a common error for Oracle beginners like me. I looked at similar posts but can't figure out how to apply the answers to my code, which follows.
I have a table of:
CREATE OR REPLACE TYPE "FDS_APPS"."TY_AUDIT_COL_TBL" IS
TABLE OF fds_apps.ty_audit_col_obj;
of this TYPE
CREATE OR REPLACE TYPE "FDS_APPS"."TY_AUDIT_COL_OBJ" AS OBJECT (
application VARCHAR2(30),
module VARCHAR2(30),
created_by VARCHAR2(50),
creation_date DATE
);
I want to create a a test procedure to call the following procedure while passing in the input values with focus, of course on the p_audit_col parameter of type ty_audit_col_tbl.
PROCEDURE check_mv_status (
o_outcome_type OUT VARCHAR2,
p_audit_col IN fds_apps.ty_audit_col_tbl,
p_refresh_ind IN CHAR DEFAULT 'N',
p_mv_result OUT NOCOPY fds_apps.ty_result_tbl
) AS...
Here is my calling procedure:
CREATE OR REPLACE PROCEDURE FDS_APPS.JUNKPROC2
AS
O_OUTCOME_TYPE VARCHAR2(32767);
P_AUDIT_COL TY_AUDIT_COL_TBL;
P_REFRESH_IND CHAR;
P_MV_RESULT TY_RESULT_TBL;
BEGIN
P_AUDIT_COL := fds_apps.TY_AUDIT_COL_TBL();
P_AUDIT_COL.extend(1);
--Error occurs on the following line
P_AUDIT_COL(1).application := 'App';
P_AUDIT_COL(1).module := 'Module';
P_AUDIT_COL(1).created_by := 'MyID';
P_REFRESH_IND := 'N';
FIRM_RTBI_PKG.CHECK_MV_STATUS(O_OUTCOME_TYPE, P_AUDIT_COL, P_REFRESH_IND, P_MV_RESULT);
dbms_output.put_line('O_OUTCOME_TYPE=' || O_OUTCOME_TYPE);
END;
/
I get the error where indicated as a comment, when I try to assign a value to an element in the 1 record collection.
How can I overcome this error?
The syntax you are showing is for populating RECORDS, which is different than populating an OBJECT type.
Replace this:
P_AUDIT_COL(1).application := 'App';
P_AUDIT_COL(1).module := 'Module';
P_AUDIT_COL(1).created_by := 'MyID';
with this:
P_AUDIT_COL(1) := TY_AUDIT_COL_OBJ('App','Module','MyID',sysdate);
An object type variable needs to be initialized with a constructor

How can i use REF type in PL/SQL Oracle?

I have this code :
CREATE OR REPLACE TYPE t_abonnement_type AS OBJECT
(
ref_abonnement_type NUMBER,
type_abonne VARCHAR(50),
MEMBER PROCEDURE DISPLAY
);
CREATE OR REPLACE TYPE t_abonnement AS OBJECT
(
ref_abonnement NUMBER,
date_debut DATE,
type_abonnement REF t_abonnement_type,
MEMBER PROCEDURE DISPLAY
);
What i want to do is just create the members procedures DISPLAY declared.
So i did it this way :
CREATE OR REPLACE TYPE BODY t_abonnement AS
MEMBER PROCEDURE DISPLAY IS
BEGIN
/* SOME CODE */
type_abonnement.display;
END;
END;
And i get this error
PLS-00536: Navigation through REF variables is not supported in PL/SQL.
So how can i deal with REF in PL/SQL statements ?
Thanks
As mentioned by #APC, it's not possible to directly use member function of a Object to another using REF since Oracle supports them in SQL but not in PL/SQL.
However if I look at your requirement from a different angle, I could see you are trying to simply make use of Procedure used in an Object to another Object. Means if I forget the referencing part and create a scenario which could satisfy the referencing concept then it should "OK".
This is possible. Yes..!!! This can be done. The only thing I did here is to make the two Objects as parent-child to achieve referencing. See demo below:
--Parent Object
CREATE OR REPLACE TYPE t_abonnement_type AS OBJECT
(
ref_abonnement_type NUMBER,
type_abonne VARCHAR(50),
MEMBER FUNCTION DISPLAY return varchar2
) NOT FINAL;
-- Member Funtion Body
CREATE OR REPLACE TYPE BODY t_abonnement_type
AS
MEMBER FUNCTION DISPLAY
return varchar2
IS
BEGIN
return ('Hi');
END DISPLAY;
END;
Testing my Parent Object:
SQL> SELECT t_abonnement_type(1,'a').display() col from DUAL;
COL
---
Hi
Child Object to achieve referencing concept
CREATE OR REPLACE TYPE t_abonnement
under t_abonnement_type
(
ref_abonnement NUMBER,
date_debut DATE,
MEMBER function V_DISPLAY return varchar2
);
--Member function
CREATE OR REPLACE TYPE BODY t_abonnement
AS
MEMBER Function V_DISPLAY return varchar2
IS
var varchar2(10);
BEGIN
var:= t_abonnement_type(1,'A').display(); --Calling Parent Member function here
return('Called from Child Object -->'||var);
END;
END;
Testing my Child Object to check if the parent Member function is referenced or not:
SQL> SELECT T_ABONNEMENT(1,'A',2,TO_DATE('30-JUN-2018','DD-MON-YYYY')).V_DISPLAY() COL FROM DUAL;
Col
---
Called from Child Object -->Hi
Note I haven't used overloading done in your code as I feel overloading makes the stuff harder to understand as an individual as well as for compiler.

User-Defined Types (PL/SQL) in Oracle Forms

I'm using PL/SQL, and I've recently found out that you can do OOP with it.
The thing is that I've created an Object Type on database level with, like this:
CREATE OR REPLACE TYPE customer AS OBJECT
(
customer_id NUMBER(10)
,customer_name VARCHAR2(30)
,customer_last VARCHAR2(30)
,constructor function customer(p_id NUMBER)
RETURN SELF AS RESULT
,member procedure display
)
And the type's body:
CREATE OR REPLACE TYPE BODY customer AS
constructor function customer(p_id NUMBER)
RETURN SELF AS RESULT
AS
BEGIN
SELECT client_id,
client_name,
client_last
INTO self.customer_id,
self.customer_name,
self.customer_last
FROM clients
WHERE client_id = p_id;
RETURN;
END;
member procedure display IS
BEGIN
dbms_output.put_line('Name: ' || customer_name||' '|| customer_last);
END;
END;
This compiles great and has no problems.
The thing is when I try to use this new type on Oracle Forms.
I have a very simple form, with just a textbox to put the client_id, and a button to search for the customer (it uses the constructor function from the customer type to create a new instance and return it), and another textbox where it displays the customer name. When pressed it executes a Program Unit that goes like this:
PROCEDURE search_client IS
client customer;
BEGIN
IF :CLIENT.ID_CLIENT IS NOT NULL THEN
client := customer(p_id => :CLIENT.ID_CLIENT);
:CLIENT.NAME := client.customer_name;
END IF;
END;
When I try to compile it, I'm getting this errors:
Error 0 in Line 3, column 11
Item ignored
and a few more errors like that.
I've read somewhere that client side PLSQL does not support this kind of defined types. Is that true? Or there's any other mistakes that I'm no seen here.
By the way I'm using Oracle Forms 11g, and an Oracle 10g Data base.

Create or replace global subtype

I know that I can create a subtype inside a package specification like:
CREATE OR REPLACE PACKAGE XY
AS
SUBTYPE type_sdebug IS VARCHAR (200);
...
END;
/
If I want to use the same subtype within another package then I need to redefine the same type again. Is there a way to create or replace a global subtype such as:
CREATE OR REPLACE TYPE STRING_ARRAY AS VARRAY(500) OF VARCHAR2(30);
/
As far as I know, SUBTYPEs are a PL/SQL feature, so you cannot create them globally. But nothing prevents you from using a type defined in your package XY in another package (e.g. AB):
CREATE OR REPLACE PACKAGE XY
AS
SUBTYPE type_sdebug IS VARCHAR (200);
END;
CREATE OR REPLACE PACKAGE AB
AS
PROCEDURE print_it(p_Debug in XY.type_sdebug);
END;
CREATE OR REPLACE PACKAGE BODY AB
AS
PROCEDURE print_it(p_Debug in XY.type_sdebug) is
begin
dbms_output.put_line(p_Debug);
end;
END;
declare
v_Debug XY.type_sdebug default 'hello world';
begin
ab.print_it(v_Debug);
end;
Now that I've read the question correctly *{;-) , according to the documentation you can indeed create a subtype:
"This statement shows how the subtype corporate_customer_typ in the sample oe schema was created. It is based on the customer_typ supertype created in the preceding example and adds the account_mgr_id attribute. A hypothetical name is given to the table so that you can duplicate this example in your test database:"
CREATE TYPE corporate_customer_typ_demo UNDER customer_typ
( account_mgr_id NUMBER(6)
);
You may need additional privileges to be able to do so though, according to the prerequisites for creating types:
"To create a subtype, you must have the UNDER ANY TYPE system privilege or the UNDER object privilege on the supertype."

Possible to create Oracle Database object types inside of PL/SQL?

Is it possible to create an object type inside of a package in Oracle Database 10g? Something like:
create or replace package my_package as
type my_type as object (
id number(15)
);
end;
Gives:
Error(3,9): PLS-00540: object not supported in this context.
What I'm ultimately looking to be able to do is use polymorphism but also allow the objects to access tables and use PL/SQL, which isn't allowed in types defined outside of packages.
Thanks,
Jeff
From the Oracle 10g documentation:
Currently, you cannot define object
types in a PL/SQL block, subprogram,
or package.
So, unfortunately, no.
Update for Oracle 11g Release 2:
From Chapter 3 Using PL/SQL With Object Types of Oracle Database Object-Relational Developer's Guide:
Using object types in a PL/SQL block, subprogram, or package is a two-step process.
You must define object types using the SQL statement CREATE TYPE, in SQL*Plus or other similar programs.
After an object type is defined and installed in the schema, you can use it in any PL/SQL block, subprogram, or package.
In PL/SQL, you then declare a variable whose data type is the user-defined type or ADT that you just defined.
You can use PL/SQL in objects that are defined outside a PL/SQL package!! Use object bodies:
CREATE TYPE person_typ AS OBJECT (
idno NUMBER,
first_name VARCHAR2(20),
last_name VARCHAR2(25),
email VARCHAR2(25),
phone VARCHAR2(20),
MAP MEMBER FUNCTION get_idno RETURN NUMBER,
MEMBER PROCEDURE display_details ( SELF IN OUT NOCOPY person_typ ));
/
CREATE TYPE BODY person_typ AS
MAP MEMBER FUNCTION get_idno RETURN NUMBER IS
BEGIN
RETURN idno;
END;
MEMBER PROCEDURE display_details ( SELF IN OUT NOCOPY person_typ ) IS
BEGIN
-- use the PUT_LINE procedure of the DBMS_OUTPUT package to display details
DBMS_OUTPUT.PUT_LINE(TO_CHAR(idno) || ' ' || first_name || ' ' || last_name);
DBMS_OUTPUT.PUT_LINE(email || ' ' || phone);
END;
END;
/
copy-pasted this example from this link: http://www.mcs.csueastbay.edu/support/oracle/doc/10.2/appdev.102/b14260/adobjint.htm

Resources