Replace function in where clause IN (list)
DECLARE @DNNo NVARCHAR(15), @InvDNNo NVARCHAR(200)
SELECT @DNNo='11-0748-DN01', @InvDNNo='11-0748-DN01,11-0748-DN02,11-0748-DN03,11-0748-DN04'
Select 1 Where @DNNo IN (''''+ REPLACE(@InvDNNo,',',''',''') + '''' )
It must be worked as per syntax, but it doesn't
Anybody can help me out?
Thanks & regards
Abdul Rahiman
Thank you Naomi for attending my query.
Actually I need to get sum of quantity invoiced against a Delivery Note Number (@DNNo). Delivery
Note numbers are stored in the Invoice table(I1.DNNo) as a comma separated value(Create one invoice
from Multiple Delivery Notes). This query is neither a standalone nor an sp. It is a sub query. Please see the sub query below. I appreciate your time and patience.
Select Sum(I2.PrintQty) From IDEAPLUS2012.dbo.Invoice I1 Inner Join
IDEAPLUS2012.dbo.InvoiceItem I2 ON I1.KeyFld=I2.KeyFld
WHERE @DNNo in (''''+ REPLACE(I1.DNNo,',',''',''') + '''')
Similar Messages
-
Using function in where clause
I have created a function as follows
create or replace FUNCTION get_codes RETURN varchar2 IS
scodes varchar2(50) := 'A1,A2';
BEGIN
scodes := '('''||REPLACE(scodes,',',''',''')||''')';
return scodes;
END;
this function returns ('A1','A2')
now i want to use this in where clause, both below statements fetches no rows
select * from tablea where code in (select get_codes from dual);
select * from tablea where code in get_codes;
but the following will fetch rows
select * from tablea where code in ('A1','A2')
how to use function in where clause
ThanksHi,
The code that works:
where code in ('A1','A2')is testing whther code is either of two 2-character strings, A1 or A2.
The ones that don't work, such as:
where code in get_codes;are comparing code to one 9-character string: 'A1','A2', where characters 1, 4, 6 and 9 are single-quotes. (The function can only return one value.)
You can use dynamic SQL to embed that 9-character string in part of your query, where it will be interpreted as two 2-character strrings.
[Oracle Base|http://www.oracle-base.com/articles/misc/DynamicInLists.php] and AskTom have good pages on the subject of dynamic IN-lists.
Of you can use INSTR or LIKE:
where INSTR ( get_codes
, '''' || code || ''''
) > 0 -
My function in where clause? help me please.
hello friends, I need to call my function in where clause as dummy example below:
declare
name_ table1.name%type;
function return_id(id number) return number is
begin
return 1;
end return_id;
begin
select name into name_
from table1
where id = return_id(table1.id);
end;
raise exception: 'the function doesn't used in where clause'. why????-- CREATING A FUNCTION AVAILABLE THROUGH A PACKAGE SPEC.
SQL> ed
Wrote file afiedt.buf
1 create package mypackage is
2 function myfunc(p_val NUMBER) RETURN NUMBER;
3* end;
SQL> /
Package created.
SQL> ed
Wrote file afiedt.buf
1 create or replace package body mypackage is
2 function myfunc(p_val NUMBER) RETURN NUMBER IS
3 begin
4 RETURN (p_val*p_val)-1;
5 end;
6* end;
SQL> /
Package body created.
SQL> declare
2 v_myval NUMBER := 2;
3 begin
4 select mypackage.myfunc(v_myval)
5 into v_myval
6 from dual;
7 dbms_output.put_line(v_myval);
8 select mypackage.myfunc(v_myval)
9 into v_myval
10 from dual;
11 dbms_output.put_line(v_myval);
12 end;
13 /
3
8
PL/SQL procedure successfully completed.
-- CREATING A STANDALONE DATABASE FUNCTION.
SQL> create or replace function myfunc2(p_val number) return number is
2 begin
3 return (p_val*2)+1;
4 end;
5 /
Function created.
SQL> ed
Wrote file afiedt.buf
1 declare
2 v_myval NUMBER := 2;
3 begin
4 select myfunc2(v_myval)
5 into v_myval
6 from dual;
7 dbms_output.put_line(v_myval);
8 select myfunc2(v_myval)
9 into v_myval
10 from dual;
11 dbms_output.put_line(v_myval);
12* end;
SQL> /
5
11
PL/SQL procedure successfully completed.
-- CREATING A LOCAL FUNCTION IN THE ANONYMOUS PL/SQL BLOCK
SQL> ed
Wrote file afiedt.buf
1 declare
2 v_myval NUMBER := 2;
3 function myfunc3(p_val number) return number is
4 begin
5 return (p_val*p_val*p_val);
6 end;
7 begin
8 select myfunc3(v_myval)
9 into v_myval
10 from dual;
11 dbms_output.put_line(v_myval);
12 select myfunc3(v_myval)
13 into v_myval
14 from dual;
15 dbms_output.put_line(v_myval);
16* end;
SQL> /
select myfunc3(v_myval)
ERROR at line 8:
ORA-06550: line 8, column 10:
PLS-00231: function 'MYFUNC3' may not be used in SQL
ORA-06550: line 8, column 10:
PL/SQL: ORA-00904: : invalid identifier
ORA-06550: line 8, column 3:
PL/SQL: SQL Statement ignored
ORA-06550: line 12, column 10:
PLS-00231: function 'MYFUNC3' may not be used in SQL
ORA-06550: line 12, column 10:
PL/SQL: ORA-00904: : invalid identifier
ORA-06550: line 12, column 3:
PL/SQL: SQL Statement ignored
SQL>As you can see (and as previously mentioned by someone else) the function has to be available to the SQL engine either via a datavbase package or as a database function. If you declare the function locally within the anonymous PL/SQL block then the function only exists in the scope of that PL/SQL block and thus when your SQL statement is sent to the SQL engine for execution, the SQL engine can't see it.
;) -
Clarification on using function in where clause of oracle sql query
I have an issue in regarding function using where clause of sql query..
We are facing performance issue while executing query, so in what ways to improve the performance of the query which i have posted below.
select col ,case when my_function(parameter)
from tab1 a ,tab2 b,tabl3 c
where a.column1=b.column2
and b.column3 =c.column6
and my_function(parameter)>0
Regards
Dinesh
Edited by: wild fire on May 18, 2012 4:15 PMDinesh,
remind that when you use a function in the where clause it normally will get started for each record in the table.
So your answer is two-fold:
1. make the function only start when needed by adding a function based index on the table (this will make inserts and updates slower)
2. make the function faster by adding the DETERMINISTIC clause if possible. this will make Oracle "cache" the result of the function.
Regards,
Richard
blog: http://blog.warp11.nl
twitter: @rhjmartens
If this question is answered, please mark the thread as closed and assign points where earned.. -
Can't have aggregate function in WHERE clause clause
Dear all,
I've created object in BO XI 3.1 Designer with following criterias:
http://img4.imageshack.us/img4/833/20111201124314.th.jpg
It is a simple number - 1,2,3,4,5.
Now I need to use this object as a criteria for WHERE function in another object.
http://img607.imageshack.us/img607/1543/20111201124717.th.jpg
I receive an error "Can't have aggregate function in WHERE clause <clause>"
How can I overcome this?
P.S. I'm sorry in advance if such topic already exist - I didn't found one.
Edited by: Ashot Antonyan on Dec 1, 2011 9:50 AM
Edited by: Ashot Antonyan on Dec 1, 2011 9:51 AMHi,
You will have to use Sub query to achieve this. Give more details on what is available and what you need then i could help you out with the complete solution.
Thanks,
Ravichandra K -
Help:alternate for calling function in where clause
Hi ,
In below query i'm calling function in where clause to avoid COMPLETE status records,due to this query taking 700 secs to return result.If i'm remove below function condition it's returning results with in 5 secs.Can you some one advice to any alternate idea for this?
WHERE mark_status != 'COMPLETE'
SELECT assessment_school,
subject,
subject_option,
lvl,
component,mark_status,
mark_status
NULL AS grade_status,
NULL AS sample_status,
:v_year,
:v_month,
:v_formated_date,
:v_type,
cand_lang
FROM
(SELECT assessment_school,
subject,
subject_option,
lvl,
programme,
component,
paper_code,
cand_lang,
mark_entry.get_ia_entry_status(:v_year, :v_month, assessment_school, subject_option, lvl, cand_lang, component, paper_code) AS mark_status
FROM
(SELECT DISTINCT ccr.assessment_school,
ccr.subject,
ccr.subject_option,
ccr.lvl,
ccr.programme,
ccr.language AS cand_lang,
ccr.paper_code,
ccr.component
FROM candidate_component_reg ccr
WHERE ccr.split_session_year = :v_year
AND ccr.split_session_month = :v_month
AND EXISTS
(SELECT 1
FROM IBIS.subject_component sc
WHERE sc.year = ccr.split_session_year
AND sc.month = ccr.split_session_month
AND sc.paper_code = ccr.paper_code
AND sc.assessment_type = 'INTERNAL'
AND sc.subject_option NOT LIKE '%self taught%'
AND sc.component NOT IN ('PERFORMANCE PRODUCTION','PRESENTATION WORK','REFLECTIVE PROJECT','SPECIAL SYLLABUS INT. ASSESSMENT')
AND NVL(ccr.withdrawn,'N') = 'N'
AND ccr.mark_status != 'COMPLETE'
AND EXISTS
(SELECT 1
FROM school s
WHERE s.school_code = ccr.assessment_school
AND s.training_school = 'N'
WHERE mark_status != 'COMPLETE';One thing you can test quickly is to put the function call in it's own select ...from dual.
This might make a difference.
However, only you can check this, I don't have your tables or data.
So, what happens if you use:
paper_code,
cand_lang,
(select mark_entry.get_ia_entry_status(:v_year, :v_month, assessment_school, subject_option, lvl, cand_lang, component, paper_code) from dual ) AS mark_status
FROM
(SELECT DISTINCT ccr.assessment_school, --<< is the DISTINCT really needed?
ccr.subject,
ccr.subject_option,
...Also, try to find out the purpose of that above DISTINCT, is it really needed or is there some join missing? -
Using round off function in where clause
Hi All,
I'm trying to use round off function in where clause, I seek help in completing this script.
WITH CR_Details AS
(Select
request_id,
parent_request_id,
fcpt.user_concurrent_program_name Request_Name, phase_code, status_code,
round((fcr.actual_completion_date - fcr.actual_start_date),3) * 24 * 60 as Run_Time,
round(avg(round(to_number(actual_start_date - fcr.requested_start_date),3) * 1440),2) wait_time,
fu.User_Name Requestor,
fcr.argument_text parameters,
to_char (fcr.requested_start_date, 'MM/DD HH24:mi:SS') requested_start,
to_char(actual_start_date, 'MM/DD/YY HH24:mi:SS') ACT_START,
to_char(actual_completion_date, 'MM/DD/YY HH24:mi:SS') ACT_COMP,
fcr.completion_text
From
apps.fnd_concurrent_requests fcr,
apps.fnd_concurrent_programs fcp,
apps.fnd_concurrent_programs_tl fcpt,
apps.fnd_user fu
Where 1=1
and fcr.concurrent_program_id = fcp.concurrent_program_id
and fcp.concurrent_program_id = fcpt.concurrent_program_id
and fcr.program_application_id = fcp.application_id
and fcp.application_id = fcpt.application_id
and fcr.requested_by = fu.user_id
and fcpt.language = 'US'
and fcr.actual_start_date like sysdate )
select crd.*
from CR_Details crd
where Run_time <> '0'
AND wait_time <> '0'
GROUP BY
crd.request_id,
crd.parent_request_id,
crd.fcpt.user_concurrent_program_name,
crd.requested_start_date,
crd.User_Name,
crd.argument_text,
crd.actual_completion_date,
crd.actual_start_date,
crd.phase_code,
crd.status_code,
crd.resubmit_interval,
crd.completion_text,
crd.resubmit_interval,
crd.resubmit_interval_unit_code,
crd.description
Not sure about the GROUPBY function referencing the "crd." .Hi,
The best thing for you to do is start over. Start as small as possible, then take baby steps.
Pick one of the tables; fcr perhaps, and write a query that just uses that table, like this:
SELECT *
FROM apps.fnd_concurrent_requests fcr
WHERE fcr.actual_start_date >= TRUNC (SYSDATE)
AND fcr.actual_start_dt < TRUNC (SYSDATE) + 1
;(I think this is what you meant to do when you said "... LIKE SYSDATE".)
Make sure this little query gets credible results. When that tiny query is working perfectly, add another line or two. You can cut and paste code from what you posted, if that helps you.
If you get stuck, post the last version of your code that worked perfectly, and the latest version (only a line or two bigger) that has the problem. Describe what the problem is. If you get an error, post the complete error message. In any event, post CREATE TABLE and INSERT statements for all the tables and columns needed to run the query, and the results you want to get from that query.
When you post any code, format it, so that how the code looks on the screen gives some clues about how it is working.
When you post any formatted text on this site, type these 6 characters:
\(small letters only, inside curly brackets) before and after each section of formatted text, to preserve spacing.
If you going to use the AVG function in the sub-query, then you probably need to do a GROUP BY in the sub-query.
If you're not using any aggregate functions (like AVG) in the main query, then you probably don't want to do a GROUP BY in the main query.
I know this is a lot of work. I'm sorry. If there was an easier way, I wouldn't ask you to do all this. -
i insert the below rows in a table cash_book.
PRJ_CODE PRJ_NAME
1203 SHIFA
1203 SHIFA
1203 SHIFA
1202 FATIMA
1202 FATIMA
1203 SHIFA
if i select 1202 code then return 1202 code rows, if i select 1203 then returns 1203 code rows, if i select other than both values then returns all rows. how can i define in one query with use (case or decode function) in where clause ??perhaps something like this:
create table test
as
select 1200 + rownum prj_code
from dual
connect by level <= 10;
select * from test;
PRJ_CODE
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
var v_PRJ_CODE number
exec :v_PRJ_CODE := 1200;
select *
from test
where PRJ_CODE = :v_PRJ_CODE
or 1 = case when :v_PRJ_CODE in (1202, 1203) then 0 else 1 end;
PRJ_CODE
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
exec :v_PRJ_CODE := 1203;
select *
from test
where PRJ_CODE = :v_PRJ_CODE
or 1 = case when :v_PRJ_CODE in (1202, 1203) then 0 else 1 end;
PRJ_CODE
1203Regards
Martin -
How can we use DECODE function in where clause.
Hi Guys,
I have to use DECODE function in where clause.
like below
select * from tab1,tab2
where a.tab1 = b.tab2
and decode(code, 'a','approved')
in this manner its not accepting?
Can any one help me on this or any other aproach?
Thanks
-LKR>
I am looking for to decode the actual db value something in different for my report.
like if A then Accepted
elseif R then Rejected
elseif D then Denied
these conditions I have to check in where clause.
>
what are you trying to do?
may be you are looking for
select * from tab1,tab2
where a.tab1 = b.tab2
and
(decode(:code, 'A','Accepted') = <table_column>
or
decode(:code, 'R','Rejected') = <table_column>
or
decode(:code, 'D','Denied') = <table_column>
) -
User Defined function in Where clause
DB:- 11.2
Input:- 'ACCOUNTING,SALES'
Output:- ('ACCOUNTING','SALES')
WITH T AS (select 'ACCOUNTING,SALES' str from dual)
select '('||regexp_replace(str,'([[:alpha:]]+)','''\1''')||')' from t /*this works*/I've created a function to use this in a where clause
create or replace function ss(dname varchar2)
return varchar2 is
begin
RETURN '('||regexp_replace(dname,'([[:alpha:]]+)','''\1''')||')';
end;
select ss('ACCOUNTING,SALES') from dual --this worksBut when I am using this function in a where clause result is not coming..any thing i am missing?
select * from dept where dname in ss('ACCOUNTING,SALES') --no rows940838 wrote:
Output:- ('ACCOUNTING','SALES')Wrong. ('ACCOUNTING','SALES') is a list of two strings 'ACCOUNTING' and 'SALES' while your function returns a single string '(''ACCOUNTING'',''SALES'')'.
IN clause requires a comma-separated list of values while your function, again, returns just one value. So query is comparing 'SALES' whith '(''ACCOUNTING'',''SALES'')', not with ('ACCOUNTING','SALES') and obviously no match. What you are trying to do is called dynamic SQL. There are plenty examples on how to use it. But you don't need it. Use nested table or varray. I'll use Oracle supplied varray type sys.OdciVarchar2List:
select *
from dept
where dname in (
select *
from table(sys.OdciVarchar2List('ACCOUNTING','SALES'))
DEPTNO DNAME LOC
10 ACCOUNTING NEW YORK
30 SALES CHICAGO
SQL>SY. -
Calling function in where clause
<BR>
Hi
I receive a string of form '333,444,55R5,B342,A556' as string value which should be passed to condition check to filter records in where clause of query.
to make string form in right format with proper quotes separated i have written one function which does that job
CREATE OR REPLACE FUNCTION DW.F_TASK(P_VAL VARCHAR2) RETURN VARCHAR2 AS
V_VAL VARCHAR2(4000);
V_VAL1 VARCHAR2(4000);
BEGIN
V_VAL1:=REPLACE(P_VAL,',',''',''');
V_VAL:='('||''''||V_VAL1||''''||')';
DBMS_OUTPUT.PUT_LINE(V_VAL);
RETURN V_VAL;
END F_TASK;
When i fire below query it doesnt give me output
SELECT * FROM CONTRACT_TABLE WHERE
CONTRACT_NUMBER IN F_TASK('333,444,55R5,B342,A556');
when i fire below query
SELECT F_TASK('333,444,55R5,B342,A556') FROM DUAL
below is the output
('333','444','55R5','B342','A556')
note: above output holds quotes now.
Issue: when i pass paratmeters directly to funciton then i could see output with brackets but when i use same funciton with parameters iin query i dont see data afer firing the query.. though i have those contract numbers in the table.
Please help how to acquire this
Thanks,
Naren
</BR>You haven't described your problem clearly (see: {message:id=9360002})
However, it sounds like you want a varying IN list, which is also in the FAQ: {message:id=9360009} -
How to pass parameters to function in where clause....
I have a select statement like this
SELECT XX_AIR_TICKET_EMP_BAL(:P2) from dual
is it possible to pass to variable p2 from where clause
like
SELECT XX_AIR_TICKET_EMP_BAL(:P2) from dual
where :p2 = :p1
user can enter only in p1 so that p2 should get passed.
Reson for this wierd requirement:In Oracle apps i cant use bind variable in select clause value set..? please ignore this reason if u are not in oracle apps...
Tell me the solution..
Is there any way...
setting some env variavle aor anything[email protected] wrote:
I have a select statement like this
SELECT XX_AIR_TICKET_EMP_BAL(:P2) from dualWhy a SELECT statement? This calls the SQL engine. The function is PL/SQL. This now needs the SQL engine to context switch to the PL engine. The PL engine runs and returns a value (across memory boundaries) to the SQL engine. The SQL engine now needs to return that value as part of the output from a SQL cursor.
Why do all this? Surely it is a lot easier and better for performance to call the PL engine directly using an anonymous PL block. E.g.
begin
:P3 := XX_AIR_TICKET_EMP_BAL(:P2);
end;
is it possible to pass to variable p2 from where clause
like
SELECT XX_AIR_TICKET_EMP_BAL(:P2) from dual
where :p2 = :p1Why?
This can be done as part of the PL block as follows:
begin
if :P2 = :P1 then
:P3 := XX_AIR_TICKET_EMP_BAL(:P2);
end if;
end;But then why construct conditional statements dynamically?
It would be a lot easier to have a new function that does the condition, e.g.
create or replace function getAirTicket( p1 number, p2 number ) return number is
begin
if p1 = p2 then
return( XX_AIR_TICKET_EMP_BAL(p2) );
else
return( null );
end if;
end; -
Error encounter when calling function in where clause
I have created on e user define function.when i am trying to call in select statement it is working fine but when I try to call in where clause it gives me this
error
The following error has occurred:
ORA-06503: PL/SQL: Function returned without value
ORA-06512: at "KINTANA.COMPARE_DATE", line 33
suggest me possible solution
Thanks ChandaHi,
i am trying to call in select statement it is working fine but when I try to call in >>where clause it gives me this I am suspecting the same function call is working fine in SELECT and not in WHERE clause.
Please have a look:
1 CREATE OR REPLACE FUNCTION f1
2 RETURN NUMBER IS
3 BEGIN
4 return 1;
5 EXCEPTION
6 WHEN OTHERS THEN
7 return -1;
8* END;
SQL>/
Function created.
SQL>
SQL>SELECT f1 FROM DUAL;
F1
1
1 row selected.
SQL>SELECT sysdate FROM dual WHERE 1=f1;
SYSDATE
15-MAY-06
1 row selected.
"afiedt.buf" 10 lines, 140 characters
1 CREATE OR REPLACE FUNCTION f1
2 RETURN NUMBER IS
3 BEGIN
4 NULL;
5 EXCEPTION
6 WHEN OTHERS THEN
7 return -1;
8* END;
9 /
Function created.
SQL>SELECT f1 FROM dual;
SELECT f1 FROM dual
ERROR at line 1:
ORA-06503: PL/SQL: Function returned without value
ORA-06512: at "AVINASHT.F1", line 7
SQL>SELECT sysdate FROM dual where 1=f1;
SELECT sysdate FROM dual where 1=f1
ERROR at line 1:
ORA-06503: PL/SQL: Function returned without value
ORA-06512: at "AVINASHT.F1", line 7
SQL>DECLARE
2 a NUMBER ;
3 BEGIN
4 a := 0;
5 a := f1;
6 END;
7 /
DECLARE
ERROR at line 1:
ORA-06503: PL/SQL: Function returned without value
ORA-06512: at "AVINASHT.F1", line 7
ORA-06512: at line 5It would be better to understand if you post your function and how you are calling.
Regards -
Can you use boolean function in where clause
Hi,
I have a boolean function. Is it possible to use it in where clause of query.
Eg;
is_prime(13) returns boolean
select 1 from dual where is_prime(13)What about something like this
Create or replace function boolret(id number) return boolean as
begin
If id <10 then
return true;
elsif id>10 and id<100 then
return false;
else
return null;
end if;
end;
1 declare
2 id_cat boolean;
3 begin
4 id_cat:= boolret(8);
5 dbms_output.put_line(id_cat);
6* end;
SQL> /
dbms_output.put_line(id_cat);
ERROR at line 5:
ORA-06550: line 5, column 2:
PLS-00306: wrong number or types of arguments in call to 'PUT_LINE'
ORA-06550: line 5, column 2:
PL/SQL: Statement ignored
It seems PL/Sql doesn't have any datatype like Boolean,But it handles Boolean like datatype.
Regards
Raj deep.A -
Functions in where clauses vs. in group-by ... inconsistent?
Hello all.
(assuming Oracle 9.2)
First of all, does anyone know why the Oracle SQL Parser will not allow
us to use the <name>-part of "table.column AS <name>" in where or
group-by clauses?? Is this just being lazy on their part, or is there
an actual reason behind this?
Second, and relating to this I am confused as to how ORACLE handles
group-by clauses with functions. (Or rather I find it a bit
inconsistent.)
a)
select my_func(col1), col2
from a_table
where my_func(col1) = :filter;
==> This will evaluate my_func() two(2) times for every row in the
table.
b)
select my_func(col1), sum(col2)
from a_table
group by my_func(col1);
==> This will NOT evaluate the function twice(2) for every result row,
instead it is EXACTLY the same as when I would write:
c = b)
select col1_func, sum(col2)
from (select my_func(col1) col1_func, col2)
group_by col1_func
Consider also the attached example to further confuse the issue.
Any opinions, pointers, corrections on this are most welcome.
cheers,
Martin
** small example **
CREATE OR REPLACE
PACKAGE TEST_PACKAGE
IS
global_counter NUMBER;
END TEST_PACKAGE;
CREATE OR REPLACE
FUNCTION TEST_PUT(x IN VARCHAR2)
RETURN VARCHAR2 IS
ret VARCHAR2(100) := x || test_package.global_counter;
BEGIN
dbms_output.put_line(ret);
test_package.global_counter := NVL(test_package.global_counter, 0) +
1;
return ret;
END;
-- Test_Put will be evaluated 2 times(!):
select test_put('fn_called') my_string, COUNT(object_name)
from all_objects
where rownum <= 2
group by test_put('fn_called')
-- Test_Put will be evaluated 4 times(!):
select test_put('fn_called') my_string, COUNT(object_name)
from all_objects
where rownum <= 2
group by test_put('fn_call')Hello
Hopefully this will help to explain:
SQL> create or replace package test_package
2 is
3 counter_select number;
4 counter_where number;
5 end;
6 /
Package created.
SQL> create or replace function test_func_select
2 return varchar2
3 is
4 begin
5
6 test_package.counter_select := NVL(test_package.counter_select,0) + 1;
7
8 dbms_output.put_line('test_func_select Call # '||TO_CHAR(test_package.counter_select));
9
10 return 'Call # '||TO_CHAR(test_package.counter_select);
11
12 end;
13 /
Function created.
SQL>
SQL> create or replace function test_func_where
2 return varchar2
3 is
4 begin
5
6 test_package.counter_where := NVL(test_package.counter_where,0) + 1;
7
8 dbms_output.put_line('test_func_where Call # '||TO_CHAR(test_package.counter_where));
9
10 return 'Call # '||TO_CHAR(test_package.counter_where);
11
12 end;
13 /
Function created.
SQL> set serveroutput on
SQL>
SQL> SELECT
2 test_func_select,
3 count(*)
4 FROM
5 dt_test_tab
6 WHERE
7 rownum <=2
8 GROUP BY
9 test_func_select
10 /
TEST_FUNC_SELECT COUNT(*)
Call # 2 1
Call # 1 1
test_func_select Call # 1
test_func_select Call # 2
SQL> exec test_package.counter_select:=NULL;
PL/SQL procedure successfully completed.
SQL> SELECT
2 test_func_select
3 FROM
4 dt_test_tab
5 WHERE
6 rownum <=2
7 AND
8 test_func_where LIKE 'Call #%'
9 /
TEST_FUNC_SELECT
Call # 1
Call # 2
test_func_where Call # 1
test_func_select Call # 1
test_func_select Call # 2
SQL>
SQL> create or replace function test_func_select(av_param in varchar2)
2 return varchar2
3 is
4 begin
5
6 test_package.counter_select := NVL(test_package.counter_select,0) + 1;
7
8 dbms_output.put_line('test_func_select Call # '||TO_CHAR(test_package.counter_select));
9
10 return 'Call # '||TO_CHAR(test_package.counter_select);
11
12 end;
13 /
Function created.
SQL>
SQL> create or replace function test_func_where(av_param in varchar2)
2 return varchar2
3 is
4 begin
5
6 test_package.counter_where := NVL(test_package.counter_where,0) + 1;
7
8 dbms_output.put_line('test_func_where Call # '||TO_CHAR(test_package.counter_where));
9
10 return 'Call # '||TO_CHAR(test_package.counter_where);
11
12 end;
13 /
Function created.
SQL> exec test_package.counter_select:=NULL;
PL/SQL procedure successfully completed.
SQL>
SQL> SELECT
2 test_func_select(object_name) test_func_select,
3 count(*)
4 FROM
5 dt_test_tab
6 WHERE
7 rownum <=2
8 GROUP BY
9 test_func_select(object_name)
10 /
TEST_FUNC_SELECT COUNT(*)
Call # 2 1
Call # 1 1
test_func_select Call # 1
test_func_select Call # 2
SQL> exec test_package.counter_select:=NULL;
PL/SQL procedure successfully completed.
SQL> exec test_package.counter_where:=NULL;
PL/SQL procedure successfully completed.
SQL> SELECT
2 test_func_select(object_name) test_func_select
3 FROM
4 dt_test_tab
5 WHERE
6 rownum <=2
7 AND
8 test_func_where(object_name) LIKE 'Call #%'
9 /
TEST_FUNC_SELECT
Call # 1
Call # 2
test_func_where Call # 1
test_func_select Call # 1
test_func_where Call # 2
test_func_select Call # 2In the fist example, oracle only has to call the function once to satisfy the predicate as it is not technically being applied to the table. There could be 1million rows but if the function did not return a string in the form Call #, none of the result set would be materialised as the predicate had failed. In the second example, the predicate is being applied to the table as we are passing a column from the result set to the function. This means that the where clause function has to be called once for every row in the result set.
HTH
David
Maybe you are looking for
-
Video streaming from a phone to a DLNA TV via a Ho...
The Network: I have a Home Hub 2b ( Software version 4.7.5.1.83.2.11.2.6 (Type B) ) running on Infinity 2. The router is set for b/g/n working. I have two devices, one a netbook PC set for 'n' working and this connects at 54Mbps at best. The other a
-
I have my mail set to retrieve data manually. When I retrieve mail, I get a popup box for each and every e-mail message asking if I want to view or cancel and must either view or cancel each one before I can use other apps on the ipad. How can I turn
-
How to display UDT/UDF in XL Reporter
Hi, Please guide how to display user defined tables and user defined fields in XL Reporter. My version is SB1 2005A. Thanks. rgds ERIC
-
Trying to post images to Facebook from within Lightroom
I know that this will work, but unfortunately I have not been able to get this to work, and after spending nearly 3 hours with technical support, I am no closer than when I started the call. I get the following error message This content is currently
-
Everything won't fit on the disk...do I need to change settings?
Hey, I am working on a project that I edited in FCP 5.0 that is approx. 2 hrs long. I would like that video plus a 40 picture slideshow and a scene selection on a DVD. I have done this before and it has fit on a single non dual layer disk. When expor