Tuning with functions in the SQL Query
Hi there,
I am trying to tune a query that has functions in the select section. Wondering how to see the results of the explain plan with these functions included. Is there a qs to include them when running the explain plan
Thanks
Hilton
Oracle Database 11g Enterprise Edition Release 11.2.0.3.0 - 64bit Production
PL/SQL Release 11.2.0.3.0 - Production
"CORE 11.2.0.3.0 Production"
TNS for Linux: Version 11.2.0.3.0 - Production
NLSRTL Version 11.2.0.3.0 - Production
Not really. A function comprises SQL and PL/SQL. PL/SQL cannot possibly be included in an explain plan. Yet, you may take any SQL statement in a function and get its explain plan.
As a hint, it is generally not good to include functions in the where clause of a query unless that query has some other filter condition that does a drastic filtering of the results. Running a function for tens of thousands of records may be a killer. In that case, it may be better to use joins and/or exists subquerries in you SQL rather than a function that opens a cursor.
Similar Messages
-
Getting NULL with function in the select Query
Hi all,
SELECT
,a.TRANSACTIONAL_CURR_CODE
--,gl.CONVERSION_RATE
,get_rate(a.transactional_curr_code,NVL(gsob.attribute1,gsob.currency_code),a.conversion_type_code,TRUNC(a.ordered_date)) CONVERSION_RATE
FROM
oe_order_headers_all a,
oe_order_lines_all b,
gl_sets_of_books gsob
--gl_daily_rates gl
WHERE 1=1
and a.header_id = b.header_id
--and from_currency = 'USD' --a.transactional_curr_code
--and conversion_type = 'Corporate' --a.CONVERSION_TYPE_CODE
--and conversion_date = '23-APR-12' --a.ORDERED_DATE
and a.header_id =1234;
With commented above Line
0.749400479616307
NULL ---->Why i am getting NULL , i have a Value (0.07809)
18.521
Without comment above Code(Hardcoded Code or Commented Line)
18.521
0.749400479616307
0.07809
select transactional_curr_code,ORDERED_DATE from oe_order_headers_all
where header_id=1234
o/p:-
USD '23-APR-12'
select CONVERSION_RATE from gl_daily_rates
where from_currency = 'USD' --transactional_curr_code
and conversion_type = 'Corporate' --CONVERSION_TYPE_CODE
and conversion_date = '23-APR-12' --ORDERED_DATE
--and to_currency = 'USD'
CONVERSION_RATE
18.521
0.749400479616307
0.07809
select gsob.attribute1,gsob.currency_code from gl_sets_of_books
where SET_OF_BOOKS_ID=1
gsob.attribute1 gsob.currency_code
USD USDHi ,
Same as below code in the Function
select CONVERSION_RATE from gl_daily_rates
where from_currency = 'USD' --transactional_curr_code
and conversion_type = 'Corporate' --CONVERSION_TYPE_CODE
and conversion_date = '23-APR-12' --ORDERED_DATE
and to_currency = 'USD' -
Error while calling the function which returns SQL Query!!!
Hi,
I have a Function which returns SQL query. I am calling this function in my APEX report region source.
The query is dynamic SQL and its size varies based on the dynamic "where clause" condition.
But I am not able to execute this function.It gives me the following error in APEX region source.
ORA-06502: PL/SQL: numeric or value error: character string buffer too small
Even in SQL* Plus or SQL developer also same error .
The length of my query is more than 4000. I tried changing the variable size which holds my query in the function.
Earlier it was
l_query varchar2(4000)
Now I changed to
l_query varchar2(32767).
Still it is throwing the same error.
Can anybody help me to resolve this.???
Thanks
AlakaHi Varad,
I am already using 32k of varchar2. Then also it is not working.
It is giving the same error. I think there is something to do with buffer size.
My query size is not more than 4200. Even if i give 32k of varchar2 also buffer is able to hold only 3997 size of the query only.
Error is
ORA-06502: PL/SQL: numeric or value error: character string buffer too small
Tried CLOB also. It is not working.
Any other solution for this.
Thanks
Alaka -
Hello,
I've set up a region definition of type "SQL Query(PL/SQL function body return SQL query). In my query I make use of an "in" condition. When I populate :P755_INC_BARG_UNIT with a value of 0F (no quotes), I get the correct count. However, when I set :P755_INC_BARG_UNIT to 0F, 0E I get an invalid count. What do I have to set the page item to?
When running the query in TOAD, and setting :P755_INC_BARG_UNIT to the string inside the brackets (0F, 0E) I get the proper count.
The code I use is shown below. Any help would be appreciated,
Alex.
DECLARE
v_sql VARCHAR2(32767);
BEGIN
SELECT count(*) "cnts",
''Faculty data file IDs missing in appt table'' "err_type"
FROM hradmin.et_faculty_salary fs left outer join
hradmin.appointments appt
ON trim(fs.empl_id) = appt.emp_emp
and appt.ear_activ <> ''Z''
and appt.ear_type = ''F''
and (appt.ear_class in (''A'',''B'',''C'',''D''))
and appt.ear_bargunit in ( :P755_INC_BARG_UNIT )
WHERE appt.emp_emp is null
RETURN v_sql;
END;Alex,
try something like:
DECLARE
v_sql VARCHAR2(32767);
BEGIN
v_sql := <YOUR_SQL_STATEMENT_WITH_P755_INC_BARG_UNIT_IN_IT>;
v_sql := REPLACE(v_sql, ':P755_INC_BARG_UNIT',:P755_INC_BARG_UNIT);
RETURN v_sql;
END; But before doing it read this:
http://asktom.oracle.com/pls/apex/f?p=100:11:0::::P11_QUESTION_ID:210612357425
After reading you will be able to find the best solution yourself.
Lev -
How to view the sql query?
hi,
how to view the sql query formed from the xml structure in the receiver jdbc?You can view SAP Note at
http://service.sap.com/notes
But you require SMP login ID for this which you should get from your company. The content of the notes are as follows:
Reason and Prerequisites
You are looking for additional parameter settings. There are two possible reasons why a feature is available via the "additional parameters" table in the "advanced mode" section of the configuration, but not as documented parameter in the configuration UI itself:
Category 1: The parameter has been introduced for a patch or a SP upgrade where no UI upgrade and/or documentation upgrade was possible. In this case, the parameter will be moved to the UI and the documentation as soon as possible. The parameter in the "additional parameters" table will be deprecated after this move, but still be working. The parameter belongs to the supported adapter functionality and can be used in all, also productive, scenarios.
Category 2. The parameter has been introduced for testing purposes, proof-of-concept scenarios, as workaround or as pre-released functionality. In this case, the parameter may or may not be moved to the UI and documentation, and the functionality may be changed, replaced or removed. For this parameter category there is no guaranteed support and usage in productive scenarios is not supported.
When you want to use a parameter documented here, please be aware to which category it belongs!
Solution
The following list shows all available parameters of category 1 or 2. Please note:
Parameter names are always case-sensitive! Parameter values may be case-sensitive, this is documented for each parameter.
Parameter names and values as documented below must be used always without quotaton marks ("), if not explicitly stated otherwise.
The default value of a parameter is always chosen that it does not change the standard functionality
JDBC Receiver Adapter Parameters
1. Parameter name: "logSQLStatement"
Parameter type: boolean
Parameter value: true for any string value, false only for empty string
Parameter value default: false (empty String)
Available with: SP9
Category: 2
Description:
When implementing a scenario with the JDBC receiver adapter, it may be helpful to see which SQL statement is generated by the JDBC adapter from the XI message content for error analysis. Before SP9, this can only be found in the trace of the JDBC adapter if trace level DEBUG is activated. With SP9, the generated SQL statement will be shown in the details page (audit protocol) of the message monitor for each message directly.
This should be used only during the test phase and not in productive scenarios.
Regards,
Prateek -
I'm attempting to dynamically generate a rather large SQL query via the "PL/SQL function body returning SQL query" report region option. The SQL query generated will possibly be over 32K. When I execute my page, I sometimes receive the "ORA-06502: PL/SQL: numeric or value error" which points to a larger than 32K query that was generated. I've seen other posts in the forum related to this dynamic SQL size limitation issue, but they are older (pre-2010) and point to the 32K limit of the DNS (EXECUTE IMMEDIATE) and DBMS_SQL. I found this post (dynamic sql enhancements in 11g) which discusses 11g no longer having the 32K size limitation for generating dynamic SQL. Our environment is on 11gR2 and using ApEx 4.2.1. I do not know which dynamic SQL method -- DNS or DBMS_SQL -- ApEx 4.2.1 is using. Can someone clarify for me which dynamic SQL method ApEx uses to implement the "PL/SQL function body returning SQL query" option?
As a test, I created a page on apex.oracle.com with a report region with the following source:
declare
l_stub varchar2(25) := 'select * from sys.dual ';
l_sql clob := l_stub || 'union all ';
br number(3) := 33;
begin
while length ( l_sql ) < 34000 loop
l_sql := l_sql || l_stub || 'union all ';
end loop;
l_sql := l_sql || l_stub;
for i in 1 .. ceil ( length ( l_sql ) / br ) loop
dbms_output.put_line ( dbms_lob.substr ( l_sql, br, ( ( i - 1 ) * br ) + 1 ) );
end loop;
return l_sql;
end;
The dbms_output section is there to be able to run this code in SQL*Plus and confirm the size of the SQL is indeed larger than 32K. When running this in SQL*Plus, the procedure is successful and produces a proper SQL statement which can be executed. When I put this into the report region on apex.oracle.com, I get the ORA-06502 error.
I can certainly implement a work-around for my issue by creating a 'Before Header' process on the page which populates an ApEx collection with the data I am returning and then the report can simply select from the collection, but according to documentation, the above 32K limitation should be resolved in 11g. Thoughts?
Shane.What setting do you use in your report properties - especially in Type and in Region Source?
If you have Type="SQL Query", then you should have a SELECT statement in the Region Source. Something like: SELECT .... FROM ... WHERE
According to the ERR-1101 error message, you have probably set Type to "SQL Query (PL/SQL function body returning SQL query)". In this situation APEX expects you to write a body of a PL/SQL function, that will generate the text of a SQL query that APEX should run. So it can be something like:
declare
mycond varchar2(4000);
begin
if :P1_REPORT_SEARCH is not null THEN
mycond:='WHERE LAST_NAME like :P1_REPORT_SEARCH ||''%''';
end if;
return 'select EMPLOYEE_ID, FIRST_NAME, LAST_NAME from EMPLOYEES ' ||mycond;
end;
And for escaping - are you interested in escaping the LIKE wildcards, or the quotes?
For escaping the wildcards in LIKE function so that when the user enters % you will find a record with % and not all functions, look into the SQL Reference:
http://download-uk.oracle.com/docs/cd/B19306_01/server.102/b14200/conditions007.htm
(You would than need to change the code of your function accordingly).
If you are interested in escaping the quotes, try to avoid concatenating the values entered by the user into the SQL. If you can, use bind variables instead - as I have in my example above. If you start concatenating the values into the text of SQL, you are open to SQLInjection - user can enter anything, even things that will break your SQL. If you really need to allow users to choose the operator, I would probably give them a separate combo for operators and a textfield for values, than you could check if the operator is one of the allowed ones and create the condition accordingly - and than still use bind variable for inserting the filtering value into the query. -
Region source (PL/SQL function body returning SQL query)
Hi, guys.
Here is what i try to do:
Create a region of type SQL Query (PL/SQL function body returning SQL query). In the source area i tried to put this:
DECLARE
v_new VARCHAR2(10);
v_SQL varchar2(32000);
BEGIN
v_new := :P102_HDN_NEW;
-- htp.p(v_new);
IF v_new = 'N-Set' THEN
v_SQL := 'select ' ||
ELSIF v_new = 'Y-Set' THEN
v_SQL := 'select ' ||
END IF;
RETURN v_SQL;
END;
And here is the reply from APEX:
1 error has occurred
Query cannot be parsed within the Builder. If you believe your query is syntactically correct, check the ''generic columns'' checkbox below the region source to proceed without parsing. The query can not be parsed, the cursor is not yet open or a function returning a SQL query returned without a value.
Now.
1. Variable is set with the right value.
2. Each statement (separately) returns SQL that works with no problems
3. Problem occures if i try to put IF statement around the SQL creation.
4. If i select "Use Generic Column Names (parse query at runtime only)" instead of "Use Query-Specific Column Names and Validate Query" then the script returns SQL properly, however report's column names are set to Col1, Col2,Col3 ......
Thnks in advence
MikeOK. Here is enire statement:
DECLARE
v_new VARCHAR2(10);
v_SQL varchar2(32000);
BEGIN
v_new := :P102_HDN_NEW;
htp.p(v_new);
IF v_new = 'N-Set' THEN
v_SQL := 'select ' ||
'APEX_ITEM.DISPLAY_AND_SAVE(10,c.sdescr) descr, ' ||
'APEX_ITEM.DISPLAY_AND_SAVE(12,DECODE(ld.level,''All'', ''All Categories'',ld.level)) level, ' ||
'apex_item.checkbox(1, ld.opt_in_auto_flag, decode(ld.opt_in_auto_flag,NULL,''disabled'',''Y'',''checked'')) auto_in, ' ||
'apex_item.checkbox(2, ld.opt_in_manual_flag, decode(ld.opt_in_manual_flag,NULL,''disabled'',''Y'',''checked'')) manual_in, ' ||
'apex_item.checkbox(3, ld.opt_out_auto_flag, decode(ld.opt_out_auto_flag,NULL,''disabled'',''Y'',''checked'')) auto_out, ' ||
'apex_item.checkbox(4, ld.opt_out_manual_flag, decode(ld.opt_out_manual_flag,NULL,''disabled'',''Y'',''checked'')) manual_out, ' ||
'DECODE(c.code, ''NMBR'', NULL,''Change to '' || DECODE(ld.level,''All'',''Categories'',''All Categories'')) link_change, ' ||
'APEX_ITEM.DISPLAY_AND_SAVE(11,c.code) code ' ||
'from ' ||
'tbl1 c, ' ||
'tbl2 ld ' ||
'where c.code = ld.code ' ||
'and c.type = ''TYPE1'' ' ||
'and c.active = ''Y'' ' ||
'order by c.sorting ';
ELSIF v_new = 'Y-Set' THEN
v_SQL := 'select ' ||
'APEX_ITEM.DISPLAY_AND_SAVE(10,c.sdescr) descr, ' ||
'APEX_ITEM.DISPLAY_AND_SAVE(12,''All Categories'') level, ' ||
'apex_item.checkbox(1, c.option_1, decode(c.option_1,NULL,''disabled'',''Y'',''checked'')) auto_in, ' ||
'apex_item.checkbox(2, c.option_3, decode(c.option_3,NULL,''disabled'',''Y'',''checked'')) manual_in, ' ||
'apex_item.checkbox(3, c.option_2, decode(c.option_2,NULL,''disabled'',''Y'',''checked'')) auto_out, ' ||
'apex_item.checkbox(4, c.option_4, decode(c.option_4,NULL,''disabled'',''Y'',''checked'')) manual_out, ' ||
'DECODE(c.code, ''AAA'', NULL,''Options by AAA'') link_change, ' ||
'APEX_ITEM.DISPLAY_AND_SAVE(11,c.code) code ' ||
'from ' ||
'tbl1 c ' ||
'where 1 = 1 ' ||
'and c.type = ''TYPE1'' ' ||
'and c.active = ''Y'' ' ||
'order by c.sorting ';
END IF;
RETURN v_SQL;
END;
If i put just this
DECLARE
v_new VARCHAR2(10);
v_SQL varchar2(32000);
BEGIN
v_new := :P102_HDN_NEW;
htp.p(v_new);
v_SQL := 'select ' ||
'APEX_ITEM.DISPLAY_AND_SAVE(10,c.sdescr) descr, ' ||
'APEX_ITEM.DISPLAY_AND_SAVE(12,DECODE(ld.level,''All'', ''All Categories'',ld.level)) level, ' ||
'apex_item.checkbox(1, ld.opt_in_auto_flag, decode(ld.opt_in_auto_flag,NULL,''disabled'',''Y'',''checked'')) auto_in, ' ||
'apex_item.checkbox(2, ld.opt_in_manual_flag, decode(ld.opt_in_manual_flag,NULL,''disabled'',''Y'',''checked'')) manual_in, ' ||
'apex_item.checkbox(3, ld.opt_out_auto_flag, decode(ld.opt_out_auto_flag,NULL,''disabled'',''Y'',''checked'')) auto_out, ' ||
'apex_item.checkbox(4, ld.opt_out_manual_flag, decode(ld.opt_out_manual_flag,NULL,''disabled'',''Y'',''checked'')) manual_out, ' ||
'DECODE(c.code, ''NMBR'', NULL,''Change to '' || DECODE(ld.level,''All'',''Categories'',''All Categories'')) link_change, ' ||
'APEX_ITEM.DISPLAY_AND_SAVE(11,c.code) code ' ||
'from ' ||
'tbl1 c, ' ||
'tbl2 ld ' ||
'where c.code = ld.code ' ||
'and c.type = ''TYPE1'' ' ||
'and c.active = ''Y'' ' ||
'order by c.sorting ';
RETURN v_SQL;
END;
it works fune... -
SQL Query (PL/SQL Function Body returning SQL query) doesn't return any row
I have a region with the following type:
SQL Query (PL/SQL Function Body returning SQL query).
In a search screen the users can enter different numbers, separated by an ENTER.
I want to check these numbers by replacing the ENTER, which is CHR(13) || CHR(10) I believe, with commas. And then I can use it like this: POD IN (<<text>>).
It's something like this:
If (:P30_POD Is Not Null) Then
v_where := v_where || v_condition || 'POD IN (''''''''||REPLACE(''' || :P30_POD || ''', CHR(13) || CHR(10), '','')||'''''''''')';
v_condition := ' AND ';
End If;
But the query doesn't return any rows.
I tried to reproduce it in Toad:
select * from asx_worklistitem
where
POD IN (''''||REPLACE('541449200000171813'||CHR(13) || CHR(10)||'541449206006341366', CHR(13) || CHR(10), ''',''')||'''')
==> This is the query that does't return any rows
select (''''||REPLACE('541449200000171813'||CHR(13) || CHR(10)||'541449206006341366', CHR(13) || CHR(10), ''',''')||'''')
from dual;
==> This returns '541449200000171813','541449206006341366'
select * from asx_worklistitem
where pod in ('541449200000171813','541449206006341366');
==> and when I copy/paste this in the above query, it does return my rows.
So why does my first query doesn't work?
Doe anyone have any idea?
Kind regards,
Geert
Message was edited by:
ZorryThanks for the help.
I made it work, but via the following code:
If (:P30_POD Is Not Null) Then
v_pods := REPLACE(:P30_POD, CHR(13) || CHR(10));
v_where := v_where || v_condition || 'POD IN (';
v_counter := 1;
WHILE (v_counter < LENGTH(v_pods)) LOOP
v_pod := SUBSTR(v_pods, v_counter, 18);
IF (v_counter <> 1) THEN
v_where := v_where || ',';
END IF;
v_where := v_where || '''' || v_pod || '''';
v_counter := v_counter + 18;
END LOOP;
v_where := v_where || ')';
v_condition := ' AND ';
End If;But now I want to make an update of all the records that correspond to this search criteria. I can give in a status via a dropdownlist and that I want to update all the records that correspond to one of these POD's with that status.
For a region you can build an SQL query via PL/SQL, but for a process you only have a PL/SQL block. Is the only way to update all these records by making a loop and make an update for every POD that is specified.
Because I think this will have a lot of overhead.
I would like to make something like a multi row update in an updateable report, but I want to specify the status from somewhere else. Is this possible? -
Using Package to produce pl/sql function body returning sql query Report
I have existing code that we want to use in building reports in APEX. We are needing to modify it slightly to handle some new requirements, but would like to use them in reports based upon SQL query (pl/sql function body returning sql query) functionality.
Any suggestions as how to call these in an APEX report region?
Thank you,
Tony Miller
UTMB/EHNHi Tony-
I am also v new to Apex and you may have answered a question I was in search of. I, however, now have a couple more. First a bit of background-- Like in your situation, my college has a lot of existing code (400 +) that we need to get into Apex. The majority of this canned code contains one/both: 1) many lines, sometimes containing multiple select statements 2) imbedded create table & view statements (temp user owned). Up until reading your post, I was unable to figure out an easy way of getting this existing code into the product. Thanks. Now the questions, do you know how I would go about dealing with the create tables/views. I've read some posts on this forum which suggest temporary tables being unstable in this environment. Also, do you know if there's a size limitation when passing sql code via a function?
As you may/may not be able to tell, I'm a bit lost right now... so any info you can provide would be appreciated. Thanks.
Don -
Error in report when executing pl/sql function body returning sql query.
Hi,
I have used the pl/sql function body returning sql query for creating a report. I have created a datepicker(
P10_TASK_DATE) which can be submitted.The code is as below
DECLARE
v_sql varchar2(3000);
BEGIN
if :P10_TASK_DATE is not null THEN
v_sql:='select
* from tasks';
return v_sql;
else
v_sql:='select * from discovery';
return v_sql;
END IF;
END;if the date field is empty "select * from discovery" is executed and report is getting generated. But when we give a
date using date picker the page is submitted and i get "report error: ORA-01403: no data found" even
though the "tasks" table has data in it. Plz help
Thanks,
TJhi
Please try this
1. Create 2 region
1st region source=
select * from tasks'
go to the tab -> condition =
item NOT NULL
EXpression1 =:P10_TASK_DATE
this will run whenever the item have any date
2. open your 2 nd region source code= select * from discovery
put the condition
item is NULL
EXpression1 =:P10_TASK_DATE
thanks
Mark Wyatt -
How to get cm:search to use the max attribute when creating the SQL query?
When we use the max attribute in the cm:search tag, it does not seem to honor the max attribute when creating the SQL query. However, the result returned from the tag is limited to the number specified by the max attribute. Then the tag seems to work as intended, but the performance will be sub optimal when the SQL query returns unnecessary rows to the application.
We use the cm:search tag to list the latest news (ordered by date), and with the current implementation we have to expect a decrease in performance over time as more news is published. But we can’t live with that. We need to do the constraint in the SQL query, not in the application.
The sortBy attribute of cm:search is translated to “order by” in the SQL query, as expected.
Is it possible to get cm:search to generate the SQL query with an addition of “where rownum <= maxRows”?Hi Erik,
The behavior of a repository in regards to the search tag's max results parameter is dependent on the underlying repository's implementation. That said, the OOTB repository in WLP does augment the generated SQL to limit the number of rows returned from the database. This is done in the parsing logic. This behavior may differ with other repository implementations.
-Ryan -
How to find out which Tables have been accessed without looking at the SQL query ?
Hi,
I would like to know is there a way to find out what queries have been executed and on which tables without looking at the SQL query.
I have an old C++ code which calls some library functions to access the Oracle database. The source code for the library is not available to me yet. The functions selects/updates/deletes and inserts based on some input parameters I give. I do not know which tables it affects. How do I find out the actual SQL query and/or the tables it accesses ? I was told about V$SQL table that
has the most recently executed queries, but
I did'nt see any queries connected to my process.
Could anybody help me on this ?
Thanks
Jagdeep
[email protected]
nullPRECISE/SQL can help you if you have access to it
2nd option can be that turn on SQL_TRACE
Run executable of ur c++ program
it will create a trace file in user_dump_dest
and then using TKPROF u can see all quesries and their plan also.
HTH
Gagan Deep Singh
<BLOCKQUOTE><font size="1" face="Verdana, Arial, Helvetica">quote:</font><HR>Originally posted by (jagdeeps):
Hi,
I would like to know is there a way to find out what queries have been executed and on which tables without looking at the SQL query.
I have an old C++ code which calls some library functions to access the Oracle database. The source code for the library is not available to me yet. The functions selects/updates/deletes and inserts based on some input parameters I give. I do not know which tables it affects. How do I find out the actual SQL query and/or the tables it accesses ? I was told about V$SQL table that
has the most recently executed queries, but
I did'nt see any queries connected to my process.
Could anybody help me on this ?
Thanks
Jagdeep
[email protected]<HR></BLOCKQUOTE>
null -
In JDBC Sender Adapter , the server is Microsoft SQL .I need to pass current date as the input column while Executing stored procedure, which will get me 10 Output Columns. Kindly suggest me the SQL Query String , for executing the Stored Procedure with Current date as the input .
Hi Srinath,
The below blog might be useful
http://scn.sap.com/community/pi-and-soa-middleware/blog/2013/03/06/executing-stored-procedure-from-sender-adapter-in-sap-pi-71
PI/XI: Sender JDBC adapter for Oracle stored procedures in 5 days
regards,
Harish -
SQL Query (pl/sql function body returning Sql query)
Hi All,
I have created a region of "SQL Query (pl/sql function body returning Sql query)" type and it is working fine , but when I am migrating(export /import) this application from development to systest environment ,
It gives error for this region :
Error ERR-1101 Unable to process function body returning query.
OK
ORA-06550: line 1, column 52: PLS-00306: wrong number or types of arguments in call to 'FU_TRADE_REPORT_QUERY' ORA-06550: line 1, column 45: PL/SQL: Statement ignored
Any pointer ...why this is happening.
Thanks
DikshitIf your function is a stored function that is called from within APEX (function body not coded into the app itself), have you made sure that the function has been created and compiles ok prior to installing your apex app.
If there are some dependency issues between other PL/SQL units or database objects that are causing your function not to be compiled, you apex install will fail as you are trying to reference an uncompelled bit of pl/sql.
Let me know how you get on
Regards
Duncan -
Pl/sql function body returning SQL query - Print function
Hello all,
I have pl/sql function body returning SQL query for my reports for my new project that I am developing. We dont have any BI tool or anything for APEX so we use Oracle reports to get the same reports to be printed in PDF format. I had been using SQL function for Reports all these days and grabbing the data using SQL query was easy in Oracle reports. But this time we had atleast 8 fields in search criteria and hence I thouhgt PL/sql function body returning SQL query could be something easy to handle that scenario. We have 11 such reports in our project. Now when we tried to use the same PL/sql function to oracle reports , I was told by one of our Oracle reports expert, that we have to write it into functions and use it in SQL query to get the Reports in Oracle reports. Is there any Easy way to convert the same Pl/SQL function or get a PDF format of the same report in APEX without going thru the much pains of rewriting the whole SQL Query.
thank you
DevisriHi,
give this a go.
I can't test it as I don't have the tables in my schema.
create or replace package MK_TEST_PF is
-- Author : MK
-- Created : 21/06/2010 16:30:19
-- Purpose : FOR LUCY_DISCOVER
-- Public type declarations
/* -- just guess the table row types.....
-- otherwise it won't compile
type test_rec is record
(INV REP.inv%type
,cNUMBER REP.cNUMBER%type
,OPENDATE REP.OPENDATE%type
,TARGETDATE REP.ESTCOMPLETE%type
,DATECLOSED REP.COMPLETED%type
,STATUS REP.STATUS%type
,cCODE REP.cCODE%type
,line varchar2(4000)
,SIGc varchar2(4000)
,CLASS REP.CLASS%type
,SUMM REP.SUMM%type
,AREA REP.AREA%type
type test_rec is record
(INV varchar2(4000)
,cNUMBER varchar2(4000)
,OPENDATE varchar2(4000)
,TARGETDATE varchar2(4000)
,DATECLOSED varchar2(4000)
,STATUS varchar2(4000)
,cCODE varchar2(4000)
,line varchar2(4000)
,SIGc varchar2(4000)
,CLASS varchar2(4000)
,SUMM varchar2(4000)
,AREA varchar2(4000)
type test_tab is table of test_rec;
-- Public constant declarations
-- Public variable declarations
-- Public function and procedure declarations
end MK_TEST_PF;
create or replace package body MK_TEST_PF is
-- Private type declarations
-- Private constant declarations
-- Private variable declarations
-- Function and procedure implementations
function get_query_f
(p_inv VARCHAR2 := UPPER(v('P44_INV'))
,p_reg VARCHAR2 := UPPER(v('P44_CLASS'))
,p_proarea VARCHAR2 := UPPER(v('P44_PROGRAM_AREA'))
,p_disp VARCHAR2 := UPPER(v('P44_DISPOSITION'))
,p_coding VARCHAR2 := UPPER(v('P44_CODING'))
,p_status VARCHAR2 := UPPER(v('P44_STATUS'))
,p_SIG VARCHAR2 := UPPER(v('P44_SIG_c'))
,p_inc_sum VARCHAR2 := UPPER(v('P44_INCLUDE_SUMM_FIELD'))
,p_word VARCHAR2 := UPPER(v('P44_WORD_IN_SUMM'))
,p_timeframe VARCHAR2 := UPPER(v('P44_TIME_FRAME'))
,p_rec VARCHAR2 := UPPER(v('P44_RECORD_KEEPING'))
,p_WORD_IN_SUMM VARCHAR2 := UPPER(v('P44_WORD_IN_SUMM'))
,p_ON_AFTER VARCHAR2 := UPPER(v('P44_ON_AFTER'))
,p_ON_BEFORE VARCHAR2 := UPPER(v('P44_ON_BEFORE'))
return varchar2
is
v_sql VARCHAR2(5000);
-- v_inv VARCHAR2(100);
-- v_reg VARCHAR2(100);
-- v_proarea VARCHAR2(100);
-- v_status VARCHAR2(100);
-- v_SIG VARCHAR2(100);
-- v_disp VARCHAR2(100);
-- v_coding VARCHAR2(100);
-- v_inc_sum VARCHAR2(4);
-- v_word VARCHAR2(4000);
v_wildcard VARCHAR2(2000);
-- v_timeframe VARCHAR2(100);
-- v_rec VARCHAR2(5);
v_record VARCHAR2(5);
v_open VARCHAR2(100);
v_closed VARCHAR2(100);
v_PEND VARCHAR2(100);
v_refSIG VARCHAR2(100);
v_refreg VARCHAR2(100);
v_refother VARCHAR2(100);
v_y varchar2(100);
BEGIN
--v_inv := UPPER(v('P44_INV')) ;
v_record := 'R%';
v_wildcard := '%';
v_open := 'OPEN';
v_closed := 'CLOSED';
v_PEND := 'PEND';
v_refSIG := 'REF - SIG';
v_refreg := 'REF - CLASS';
v_refother := 'REF - OTHER';
v_y := 'Y';
v_sql := 'SELECT REP.INV as INV, REP.cNUMBER as cNUMBER, REP.OPENDATE as OPENDATE,
REP.ESTCOMPLETE as TARGETDATE, REP.COMPLETED as DATECLOSED, REP.STATUS as STATUS,
REP.cCODE as cCODE, apex_item.checkbox(1,REP.line,null,'''||v_y||''') line , apex_item.checkbox(1,REP.SIG,null,'''||v_y||''') SIGc ,
REP.CLASS as CLASS, REP.SUMM as SUMM, REP.AREA as AREA from REP where 1=1';
IF p_rec is not null then
IF p_rec = 'E' then
v_sql := v_sql|| ' and upper(REP.cnumber) not like '''||v_record||'''';
ELSIF p_rec = 'D' then
v_sql := v_sql|| ' and upper(REP.cnumber) like '''||v_record||'''';
ELSIF p_rec = 'I' then
v_sql := v_sql|| ' and REP.cnumber = REP.cnumber ';
end if ;
end if ;
IF upper(p_status) not like '%NULL%' then
IF upper(p_status) like '%OPEN%' then
v_sql := v_sql||' AND upper(REP.status) like '''||v_open||'''';
ELSIF upper(p_status) like '%CLOSED%' then
v_sql := v_sql||' AND upper(REP.status) like '''||v_closed||'''';
ELSIF upper(v_PEND) like '%PEND%' then
v_sql := v_sql||' AND upper(REP.status) like '''||v_PEND||'''';
ELSIF upper(v_refSIG) like '%REF - SIG%' then
v_sql := v_sql||' AND upper(REP.status) like '''||v_refSIG||'''';
ELSIF upper(v_refreg) like '%REF - CLASS%' then
v_sql := v_sql||' AND upper(REP.status) like '''||v_refreg||'''';
ELSIF upper(v_refother) like '%REF - OTHER%' then
v_sql := v_sql||' AND upper(REP.status) like '''||v_refother||'''';
END IF ;
END IF ;
IF p_inv = 'NULL' THEN
v_sql := v_sql||' AND instr(upper(REP.INV),'''||p_inv||''') > 0';
END IF ;
IF p_reg = 'NULL' THEN
v_sql := v_sql||' AND instr(upper(REP.CLASS),'''||p_reg||''') > 0';
END IF ;
IF p_proarea = 'NULL' THEN
v_sql := v_sql||' AND instr(upper(REP.AREA),'''||p_proarea||''') > 0';
END IF ;
IF p_disp = 'NULL' THEN
v_sql := v_sql||' AND instr(upper(REP.disposition),'''||p_disp||''') > 0';
END IF ;
IF p_coding = 'NULL' THEN
v_sql := v_sql||' AND instr(upper(REP.ccode),'''||p_coding||''') > 0';
END IF ;
IF p_SIG = ' ' THEN
v_sql := v_sql||' AND instr(upper(REP.SIG),'''||p_SIG||''') > 0';
END IF ;
IF p_word is not null then
v_sql := v_sql|| ' and
instr(upper(REP.SUMM),
upper(nvl('''||p_WORD_IN_SUMM||''',REP.SUMM))) > 0';
end if ;
If p_timeframe is not null then
if upper(p_timeframe) = 'OPEN' then
v_sql := v_sql|| ' and to_date(REP.opendate) between to_date ('''||p_ON_AFTER||''') and to_date('''||p_ON_BEFORE||''')';
elsif upper(p_timeframe) = 'CLOSED' then
v_sql := v_sql|| ' and to_date(REP.completed) between to_date ('''||p_ON_AFTER||''') and to_date('''||p_ON_BEFORE||''')';
elsif upper(p_timeframe) = 'EST' then
v_sql := v_sql|| ' and to_date(REP.estcomplete) between to_date ('''||p_ON_AFTER||''') and to_date('''||p_ON_BEFORE||''')';
end if;
end if;
v_sql := v_sql ||' order by REP.INV ';
return v_sql;
end get_query_f;
function test_pf
(p_inv VARCHAR2 := UPPER(v('P44_INV'))
,p_reg VARCHAR2 := UPPER(v('P44_CLASS'))
,p_proarea VARCHAR2 := UPPER(v('P44_PROGRAM_AREA'))
,p_disp VARCHAR2 := UPPER(v('P44_DISPOSITION'))
,p_coding VARCHAR2 := UPPER(v('P44_CODING'))
,p_status VARCHAR2 := UPPER(v('P44_STATUS'))
,p_SIG VARCHAR2 := UPPER(v('P44_SIG_c'))
,p_inc_sum VARCHAR2 := UPPER(v('P44_INCLUDE_SUMM_FIELD'))
,p_word VARCHAR2 := UPPER(v('P44_WORD_IN_SUMM'))
,p_timeframe VARCHAR2 := UPPER(v('P44_TIME_FRAME'))
,p_rec VARCHAR2 := UPPER(v('P44_RECORD_KEEPING'))
,p_WORD_IN_SUMM VARCHAR2 := UPPER(v('P44_WORD_IN_SUMM'))
,p_ON_AFTER VARCHAR2 := UPPER(v('P44_ON_AFTER'))
,p_ON_BEFORE VARCHAR2 := UPPER(v('P44_ON_BEFORE'))
RETURN test_tab PIPELINED
is
type test_c is ref cursor;
v_row test_tab;
v_sql varchar2(4000);
v_cursor test_c;
begin
v_sql := get_query_f
(p_inv
,p_reg
,p_proarea
,p_disp
,p_coding
,p_status
,p_SIG
,p_inc_sum
,p_word
,p_timeframe
,p_rec
,p_WORD_IN_SUMM
,p_ON_AFTER
,p_ON_BEFORE
open v_cursor for v_sql;
fetch v_cursor bulk collect into v_row;
close v_cursor;
for i in 1 .. v_row.count loop
pipe row (v_row(i));
end loop;
return;
end test_pf;
end MK_TEST_PF;
/Regards
Michael
Maybe you are looking for
-
Download issue when Windows 7 Pro joins a Windows Server 2008 Active Directory
Hi, I purchased 2 new Dell OptiPlex 3010 desktop computers that came with Windows 7 Professional operating system with SP1. There were no Microsoft updates installed yet. After I added one of these Dell computers to the Windows Server 2008 Active D
-
I am unable to open a PDF file in Firefox 3.6.8. Adobe Acrobat Reader 9.3.3 is installed. I get the error message "The Adobe Acrobat/Reader that is running can not be used to view PDF files in a web browser."
-
Reboot due to system error / Register dump from exception handler
hi, I have a problem with Labview RT when using Reboot function. The RT target (desktop) reboot but there is a message : Reboot due to system error. And if I reboot once again, the target become in safe mode. Now, If I look at the log I obtain the f
-
CS3: Placing files - with a reduction
When placing something (a pdf file, but it doesn't really matter in this case) and I reduce it, is there someplace where you can see exactly how much it's being reduced? I remember in PageMaker, there was a notation in the control panel that said exa
-
SES error when doing thru Requistion
Dear All, We have created a Service PO with planned service line items and with reference to that, PM order created. During PM order creation, a requisition got generated. Using that requisition, in ML81N trying to create SES. But the error appears a