Oracle Table of Object

RainerW

Member
I have a type kanal declared as an object

>CREATE OR REPLACE TYPE kanal AS OBJECT
>nummer NUMBER(7), wert VARCHAR2(200), >attribut NUMBER(1))

and a collection in a package

>TYPE kanaele IS TABLE OF kanal;

which is used as a parameter for a function.

The documentation says, that only tables of scalar data types are supported by the Package Wizard.
Has anyone a piece of code for me which shows how to handle the call for my procedure?

Thanks, Rainer
 
The package wizard does support collection object parameters. They are implemented as TOracleObjects.

The generated package class will have a TOracleObject parameter, which you need to instantiate in your application as a 'KANAELE' type:
Code:
Kanaele := TOracleObject.Create(MySession, 'KANAELE', '');
Kanaele[0] := ...;
Kanaele[1] := ...;
MyPackage.MyFunction(Kanaele, ...);
The package wizard does not support PL/SQL Tables of non-sclalar data types, but this is not the case here.

------------------
Marco Kalter
Allround Automations
 
Originally posted by mkalter:
The package wizard does support collection object parameters. They are implemented as TOracleObjects.

The generated package class will have a TOracleObject parameter, which you need to instantiate in your application as a 'KANAELE' type:
Code:
Kanaele := TOracleObject.Create(MySession, 'KANAELE', '');
Kanaele[0] := ...;
Kanaele[1] := ...;
MyPackage.MyFunction(Kanaele, ...);
The package wizard does not support PL/SQL Tables of non-sclalar data types, but this is not the case here.


I have changed the package a bit, but I can't understand whats happening:

create or replace package PRDS$DATA is

TYPE kanaele_real IS TABLE OF INTEGER;
TYPE kanaele_string IS TABLE OF VARCHAR2(254);

declarations
function transfer_oracle_real(i_zeitstempel TIMESTAMP, i_kanaele IN kanaele_real) return NUMBER;
function transfer_oracle_string(i_zeitstempel TIMESTAMP, i_kanaele IN kanaele_string) return NUMBER;

end PRDS$DATA;

The package wizard makes the following:

// PRDS$DATA.TRANSFER_ORACLE_REAL
function TPrdsData.TransferOracleReal(const IZeitstempel: string;
IKanaele: TOracleObject): Double;
begin
ThreadAcquire;
try
GetQuery;
OCPQuery.DeclareVariable('function_result', otFloat);
OCPQuery.DeclareVariable('I_ZEITSTEMPEL', otString);
OCPQuery.SetVariable('I_ZEITSTEMPEL', IZeitstempel);
OCPQuery.DeclareVariable('I_KANAELE', otObject);
OCPQuery.SetComplexVariable('I_KANAELE', IKanaele);
OCPQuery.SQL.Add('begin');
OCPQuery.SQL.Add(' :function_result := "PRDS$DATA"."TRANSFER_ORACLE_REAL"(');
OCPQuery.SQL.Add(' I_ZEITSTEMPEL => :I_ZEITSTEMPEL,');
OCPQuery.SQL.Add(' I_KANAELE => :I_KANAELE);');
OCPQuery.SQL.Add('end;');
OCPQuery.Execute;
Result := ConvertVariant(OCPQuery.GetVariable('function_result'));
finally
ThreadRelease;
end;
end;

Why is the wizard treating the kanaele_real datatype (table of integer) as an oracle object and then uses setcomplexvariable?

OCPQuery.DeclareVariable('I_KANAELE', otObject);
OCPQuery.SetComplexVariable('I_KANAELE', IKanaele);

If I program somthing like this, an error rises, that kanal_table is not an TOracleObject, which is obviously right:

Kanal_Table := TPLSQLTable.Create(100,0);
Kanal_Table.Count := 10;
Kanal_Table[0] := 123;
Test.TransferOracleReal(now, kanal_table);

What can I do?
 
This is a collection object type:

TYPE kanaele_real IS TABLE OF INTEGER;

This is a PL/SQL Table type:

TYPE kanaele_real IS TABLE OF INTEGER INDEX BY BINARY_INTEGER;

The first is a TOracleObject parameter, the second is a TPLSQLTable parameter.

------------------
Marco Kalter
Allround Automations

[This message has been edited by mkalter (edited 17 December 2002).]
 
Back
Top