Decode function in where clause
i am developing an sql code that includes decode keyword and in keyword :
SELECT
NAME
FROM T
WHERE NO_ID IN
DECODE ( var,
1,1,
2,(SELECT ID FROM A))
when, var variable is equal to 2, there will be an error :
ora-14027 single row subquery returns more than one row.
how can i fix it?
Hi,
The answer to "how can i fix it?" depends on what you want to do. First explain that, and someone will help you.
For example, "If var = 1, then I want to test if no_id is 1. If var = 2, then I want to see if no_id is equal to any id in table a."
If that happens to be the problem:
WHERE ( var = 1
AND no_id = 1
OR ( var = 2
AND no_id IN (SELECT id FROM a)
)
Similar Messages
-
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>
) -
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 -
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.. -
Problem with DECODE block in WHERE clause
Hi,
I'm facing problem with DECODE statement. I just simulated my problem in the simple way as follows. If I execute this following query, I should get "hello", but I'm not getting anything (ZERO rows returned).
SELECT 'hello' FROM DUAL
WHERE 'sample1' in (DECODE(1, 1, '''sample1'', ''sample2'', ''sample3''',
2, '''sample4'', ''sample5'', ''sample6'''
I think some problem is there in my WHERE clause.
But When I'm exeucting the following query as a seperate query, then I'm getting the value of DECODE block properly, but didn;t understnad why its not returning the same way when I'm putting the same DECODE statement in WHERE clause.
SELECT DECODE(1, 1, '''sample1'', ''sample2'', ''sample3''',
2, '''sample4'', ''sample5'', ''sample6'''
FROM DUAL;
Please help me to get out of this problem. Thank you so much in advance.
Thanks,
Ramji.The value returned by SELECT DECODE(1, 1, '''sample1'', ''sample2'', ''sample3''',2, '''sample4'', ''sample5'', ''sample6''') FROM DUAL;
'sample1', 'sample2', 'sample3' is a single string. Consider it x.
SELECT 'hello' FROM DUAL WHERE 'sample1' in ( DECODE(1, 1, '''sample1'', ''sample2'', ''sample3''',2, '''sample4'', ''sample5'', ''sample6'''));
is like SELECT 'hello' FROM DUAL WHERE 'sample1' in ('x');
or
SELECT 'hello' FROM DUAL WHERE 'sample1' in ('''sample1'', ''sample2'', ''sample3''') and not
SELECT 'hello' FROM DUAL WHERE 'sample1' in ('sample1', 'sample2', 'sample3');
For this same reason SELECT 'hello' FROM DUAL WHERE 'sample1' in (select '''sample1'', ''sample2'', ''sample3''' from dual);
also does'nt work.
Please use INSTR to find whether 'sample1' exists in the string 'sample1', 'sample2', 'sample3'. -
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. -
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.
;) -
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 -
Decode/Case in Where clause
Hello,
We are experiencing an issue with a Select statement that uses Decode in the Where clause. Specifically, it seems to be ignoring a nested Decode and just returning the default value. We have another nested decode that works fine, though.
A member of our team mentioned that he believed there was an issue with using Decode and Case statements inside of a where clause within HTML DB...Is this correct? If it is, is there a workaround? Since the nested Decode works elsewhere in this statement, that doesn't seem right.
My select statement looks like:
SELECT
SUBSTR(OBOB.OBOB_CNAME, 0, 30) d,
OBOB.OBOB_UID r
FROM
ISR_OBOB_OBJECT OBOB,
ISR_OBAF_OBJECT_AFFILIATION OBAF,
ISR.ISR_OBSD_SDR OBSD
WHERE
OBOB.OBOB_UID = OBSD.OBOB_UID AND
OBOB.OBOB_UID = OBAF.OBOB_B_UID AND
/*If Personal radio button is selected, displays all SDRs associated with user.
If All is selected, displays all SDRs associated with IS group selected from drop down list
or every SDR.
OBAF.OBOB_A_UID = DECODE(:P1_DISPLAY_ALL,
'Personal', :F101_APP_USER_UID,
/*This is the decode statement that it seems to ignore. If ALL is selected, the query should see if a group has
has been selected from a drop down list that appears when the ALL button is chosen. If a group is selected
(the item isn't 0), only SDRs for that group should be shown. Otherwise, all SDRs for every group should display.
'ALL', DECODE(:P1_SEARCH_IS_SUPPORT_GROUP, 0, OBAF.OBOB_A_UID, :P1_SEARCH_IS_SUPPORT_GROUP),
OBAF.OBOB_A_UID) AND
/*If Personal radio button is selected, display SDRs where user is the Primary assignee.
OBAF.OBAT_UID = DECODE(:P1_DISPLAY_ALL, 'Personal', (select OBAT_UID from ISR_OBAT_OBJ_AFFIL_TYPE WHERE OBAT_APP_REF = 'SDR_PRIMARY'), OBAF.OBAT_UID) AND
/*If a SDR Status (open, completed, on hold, not started...) is selected, only display the SDRs with that status.
OBSD.KTTR_STATUS_UID = DECODE(:P1_ISR_STATUS_UID, 0, OBSD.KTTR_STATUS_UID, :P1_ISR_STATUS_UID) AND
/*If SDR_History textbox is Null, or Open, Not Started, or On Hold SDR status has been selected, then all SDRs with
a create date between today and 99999 months ago will display. Otherwise, only SDRs with a create date between
today and however many months are in the textbox will display (i.e. Completed SDRs created in the past 6 months.)
MONTHS_BETWEEN(sysdate, OBSD.OBSD_CREATE_DATE) <= DECODE(:P1_SDR_HISTORY, NULL, 99999, DECODE(:P1_ISR_STATUS_UID,
(select KTTR_UID from ISR_KTTR_TRANSLATION where KTTR_APP_REF = 'SD_STAT_OPEN'), 99999,
(select KTTR_UID from ISR_KTTR_TRANSLATION where KTTR_APP_REF = 'SD_STAT_NOT_STA'), 99999,
(select KTTR_UID from ISR_KTTR_TRANSLATION where KTTR_APP_REF = 'SD_STAT_HOLD'), 99999,
:P1_SDR_HISTORY))
/*Alphabetical order
Order by
dWe originally wrote this as a PL/SQL statement that returned a query string since most of the where clause is dependent on items the user may or may not select, but we have moved the query into a multiselect list, which only seems to allow SQL Queries.
Any help or advice would be appreciated.
Thanks,
ScottScott: Did you try running that SQL statement in SQL Workshop in Apex? You can run it as it is, it will popup a window asking you to enter values for the bind variables.
JAC73: I don't think an IN clause doesn't work that way, you need a actual SQL sub-query, not an expression from a DECODE/CASE statement. Search this site for str2tbl and see Tom's excellent discussion at
http://asktom.oracle.com/pls/ask/f?p=4950:8:::::F4950_P8_DISPLAYID:110612348061 -
Function in where clause is executed and returns null instead a valid value
Hi all
i have a strange problem.
There is a access-application where i have a pass-through-sql.
This sql is fetching a foreign exchange rate from a history table which holds this rates for every day and i'm going to fetch the rate for the last day of the last month.
Example of the fraction which does not work and which i executed directly on the DB, Oracle 11.2.0.3.0:
select val
,last_day(add_months((trunc(sysdate)+3),-1)) tag
from k.obj_ts_hist th
where obj_id = 2660
and eff_date = last_day(add_months((trunc(sysdate)+3),-1))
--and eff_date = '01-mar-2013'
eff_date on table k.obj_ts_hist is defined as date.
The function last_day in the where clause leads to null for both values in the select (val and tag).
If i use eff_date = '01-mar-2013' it's all ok, i get the rigth values.
I tested some combinations of the clause, e.g.
eff_date = to_date(to_char(last_day(add_months((trunc(sysdate)+3),-1)),'YYYYMMDD'),'YYYYMMDD')
or
to_char(eff_date,'YYYYMMDD') = to_char(last_day(add_months((trunc(sysdate)+3),-1)),'YYYYMMDD') , etc., but all of them do not work.
Also i tested the clause with select ... from dual, e.g.
select eff_date from
select last_day(add_months((trunc(sysdate)+3),-1)) eff_date from dual
where eff_date = last_day(add_months((trunc(sysdate)+3),-1))
This work's !
A cross check on Oracle 9.2.0.8.0: it works as expected !
Thanks in advance for your effort.
Regards, Konrada little simulation of your formula
select the_date,last_day(add_months((trunc(the_date) + 3),-1)) eff_date
from (select to_date('20130224','yyyymmdd') + level - 1 the_date
from dual
connect by level <= 7
)reveals you might have been querrying future rates
THE_DATE EFF_DATE
24.02.2013 31.01.2013
25.02.2013 31.01.2013
26.02.2013 28.02.2013 /* future date */
27.02.2013 28.02.2013 /* future date */
28.02.2013 28.02.2013 /* current date */
01.03.2013 28.02.2013
02.03.2013 28.02.2013Regards
Etbin -
Date functions in WHERE clause? HELP
The following two queries are identical except for how I supply the date values in the where clause, yet the first query using the a custom my_date function runs 30x slower than the one using the TO_DATE() function. Both return DATE types...any reason for the difference?
SELECT * from outcomes
WHERE start_time >=fn_my_date('START_MONTH')
AND start_time < fn_my_date('END_MONTH')+1
-- This runs 30x faster--
SELECT * from outcomes
WHERE start_time >=TO_DATE('08/01/2001','MM/DD/YYYY')
AND start_time < TO_DATE('08/31/2001','MM/DD/YYYY')+1
On the flip side, I've also experienced queries running slower using the TO_DATE() function vs the LAST_DAY(sysdate) for equivalenet dates.
nullI haven't seen the message coming up when using LENGTH or SUBSTR, but every time I connect to a database or attempt to change my preferences (including the "NLS Parameters: Comp" preference), this appears.
You are attempting to set the preference you should be to switch this from ANSI to something else, but SQL Developer is ignoring the preference setting (which I think is a bug).
A way to set the NLS_COMP to something else is to use something like "alter session set nls_comp = BINARY;". Note that changing any preference after that appears to overwrite this and you need to do this for each new connection you start. -
Error when using record group type as param in a function in where clause
Hi folks.
I have a record type defined in a packages specification. I have to use this record as parameter to call a function. I am able to call the function if as return its value to a string variable. However, the function should be called into a query to compare the returned value and this code is not compiled.
The code is below:
DECLARE
l_line_group_rec INL_CUSTOM_PUB.inl_ship_headers_rec;
l_name VARCHAR2(100);
l_count NUMBER;
BEGIN
l_name := INL_GET_PARTY_SITE_NAME(l_line_group_rec); -- Compiling successfully
SELECT COUNT(1)
INTO l_count
FROM dual
WHERE INL_GET_PARTY_SITE_NAME(l_line_group_rec) = 'Allied Manufacturing'; --- Error when compiling
END;
I got the error: PLS-00306: wrong number or types of arguments in call to 'INL_GET_PARTY_SITE_NAME'
I would like to know if there is any restriction in using record type as parameter in where clauses or if there is another way to do it.
Thanks in advanceHi.
The definition of INL_GET_PARTY_SITE_NAME:
FUNCTION INL_GET_PARTY_SITE_NAME(p_line_group_rec INL_CUSTOM_PUB.inl_ship_headers_rec) RETURN VARCHAR2 IS
l_party_site_name VARCHAR2(100);
BEGIN
l_party_site_name := 'Allied Manufacturing';
URN l_party_site_name;
END INL_GET_PARTY_SITE_NAME;
Thanks. -
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.
Maybe you are looking for
-
NetBeans acting weird; A list with different components
Hi, I'm writing an application that is using swing components and have some questions (my IDE is NetBeans 6.1): 1. I have some forms with JTextFields, JButtons and JLabels. I have a very annoying problem in the NetBeans, that sometimes if I change th
-
Getting a character at a given index in a String and returing as a String
Hello, How do I simply grab one character in a string and return it as a string? I saw the substring() method but it does not like when I invoke: String test = "abcd"; test = test.substring(0,0); **Above produces a runetime error. ***I need something
-
I have a 3 year old iMac intel processor. Apple Care ran out in April (interestingly, the long thread about the problems I had getting help from Apple Care has been removed). The past month a new problem has started. Airport seems to work for a while
-
Column width issue in SharePoint 2010 Reports using SSRS webpart
Dear sir, We need to adjust column width for output of reports. We are using SSRS webpart to generate reports. It is taking unexpected column width. We show that dynamically we cannot set the column width but we are passing the query statically is th
-
jag får felkod 41 när jag laddar hem uppgradering till PS CC, orsak? I got the error code 41 while downloading upgrades to PS CC, why?