Debugging a function with table type as input parameter - oracle11g

Can anybody let me know how can i debug a functions with table type as input parameter and this function returns a table type pipelined.
Please see below details.When i try to test the function it creates below anonymous block but when i click on debug button it gives error:
Anonymous block:
declare
-- Non-scalar parameters require additional processing
result t_bmk_q;
pit_srch_str t_parm;
begin
-- Call the function
result := f_bmk_srch(pit_srch_str => pit_srch_str,
piv_op => 'ALL');
end;
---f_bmk_q function returns table type t_bmk_q pipelined
defintions:
==============
t_bmk_q --->table type
t_bmk_q is TABLE OF r_bmk_q -->object of some attributes.
pit_srch_str ---> is parameter of type t_parm which is table type of r_parm
--plz see def of r_parm:
CREATE OR REPLACE TYPE r_parm AS OBJECT
(
p_abc varchar2(200)
,p_new_val varchar2(2000)
,CONSTRUCTOR FUNCTION r_parm
(
p_abc varchar2
,p_new_val varchar2
) RETURN SELF AS RESULT
);
Example:I have below sample values to test and debug:
r_parm('TAB1.VALUE','123321123')
Thanks
Rajesh

It seems you are using a PL/SQL Developer Test Window to run the tests. I recognise the comment Non-scalar parameters require additional processing.
PL/SQL Developer's Test Window doesn't handle pipelined functions too well.
You are best off removing the result variable and wrapping the function call in open :cursor for select * from table(...). Add a variable named cursor of type Cursor to the variables list below the window.
To populate the input table, you can simply 'call' the table type, passing each row in the table as a separate argument. For example,
t_parm(r_parm(...), r_parm(...), r_parm(...))
You can add as many rows to the table as you like this way.
Putting both of these changes together, we have something like the following:
declare
pit_srch_str t_parm;
begin
-- Create input table.
pit_srch_str := t_parm(
r_parm('TAB1.VALUE','123321123'),
r_parm('TAB2.VALUE','456597646')
);
-- Call the function
open :cursor for select * from table(f_bmk_srch(pit_srch_str => pit_srch_str,
piv_op => 'ALL'));
end;
/
Once you've run the function, you can get the results from the cursor variable (use the ... button at the far right).

Related

How to get a row object from a function that return a table object in plsql?

i'm trying to get a single row and save it into a variable in PLSQL.
I'm using APEX and all is around the APEX_DATA_PARSE.PARSE() function.
As the docs said, .PARSE() should return WWV_FLOW_T_PARSER_ROW for every row of results.
What i'm trying to do is to get only one row to be saved into a variable.
This is My code:
`
DECLARE
r_columns_headers WWV_FLOW_T_PARSER_ROW; --object
BEGIN
DBMS_OUTPUT.ENABLE;
BEGIN
<<populate_headers>>
select * into r_columns_headers
from apex_application_temp_files f,
table( apex_data_parser.parse(
p_content => f.blob_content,
p_add_headers_row => 'Y',
P_SKIP_ROWS => 1,
p_max_rows => 500,
p_store_profile_to_collection => 'FILE_PARSER_COLLECTION',
p_file_name => f.filename ) ) p
where f.name = '43300947378776117/DATALOAD_Test_data_main_v032.xlsx' and p.line_number = 2;
end populate_headers;
DBMS_OUTPUT.PUT_LINE(r_columns_headers.id);
end;
`
is just for test outside the main package that i'm writing.
The error i get is PL/SQL: ORA-00947 on row 8, on the select * into r_columns_headers section.
I don't know why i get not enough values, the fields are the same as they are the same type of object. The select return exactly one row, of a WWV_FLOW_T_PARSER_TABLE object. Not all columns are with data, someones are null, is this the problem?
I'm just at the beginning of learning plsql.
Thanks a lot
wwv_flow_t_parser_row
I'm trying to get a row into the r_columns_headers variable to access it in my program.
The "ORA-00947: not enough values" error is sometimes a bit confusing; in a PL/SQL context it can be backwards.
The problem is that you actually have too many values in your select list. You are doing:
select * into r_columns_headers
but you're joining two table expression, apex_application_temp_files as f and the unnested table as p. So the * is effectively doing:
select f.*, p.* into r_columns_headers
... and that object doesn't have fields for all the columns coming from f.
So you need to restrict it to the relevant data:
select p.* into r_columns_headers
... but that returns all of the object attributes as individual columns, not as a single object; but you can get the actual object with the value() function:
select value(p) into r_columns_headers
fiddle with a dummy object type and data as the real APEX types aren't available there.

