Oracle PL/SQL Stored Procedure within Select-Statement

Posts   
 
    
wolfgang_w
User
Posts: 16
Joined: 15-Mar-2007
# Posted on: 27-Jun-2007 17:13:23   

Hi,

I use LLBLGen Pro 2.0.0.0 Final (14 Feb. 2007) with adapter-mode and Oracle 10g Database.

I wonder if I can call a stored procedure function like this with a dynamic list:

CREATE OR REPLACE FUNCTION multiplyIt( a VARCHAR2, b VARCHAR2 ) RETURN VARCHAR2 is BEGIN RETURN (to_number(a) * to_number(b)); EXCEPTION WHEN OTHERS THEN RAISE; END; /

select multiplyIt(max(number_one), max(number_two)) from exampleTable;

content of exampleTable:

number_one  |  number_two
-------------------------------------
       2             |   3
       5             |   2
       3             |   7
       7             |   3  

Result should be 49 (7*7).

Thanks and Regards Wolfgang

Walaa avatar
Walaa
Support Team
Posts: 14995
Joined: 21-Aug-2005
# Posted on: 27-Jun-2007 17:23:41   

You can do this by using an Expression.

SELECT max(number_one) *  max(number_two) FROM exampleTable;

//SelfServicing


ResultsetFields fields = new ResultsetFields(1);
fields.DefineField(new EntityField("Total", 
    (OrderDetailsFields.UnitPrice.SetAggregateFunction(AggregateFunction.Max)  * OrderDetailsFields.Quantity.SetAggregateFunction(AggregateFunction.Max))), 0);

DataTable results = new DataTable();
TypedListDAO dao = new TypedListDAO();
dao.GetMultiAsDataTable(fields, results, 0, null, null, null, true, null, null, 0, 0);

//Adapter

ResultsetFields fields = new ResultsetFields(1);
fields.DefineField(new EntityField2("Total", 
    (OrderDetailsFields.UnitPrice.SetAggregateFunction(AggregateFunction.Max) * OrderDetailsFields.Quantity.SetAggregateFunction(AggregateFunction.Max))), 0);

DataTable results = new DataTable();
DataAccessAdapter adapter = new DataAccessAdapter();
adapter.FetchTypedList(fields, results, null);
wolfgang_w
User
Posts: 16
Joined: 15-Mar-2007
# Posted on: 28-Jun-2007 09:10:34   

Sure. This was just a example to understand my problem easier.

The "real" Stored Procedure Function is even more complicated so I have to call the function within the Select-Statement. Is there a way?

I read that it is possible to call Stored Procedures / Functions (-> generated code -> Calling a database function) but I saw no information about doing this within the Select-Statement.

Thanks and Regards Wolfgang

Walaa avatar
Walaa
Support Team
Posts: 14995
Joined: 21-Aug-2005
# Posted on: 28-Jun-2007 09:45:56   

Please check the manual "Using the generated code -> Calling a database function" The examples mentioned there are already calling DB Functions in the select list.