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

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.

Related

How do I define myself how functions must use my objects when making them available to theses functions (using my object at the end of the spec)?

In this question, I've given examples of package/object that :
implement some functions.
are used to define other functions by only making them availaible to those functions. It means. I don't write a function body but only a spec with "using package_name" or "using package_body" in the end.
I suppose that the way to use my pakcage/object to implement another function is defined somewhere.
I would like to know if there a way to define myself how to use a package/object. I want a way to implement a functions without writing the body everytime but only by writing in the spec that the function is using my package.
What I'm asking for is similar to already implemented function in a interface in java or an extention method in c#.
P.S. : I don't think that title is very clear. I would be glad if someone would propose another title.
I want a way to implement a functions without writing the body everytime but only by writing in the spec that the function is using my package.
You cannot define a function/procedure that references an SQL stored function/procedure like that. If you declare a function or procedure then it must include the signature and the body.
From the documentation:
create_function::=
plsql_function_source ::=
For a standalone function the body is required.
For a call specification, you can reference a function but it will be an external Java method or a C function and NOT another function defined in SQL.

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.

Oracle CREATE TYPE and PL/SQL

We have an Oracle type that's declared as such:
CREATE OR REPLACE TYPE its_accountarray;
There is no base type. This type is then used in Procedures and packages (and in Java Stored procedures as an array descriptor). In the procedure/package it uses extend function to add to array.
<declare section>
v_account latax.ITS_ACCOUNTARRAY := new ITS_accountArray();
...
BEGIN
...
...
v_account.extend(1);
and in Java, it's used as:
oracle.sql.ARRAY ls_accountARRAY, ls_periodARRAY;
oracle.sql.ArrayDescriptor ad = ArrayDescriptor.createDescriptor(**"ITS_ACCOUNTARRAY"**, oconn);
ls_accountARRAY = new ARRAY(ad, oconn, arg_accounts);
ocs.setARRAY(2, ls_accountARRAY);
I am curious as to how this works. Even though the name has Array in it, it is not defined as an array or table type, like I typically see. It works, but is this a legal usage or should I declare the type to be of some array type explicitly?
Thanks
Sam
I tried to reproduce what you say is happening, and got an error:
CREATE OR REPLACE TYPE its_accountarray;
DECLARE
v its_accountarray := its_accountarray();
BEGIN
null;
END;
/
PLS-00311: the declaration of "ITS_ACCOUNTARRAY" is incomplete or malformed
So, you're probably looking at the wrong type definition (e.g. you're looking at it in the wrong schema), or not looking at the entire type definition (e.g. there is a TYPE BODY that provides the implementation). Since this seems to be acting like a nested table type, the former sounds more likely.

CAST to package type

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.

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