Issue With PL/SQL Bind Variables

Recently, I deployed an Oracle WareHouse Builder (OWB) mapping. In the scenario I'm working right now, this mapping (ETL process) needs to be fired up by a trigger after an Update statement takes place on the fact table (working with WriteBack values).
As the mapping is deployed to the target schema as a package, the trigger must call the main procedure that OWB creates for the package. At first I didn't knew how to accomplish this task, but SQL Developer gave me a hint:
So, I took this code and put it inside my trigger. Like this:
CREATE OR REPLACE TRIGGER RESPALDO_HISTORIAL
AFTER UPDATE ON MONITOR_FT_TAB
FOR EACH ROW
DECLARE
P_STATUS VARCHAR2(200);
P_MAX_NO_OF_ERRORS VARCHAR2(200);
P_COMMIT_FREQUENCY VARCHAR2(200);
P_OPERATING_MODE VARCHAR2(200);
P_BULK_SIZE VARCHAR2(200);
P_AUDIT_LEVEL VARCHAR2(200);
P_PURGE_GROUP VARCHAR2(200);
P_JOB_AUDIT VARCHAR2(200);
BEGIN
P_MAX_NO_OF_ERRORS := NULL;
P_COMMIT_FREQUENCY := NULL;
P_OPERATING_MODE := NULL;
P_BULK_SIZE := NULL;
P_AUDIT_LEVEL := NULL;
P_PURGE_GROUP := NULL;
P_JOB_AUDIT := 'TRUE';
SINIESTROS_MARCADOS_MAP.MAIN(
P_STATUS => P_STATUS,
P_MAX_NO_OF_ERRORS => P_MAX_NO_OF_ERRORS,
P_COMMIT_FREQUENCY => P_COMMIT_FREQUENCY,
P_OPERATING_MODE => P_OPERATING_MODE,
P_BULK_SIZE => P_BULK_SIZE,
P_AUDIT_LEVEL => P_AUDIT_LEVEL,
P_PURGE_GROUP => P_PURGE_GROUP,
P_JOB_AUDIT => P_JOB_AUDIT
);
:P_STATUS := P_STATUS;
END RESPALDO_HISTORIAL;
/
When I tried to compile this trigger, I got this screen:
In this screen I tried clicking "Aplicar" (Apply in spanish) with and without the NULL checkbox, always getting this output:
TRIGGER RESPALDO_HISTORIAL compilado
Errors: check compiler log
Then I ran the SHOW ERRORS command and I got this:
33/3 PLS-00049: bad bind variable 'P_STATUS'
Now I don't quite understand these bind variables. If this is the code generated by SQL Developer to run the package, then why I get this error??
Please help! I need some guidelines in this matter!
Greetings!
A colon preceding a variable indicates that that variable is a bind variable. Bind variables of this type are typically used to pass values in and out of anonymous blocks. They're not allowed in procedures, functions, or triggers. In this case, you need to remove the line :P_STATUS := P_STATUS;.

PLS-00487 Error-Invalid reference to Variable 'CHAR'

