CAST to package type - oracle

Is it possible to CAST to a type within a package? For example:
CAST(v_variable AS Mypackage.type)
I know CAST states the ability to cast to built-in types but I was wondering if this was possible. I'm interested in this approach because I prefer keeping my utilities in one package instead of having a separate TYPE object.
Thanks!

No. CAST() is a SQL function so we can only use it with SQL types. This means we cannot use it with types we have declared in a PL/SQL package.

Related

Is it possible to discover all types and functions in a package using reflection?

Is it possible to get all the types and functions defined in a package using reflection at runtime? To make the question clear, in C# we can do this by using a method called ExportedTypes on an assembly and it returns a list of classes.
To be particular, what I need to do is to obtain a list of methods that have a particular return type while being able to invoke them dynamically when required.
Edit: I already know about the AST package, but I am asking in particular about the reflection package.

How use constant in type definition in oracle pl/sql?

I need something like this.
CREATE OR REPLACE PACKAGE BODY DAIS2 AS
G_TIMLIGA CONSTANT NUMBER:=20;
PROCEDURE GENZAPAS
AS
TYPE MYOWNARRAY IS VARRAY(G_TIMLIGA) OF KURZ%ROWTYPE;
I'm creating package and i need have group of constants like G_TIMLIGA and use its in many procedures and functions and i don't want to change all defenitions. Is some way to do this?
I didn't find an explicit interdiction in the documentation (http://docs.oracle.com/cd/E11882_01/appdev.112/e25519/composites.htm#CHDEIJHD), but, as I know, you have to use number in type declaration and you can't use previously defined constant. If you need array type with length defined by a constant, try to use another collection types (http://docs.oracle.com/cd/E11882_01/appdev.112/e25519/composites.htm#LNPLS005). But in this case you need write some additional code to control size, may be even create your own API for working with this structure.

Get names of structs that implement an interface or inherit a struct

Is it possible to get a slice of strings that represent the names of all types that implement an interface or inherit from a specific struct in a specific package using reflection?
After some research on the reflect package's doc, I don't think it's possible. That's not the way reflection work in go: the interfaces mechanism not beeing declarative (but duck-typed instead), there is no such list of types.
That said, you may have more luck using the ast package to parse your project, get the list of types, and check wheter or not they implement an interface, then write some code to give you the said slice. That would add a step to compilation, but could work like a charm.
AFAIK, you can't do this with reflect, since packages are kinda out of reflect's scope.
You can do this the same way godoc's static analysis works. That is, using code.google.com/p/go.tools/go/types to parse the package's source code and get the type info.
The go oracle can do this. https://godoc.org/code.google.com/p/go.tools/oracle
Here is the relevant section of the user manual.

Declare type object in an oracle package

Is there a way to declare type object in a package ?
it seems like the one following is not supported in the context the package
TYPE xxx AS OBJECT
thank you
No, you can't do that. an object type is a database object that must be declared using the CREATE statement. Its similar to a package in that it must have a spec declaration and a body implementation.
Once you've created it, you can then reference it in a package

Is there anyway to declare a TYPE without a Property in Oracle 10gR2

I want to create a base object that has only methods. The object would be QUEUABLE_OBJECT_TYPE and it will have an ENQUEUE method(s). The Payload of these messages (properties) would be added by subtyping this object.
I get an error that makes it sound like you cannot:
PLS-00589: no attributes found in object type "QUEUABLE_OBJECT_TYPE"
Does anyone know a way around this error? Or is it possible in the subtypes to hide this property of the supertype?
Either would be an acceptable answer.
Everything I've read suggests it is not possible to create a type without any attributes. Nor is it possible to hide a dummy attribute in a subtype. You may simply have to have an attribute in the master type, and utilise it - e.g. by making it identify the version of the type.
Oracle does provide some generic types, see documentation for details

Resources