Calling stored procedure dynamically from PB Script
Posted on 2006-11-28
Problem: Calling stored procedure dynamically from PB Script
I have a Customer table. For each customer one stored procedure is assigned which is saved in a column in the Customer table.
When I am viewing a customer, then respective stored procedure has to be called. There are 1000 customers and each customer has his own stored procedure, so there are 1000 stored procedures.
Each of these stored procedures accept 3 string arguments and return one integer value.
ls_Cust_sp_name = 'sp_macdonalds_budget' // This value is retrieved from the table for the selected customer
// Standard way of calling a stored procedure, where the stored proc actual name is called,
// DECLARE lsp_validate_sp PROCEDURE FOR sp_macdonalds_budget(:ls_Budget_ID, :ls_Status_ID, :ls_Resp_Person ); // Here stored proc name is hardcode, hence does not server my purpose and it is not optimized.
// EXECUTE lsp_validate_sp;
DECLARE lsp_validate_sp PROCEDURE FOR ls_Cust_sp_name(:ls_Budget_ID, :ls_Status_ID, :ls_Resp_Person ); // I get compilation error, stating 'ls_Cust_sp_name' procedure not found.
FETCH lsp_validate_sp INTO :li_Retn_Val;
How can I call the stored procedure in an optimized way without using CHOOSE... Case or any other loops. There can be more than 1000 customers and stored procedures.