I'm designing a function that is part of a larger package. The function is intended to take a District Code and return a collection of unique IDs for 10-15 stores that are assigned to that district. The function is intended to return a collection that can be queried like a table, i.e., using the TABLE function in a SQL statement.
I've created the following Types:
Schema Level type:
create or replace TYPE HDT_CORE_ORGIDS AS TABLE OF CHAR(20);
and a Type inside the Package
TYPE CORE_ORGIDS IS TABLE OF CHAR(20) INDEX BY BINARY_INTEGER;
Here's the function code:
FUNCTION FindDistrictOrgs(
ParamOrgCode VARCHAR2
)
RETURN HDT_CORE_ORGIDS
AS
ReturnOrgs HDT_CORE_ORGIDS := HDT_CORE_ORGIDS();
FDOTemp HDT_CORE_MAIN.CORE_ORGIDS;
i BINARY_INTEGER := 0;
CURSOR FDOCurr IS
SELECT org.id AS OrgID
FROM tp2.tpt_company org
WHERE LEVEL = 2
START WITH org.name = ParamOrgCode
CONNECT BY PRIOR org.id = org.parent_id;
BEGIN
OPEN FDOCurr;
LOOP
i := i +1;
FETCH FDOCurr INTO FDOTemp(i);
EXIT WHEN FDOCurr%NOTFOUND;
END LOOP;
IF FDOTemp.EXISTS(FDOTemp.FIRST) THEN
ReturnOrgs.EXTEND(FDOTemp.LAST);
FOR x IN FDOTemp.FIRST .. FDOTemp.LAST LOOP
ReturnOrgs(x) := FDOTemp(x).OrgID;
END LOOP;
END IF;
CLOSE FDOCurr;
RETURN ReturnOrgs;
END FindDistrictOrgs ;
I'm getting the PLS-00487:Invalid Reference to variable 'CHAR' at the line:
ReturnOrgs(x) := FDOTemp(x).OrgID;
I've double-checked at the value returned by the SQL (the org.id AS OrgID) is of the CHAR(20 BYTE) datatype.
So...what's causing the error?
Any help is appreciated! :)
OrgID is the alias you gave the column in your cursor, it has no meaning to the collection. Since both collections are of simple types you should just be doing:
ReturnOrgs(x) := FDOTemp(x);
The syntax you're using is implying FDOTemp is a collection of objects and you're trying to reference the OrgID attribute of an object; but since CHAR isn't an object type, this errors. The error message even makes some sense when viewed like that, though it's not terribly helpful if you don't already know what's wrong... and not entirely helpful when you do.
Incidentally, you could use a bulk collect to populate the collection without the cursor or loops, or the extra collection:
SELECT org.id
BULK COLLECT INTO ReturnOrgs
FROM tp2.tpt_company org
WHERE LEVEL = 2
START WITH org.name = ParamOrgCode
CONNECT BY PRIOR org.id = org.parent_id;
RETURN ReturnOrgs;

array must be declare error in pl sql

I want to return a array in a function as my function looks like below,
CREATE OR REPLACE FUNCTION TEST
RETURN t_array
IS
strings t_array;
BEGIN
--do something
RETURN strings;
END:
But it gives a error t_array must be declare. I want to know where to declare it and how can i declare it?
When you are using a custom type, you have to declare that type first. For example:
CREATE OR REPLACE TYPE string_array IS TABLE OF varchar2(50);
Which creates a new type named string_array that is a table of varchars.
For more information check the official oracle dokumentation here

Unable to return query output in Apex PL SQL expression

I am trying to write a following PL/SQL function body for a dynamic action
The purpose of dynamic action is to set value for text area based on input parameters. Way I am trying to do it, is that setting the value into variable for different options
declare
P_NOTE varchar(100); -- derive value
P_WEBSERVER varchar(100); -- derive name
begin
-- for getting the P_NOTE value
select distinct note into P_NOTE from port_mapping where PLATFORM = :P3_PLATFORM and VERSION = :P3_VERSION;
-- for getting web server value
select CONCAT(P_NOTE,CONCAT('https-',:P3_CLIENT)) into P_WEBSERVER from dual order by 1;
if (:P3_PLATFORM = 'Apache') then
return P_WEBSERVER;
end if;
end;
However I am getting error
ORA-06550: line 15, column 5:
PLS-00372: In a procedure, RETURN statement cannot contain an expression
ORA-06550: line 15, column 5:
PL/SQL: Statement ignored
declare
P_NOTE varchar(100);
P_WEBSERVER varchar(100);
I am not sure what I am missing.
(Since you did not post any apex version this explanation deals with version 4.2)
If this -is- a dynamic action and the code you posted is in a true action of type 'Execute PL/SQL Code' then you can not use RETURN. The plsql block is not a function body (close, Mr Kemp!).
If you want to return values from the session state to page items then you need to use the "Page Items to Return" item of the true action.
This will put the session state of the defined page items into the value of the item on the page. This means that you can not use any variable to just put stuff in to be able to return it to the page, but you need to use an actual page item (after all, these are bind variables).
To clarify further, you would not write :
return P_WEBSERVER;
But you'd have to use a page item, say P3_WEBSERVER, and you'll need to create one if it doesn't exist of course:
:P3_WEBSERVER := p_webserver;
Of course you'd need to make sure that the correct value will be in there as you can not shortcircuit as you did in your code sample (p_webserver will usually hold a value even if the platform is not 'Apache') eg:
if (:P3_PLATFORM = 'Apache') then
:P3_WEBSERVER := P_WEBSERVER;
else
:P3_WEBSERVER := NULL;
end if;
Just read error message:
line 15, column 5
So, trouble caused by this line:
return P_WEBSERVER;
return not allowed in PL/SQL blocks, use output parameter to return a value.
Read Tom's answer to find out how to do that.

Resources