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
ReferenceURL : https://stackoverflow.com/questions/1069176/possible-to-create-oracle-database-object-types-inside-of-pl-sql
'programing' 카테고리의 다른 글
| cocoapods 버전 1.0.0.beta.1에 오류가 표시되는 포드 설치 (0) | 2023.06.18 |
|---|---|
| Python Panda는 한 열의 NaN을 두 번째 열의 해당 행 값으로 바꿉니다. (0) | 2023.06.18 |
| 유형 스크립트: 인터페이스의 상수 (0) | 2023.06.18 |
| 관리되지 않는 DLL이 ASP.NET 서버에 로드되지 않음 (0) | 2023.06.18 |
| 유형 스크립트의 다른 파일에서 함수를 선언하려면 어떻게 해야 합니까? (0) | 2023.06.18 |