Simple conditional SQL WHERE Clause with two Subselects
Hi SQL Experts,
I need some quick help with a query.
It is a ' select ' for a data source object repository phyiscal table OBI.
So, I can't put in PL/SQL or in stored procedures. I just need
have two conditions / selects different according to the user's role (this information comes
of the session).
The above does not work:
-ORA00905. 00000 - 'lack the key word'
SELECT OFFICENO FROM orgunit
WHERE
BOX WHEN "SESSION_VARIABLE' LIKE '% globalmanager %' THEN
ASSIGNEDOFFICES =
(
SELECT DISTINCT ASSIGNEDOFFICES
FROM USERSTABLE INNER JOIN orgunit WE
OrgUnit. KEY = USERSTABLE. OFFICE
WHERE USERSTABLE. USERNAME ='VALUEOF (NQ_SESSION. THE USER)"
)
ON THE OTHER
OFFICENO =
(
SELECT DISTINCT USERSTABLE OFFICENO
INNER JOIN orgunit WE
OrgUnit. KEY = USERSTABLE. OFFICE
WHERE USERSTABLE. USERNAME ='VALUEOF (NQ_SESSION. THE USER)"
)
END;
Can anyone help?
Hello
I can't tell what you want to do by looking at the code that do not do. Maybe:
SELECT officeno
For orgunit
WHERE (session_variable LIKE '% globalmanager %'
AND IN assignedofficies
(
SELECT assignedoffices
UserTable U1
JOIN orgunit o1 ON o1.officekey = u1.officekey
WHERE u1.username = ' VALUEOF (NQ_SESSION. THE USER)"
)
)
OR (NVL (session_variable
, '?'
) NOT LIKE '% globalmanager % '.
AND IN officeno
(
SELECT officeno
Of u2 usertable
JOIN orgunit o2 ON o2.officekey = u2.officekey
WHERE u2.username = ' VALUEOF (NQ_SESSION. THE USER)"
)
)
;
There might be a simpler and more efficient way in function your tables and your limit.
The condition u2.username = ' VALUEOF (NQ_SESSION. The USER) "almost certainly not what you really want.
.
Whenever you have any questions, post a small example data (CREATE TABLE and only relevant columns, INSERT statements) for all of the tables involved and also publish outcomes from these data.
Explain, using specific examples, how you get these results from these data.
Always say what version of Oracle you are using (for example, 11.2.0.2.0).
See the FAQ forum: https://forums.oracle.com/message/9362002#9362002
Tags: Database
Similar Questions
-
where clause with reg_exp
Hello
My query is...
The string is "1,2,3"...
output must be '1', ' 2 ', ' 3',
Please help me...!
Concerning
SA
The guru gave the solution...
But, I have to use this condition in Where clause on my request. If I put in which the value of the clause does not appear. Any help on that...! Please, I beg you.select REGEXP_REPLACE('1, 2, 3', '([0-9]+)', '''\1''') from dual;
Concerning
SAHello
Query: SELECT "' | REPLACE ('1,2,3',',' "',"'). "' val FROM DUAL;
will convert '1,2,3' string '1', ' 2 ', 3'.
Run the sub queries first and then run a select statement.
CREATE TABLE sample_table
(
col_a VARCHAR2 (3)
);INSERT INTO sample_table
VALUES ('1');INSERT INTO sample_table
VALUES ('2');INSERT INTO sample_table
VALUES ('3');INSERT INTO sample_table
VALUES ('4');INSERT INTO sample_table
VALUES ('5');COMMIT;
SELECT col_a
OF sample_table
WHERE INSTR ((SELECT ''' ||)) REPLACE ('1,2,3',',' "',"'). "' val
THE DOUBLE).
col_a
) > 0;The select statement above will give you the desired result of "sample_table" as below.
COL_A
1
2
3Kind regards
Big Boss -
Passing the value of the where clause with the page
Dear friends,
I have a requirement like when I select a selection list value I should pass this value to sql query where clause without submitting the page
ex I have a select like: P1_Dept guess I selects the value 10 in this
then I have a query select * from emp where deptno =: P1_Dept.
DB. ORACLE 11G
APEX 4.1.1.00.23
is this possible? can someone help me please in this topic
Thanks and greetings
Vballeda
Suppose we have the selection list with the name P1_DEPT and query for report
select * from emp where deptno = :P1_DEPT
We create dynamic Action on the evolution of the P1_DEPT point. We will need two real actions:
1-> set value action
Set the Type - > body of the PL/SQL function
The function of body - > return 1;
Page item to submit-> P1_DEPT
Change to delete-> Yes event
Selecttion Type-> trigger element
2. action-> Refresh
Selecttion Type-> region
Region-> your region of report
-
Setting of outsourcing work is not for a SQL Where clause
Im trying to outsource the WHERE SQL clause of a snapshot data (connecting to Siebel DB) and specify where clause in the run profile that does not work.
Snapshot of research: Select the name of siebel.s_org_ext
Parameter of outsourcing: where_clause_sql
Run the content of the profile:
phase. Phase1.snapshot.clt.where_clause_sql = name = "ABC0009".
#phase. Phase1.snapshot.clt.snapshot_sql = select name from siebel.s_org_ext where name = 'ABC0009 '.
The above parameter retrieves all the records in the table. Below the profile execution retrieves just this record that seems to work fine.
Run the content of the profile:
phase. Phase1.snapshot.clt.snapshot_sql = select name from siebel.s_org_ext where name = 'ABC0009 '.
I want to outsource only where clause as there are many SQL and they are huge to maintain in the run profile.
I have attached a doco with screenshots that will help to understand more.
Hello
You must BE
-Choose "Select table or view" in the table of the snapshot Wizard selection page
&
-Use outsourced where clause
OR
-Choose "SQL" in the snapshot table selection wizard page.
&
-Outsourced use SQL snapshot
You can't mix and match options.
Kind regards
Nick
-
Exclude duplicates on SQL where clause statement
Hello!
Are a few posibilities to exclude duplicates do not using aggregate sql in a main select functions?
Priview SQL statement
SELECT * FROM ( select id,hin_id,name,code,valid_date_from,valid_date_to from diaries ) QRSLT WHERE (hin_id = (SELECT NVL(historic_id,id)FROM tutions where id=/*???*/ 59615)) AND NVL(valid_date_to,to_date('22.12.2999','dd.mm.yyyy')) <= (SELECT NVL(valid_date_to,to_date('22.12.2999','dd.mm.yyyy'))FROM tutions where id= /*???*/ 59615) AND trunc(valid_date_from) >=(SELECT trunc(valid_date_from)FROM tutions where id= /*???*/ 59615) ;
The result
ID HIN_ID NAME CODE VALID_DATE_TO VALID_DATE
50512 59564 RE YOU 01 07.06.2013 16:32:15 07.06.2013 16:33:28 50513 59564 TT2 02 07.06.2013 16:33:23 07.06.2013 16:33:28 50515 59564 TT2 02 07.06.2013 16:33:28 07.06.2013 16:34:42 50516 59564 STEM 03 07.06.2013 16:34:37 07.06.2013 16:34:42 VALID_DATE_TO & VALID_DATE_FROM information AND
07.06.2013 16:34:42 15.07.2013 10:33:23 In this case, I had doubles of the TT2 50513 entry in a statement identifier select main cant use agregate functions are still possible to exclude this result value by changing only the QLRST a WHERE clause (TRUNC must be here)
THANKS FOR ANY ADVICE!
FDA
Try this,
WITH QRSLT AS (SELECT id, hin_id, name, code, valid_date_from, valid_date_to FROM diaries) SELECT * FROM QRSLT A WHERE (A.hin_id = (SELECT NVL (historic_id, id) FROM tutions WHERE id = /*???*/ 59615)) AND NVL (A.valid_date_to, TO_DATE ('22.12.2999', 'dd.mm.yyyy')) <= (SELECT NVL (valid_date_to, TO_DATE ('22.12.2999', 'dd.mm.yyyy')) FROM tutions WHERE id =/*???*/ 59615) AND TRUNC (A.valid_date_from) >= (SELECT TRUNC (valid_date_from) FROM tutions WHERE id = /*???*/ 59615) AND A.valid_date_from = (SELECT MAX (B.valid_date_from) FROM QRSLT B WHERE A.Name = B.Name AND A.Code = B.Code AND A.hin_id = B.hin_id)
-
Using the Case statement in Where clause with operator
Hi all
I'm doing the following work (this is just a simple version of what I'll eventually need):
Sorry, I forgot how to use the code tags...
and li. MAJOR_ACCT in case
When: prompt = 'Energy' then ('9320906 ', ' 9321471')
end
Problem is that I get a missing closing parenthesis error.
Wouldn't - that evaluate against a value(as below) it works fine:
and li. MAJOR_ACCT in case
When: prompt = 'Energy' then ('9320906')
end
Any thoughts? Is it possible to use a box (or decode) in an In clause with multiple values? I tried to use decode as well and get the same results.
Thank you.
Darren.What:
and ( case when :prompt = 'Energy' and li.MAJOR_ACCT in ('9320906', '9321471') then 1 when :prompt = 'Vehicle' and li.MAJOR_ACCT in ('9812180', '9812320') then 1 when :prompt = 'Meals' and li.MAJOR_ACCT in ('983120', '983452') then 1 end ) = 1
-
dynamic logic in SQL WHERE clause based on the value of the ELEMENT
Hello
I have a report based on the following SQL query.
Thank youselect dept_no, dept_name, dept_loc from dept where dept_loc = :P1_DEPT_LOC // If P1_DEPT_LOC is not null, I want the WHERE clause and IF P1_DEPT_LOC is null, then I don't need the WHERE clause. // how can I build this logic in same SQL
Deepak
Published by: Deepak_J on March 11, 2010 16:37where: P1_DEPT_LOC IS NULL or dept_loc =: P1_DEPT_LOC
If dept_loc is not null better would be
where dept_loc = coalesce(:P1_DEPT_LOC,dept_loc)
-
Problem with the creation of date range with PL/SQL WHERE clause
Hello, everyone:
I'm unable to develop and the SQL statement to filter records today and seven days back. My condition is as follows:
I think I'm to mess with the (to_char (ALM_OG_ACTIVITY_DATE, ' mm/dd/yyyy ' ")) statement.from wsualumni.wsu_online_giving_table --where ALM_OG_ACTIVITY_DATE >= ALM_OG_ACTIVITY_DATE - 7 where ALM_OG_ACTIVITY_DATE >= SYSDATE - 7 and ALM_OG_CAMPAIGN_CODE = 'MED' OR ALM_OG_CAMPAIGN_CODE = 'MED1';
The actual code is below to:
Resultsset serveroutput ON SIZE 1000000 set heading off set feedback off set trimspool off set echo off set pagesize 0 DECLARE v_data_line_hdr varchar2(1000); v_data_file varchar2(80); v_sch_code varchar2(10); v_instance_name varchar2(10); ws_path payroll.pybutfl.pybutfl_utl_file_path%TYPE; v_data_line VARCHAR2 (4000) := NULL; fhandle_o UTL_FILE.file_type; v_line_count NUMBER := 0; v_selected_count NUMBER := 0; v_error_count NUMBER := 0; v_written_count NUMBER := 0; v_error_text VARCHAR2 (50) := ' Unable to write the line. '; v_errm VARCHAR2 (255); v_sqlerrm VARCHAR2 (255); CURSOR C1 IS select RTRIM ( ALM_OG_ID ||'|'|| NULL ||'|'|| (to_char(ALM_OG_AMOUNT, '999,999.99')) ||'|'|| 'Cash' ||'|'|| 'Credit Card' ||'|'|| (to_char(ALM_OG_ACTIVITY_DATE, 'mm/dd/yyyy')) ||'|'|| ALM_OG_ACCI_CODE ||'|'|| 'On-Line Giving' ||'|'|| 'On-Line giving' ||'|'|| ALM_OG_HONOR_MEM_NAME ||'|'|| NULL ||'|'|| 'Do not post' ||'|'|| 'StandardThankYou' ||'|'|| 'Not Acknowledged' ||'|'|| 'Do not receipt' ||'|'|| NULL ||'|'|| 'Banner Gift Number' ||'|'|| ALM_OG_BANNER_GIFT_NO ||'.'|| ALM_OG_ACCI_CODE ||'|'|| (to_char(ALM_OG_ACTIVITY_DATE, 'mm/dd/yyyy')) ||'|'|| NULL ||'|'|| 'Web ID' ||'|'|| ALM_OG_WEBID ||'|'|| NULL ||'|'|| 'Source' ||'|'|| ALM_OG_CAMPAIGN_CODE ||'|'|| 'On-Line Giving' ) data_line from wsualumni.wsu_online_giving_table --where ALM_OG_ACTIVITY_DATE >= ALM_OG_ACTIVITY_DATE - 7 where ALM_OG_ACTIVITY_DATE >= SYSDATE - 7 and ALM_OG_CAMPAIGN_CODE = 'MED' OR ALM_OG_CAMPAIGN_CODE = 'MED1'; CURSOR C2 IS select RTRIM( 'ConsID' ||'|'|| 'GFImpID' ||'|'|| 'GFTAmt' ||'|'|| 'GFType' ||'|'|| 'GFPayMeth' ||'|'|| 'GFDate' ||'|'|| 'FundID' ||'|'|| 'CAMPID' ||'|'|| 'GFAppeal' ||'|'|| 'GfRef' ||'|'|| 'GfPostDate' ||'|'|| 'GfPostStatus' ||'|'|| 'GfltrCode' ||'|'|| 'GfAck' ||'|'|| 'GfRcpt' ||'|'|| 'GfAttrlmpID00' ||'|'|| 'GfAttrCat00' ||'|'|| 'GfAttrdesc00' ||'|'|| 'GfAttrDate00' ||'|'|| 'GfAttrlmpD01' ||'|'|| 'GfAttrCat01' ||'|'|| 'GfAttrdesc01' ||'|'|| 'GfAttrlmpID02' ||'|'|| 'GfAttrCat02' ||'|'|| 'GfAttrdesc02' ||'|'|| 'GfSubType' ) line_header from DUAL; /**********************************************************************/ /* Main Program Processing */ /**********************************************************************/ BEGIN DBMS_OUTPUT.put_line ('Program Started in wsualumni.wsu_online_giving_online'); IF UTL_FILE.is_open (fhandle_o) THEN UTL_FILE.fclose (fhandle_o); END IF; /* Name The File Here */ v_data_file := ('MED_SCH_' || TO_CHAR(sysdate, 'dd-MON-yyyy') || '_OG_DATA.txt'); SELECT RTRIM (pybutfl_utl_file_path) INTO ws_path FROM payroll.pybutfl; fhandle_o := UTL_FILE.fopen (ws_path, v_data_file, 'w'); DBMS_OUTPUT.put_line ('UTLFILE file for this run is: ' || ws_path||'/'||v_data_file); v_written_count := 0; FOR c2_rec IN C2 LOOP BEGIN v_selected_count := v_selected_count + 1; v_data_line_hdr := rtrim(c2_rec.line_header); UTL_FILE.put_line (fhandle_o, v_data_line_hdr); v_written_count := v_written_count + 1; EXCEPTION WHEN OTHERS THEN DBMS_OUTPUT.put_line (v_error_text); v_error_count := v_error_count + 1; END; END LOOP; FOR c1_rec IN C1 LOOP BEGIN v_selected_count := v_selected_count + 1; v_data_line := rtrim(c1_rec.data_line); UTL_FILE.put_line (fhandle_o, v_data_line); v_written_count := v_written_count + 1; EXCEPTION WHEN OTHERS THEN DBMS_OUTPUT.put_line (v_error_text); v_error_count := v_error_count + 1; END; END LOOP; DBMS_OUTPUT.put_line ('Number of Records Selected: ' || v_selected_count); DBMS_OUTPUT.put_line ('Number of Records Written: ' || v_written_count); IF UTL_FILE.is_open (fhandle_o) THEN UTL_FILE.fclose (fhandle_o); END IF; END; /
ConsID|GFImpID|GFTAmt|GFType|GFPayMeth|GFDate|FundID|CAMPID|GFAppeal|GfRef|GfPostDate|GfPostStatus|GfltrCode|GfAck|GfRcpt|GfAttrlmpID00|GfAttrCat00|GfAttrdesc00|GfAttrDate00|GfAttrlmpD01|GfAttrCat01|GfAttrdesc01|GfAttrlmpID02|GfAttrCat02|GfAttrdesc02|GfSubType 000013505|| 20.00|Cash|Credit Card|06/22/2009|221686|On-Line Giving|On-Line giving|||Do not post|StandardThankYou|Not Acknowledged|Do not receipt||Banner Gift Number|1179534.221686|06/22/2009||Web ID|000013505||Source|MED|On-Line Giving 000013505|| 20.00|Cash|Credit Card|06/22/2009|770830|On-Line Giving|On-Line giving|||Do not post|StandardThankYou|Not Acknowledged|Do not receipt||Banner Gift Number|1179534.770830|06/22/2009||Web ID|000013505||Source|MED|On-Line Giving
Hello
The problem is due to the "OR" condition (I did not pay attention to it earlier).
Because of this condition, your query is given beyond 7 days recovery. You need to rewrite the code as:
ALM_OG_CAMPAIGN_CODE in ('MED', 'MED1')
Instead of
and ALM_OG_CAMPAIGN_CODE = 'MED' OR ALM_OG_CAMPAIGN_CODE = 'MED1';
This will do the magic for you.
Concerning
Asif Momen
http://momendba.blogspot.com -
case of condition in where clause
Hello
I am a beginner in SQL, but according to my reading of the manual, this syntax should be acceptable. I'm using application express but tested also in Developer SQL and the conclusion that it fails with an error "invalid relational operator", with the line number pointing to the ELSE clause of the condition, but a number of column pointing to white space.
This is a select statement nested, but that shouldn't matter. The fragment in question is:
Select columns
RES
where res.villaid =: P605_VILLAID
and INSTR (: P604_RES_STATES, res.states). = 0
and (CASE: P604_EXCLUDE_ZERO)
WHEN 'Y' THEN ' res.rate > 0'
ELSE ' res.rate > = 0'
END)
and res. DEPARTDATE >: P605_STARTDATE
and res. ARRIVEDATE < =: P605_ENDDATE.
I hope that this puts ok shaped during the validation. The code is looking for bookings within a range of dates (which works very well when the other conditions are discussed), and should only output offset lines (nights) if the user asks for it in the variable of liaison P604_EXCLUDE_ZERO. There are probably other ways to go about this, but I'm too stubborn to renounce it. Well, not yet anyway.
Thanks and greetings
CSselect some columns from res where res.villaid = :p605_villaid and instr (:p604_res_states, res.states) != 0 and sign (res.rate) >= case when :p604_exclude_zero = 'Y' then 1 else 0 end and res.departdate > :p605_startdate and res.arrivedate <= :p605_enddate
-
Oracle OFA customization list of values (LOV) mapping in Where clause with variables
Hi all
I have a requirement to add the condition of the UOM LOV I don't understand under conditions in LOV for example mcc.inventory_item_id =: 1 what: 1 means? and how the system look at the value in: 1? if I have to add the condition to the middle which number should I use?
SELECT * FROM (SELECT distinct muc.unit_of_measure unit_meas_lookup_code, muc.unit_of_measure_tl unit_meas_lookup_code_tl, muc.description, muc.uom_class, muom.uom_code FROM mtl_uom_conversions_val_v muc, mtl_units_of_measure muom WHERE (muc.uom_class IN (SELECT mcc.to_uom_class CMC mtl_uom_class_conv_val_v WHERE mcc.inventory_item_id =: 1) muc.uom_class = GOLD: 2), AND (muc.item_id =) ((: 3 GOLD muc.item_id = 0) AND muc.unit_of_measure = muom.unit_of_measure) QRSLT WHERE ((UPPER (UNIT_MEAS_LOOKUP_CODE_TL) like UPPER(:4) AND (UNIT_MEAS_LOOKUP_CODE_TL like: 5 OR UNIT_MEAS_LOOKUP_CODE_TL as: 6 OR UNIT_MEAS_LOOKUP_CODE_TL as: 7 OR UNIT_MEAS_LOOKUP_CODE_TL as: 8))) ORDER BY upper (unit_meas_lookup_code)
Concerning
A.S.
Hey A.S.,.
Looking more closely at the image you included, it seems that it is already a custom code, it starts with "Xx". You should see if you have the available custom code.
To answer part of your original question ""mcc.inventory_item_id =: 1 what: 1 means? ' " The ': 1 ' is a variable binding in the SQL code. This value is populated at run time by using the "setWhereClauseParam (Bind number, value). You can see the details of the request and the variable linking using JDeveloper and a double-tap on the View object. Again, this should be in the custom code of the object View 'atco.oracle.apps.po.lov.server.XxDocumentUomBothVo '.
I hope this helps.
Thank you
Tim
-
How to check this condition in where clause
WITH t1 AS (SELECT 1 empno, 'Sun' name,100 deptno, 'M' Gender FROM dual UNION ALL SELECT 2,'Gun',100 deptno, 'F' FROM dual UNION ALL SELECT 3, 'Run',50,'M' FROM dual UNION ALL SELECT 4, 'Nun',75,'F' FROM dual UNION ALL SELECT 5, 'Tun',25,NULL FROM dual) SELECT empno,name,deptno,gender FROM t1; I want to display those dept. data which is having Genders both 'M' and 'F',
You can use two ANDed 'exists' conditions...
... SELECT empno,name,deptno,gender FROM t1 t1o; where exists (select 'x' from t1 t1i where t1o.deptno = t1i.deptno and t1.gender = 'M') and exists (select 'x' from t1 t1i where t1o.deptno = t1i.deptno and t1.gender = 'F')
-
I need account condition in where clause.
Hi all
I have a data
Product ID AMT
1 100 A 1 100 B 1 100 C 1 100 D 2 25 A 2 40 E 2 55 F 3 50 B 3 50 A 3 50 C 3 50 G 4 12 H 4 13 E 4 14 A 4 15 I have I need following output
ID AMT Product 1 100 A 1 100 B 1 100 C 1 100 D 3 50 B 3 50 A 3 50 C 3 50 G
I tried after query, but it does not work
Select
ID,
AMT,
Product
t
Product ID, AMT Group,
having count (distinct ID) = count (distinct AMT)
It returns all the rows.
Help, please
with t as)
SELECT id,
AMT,
product,
County (separate amt) over (partition by id) cnt
of sample_data
)
SELECT id,
AMT,
product
t
where cnt = 1
order by id
/
AMT ID P
---------- ---------- -
1 100 A
1 100 B
1 100 C
1 100 D
3 50
3 50
3 50
3 508 selected lines.
SQL >
SY.
-
case in PL/SQL where clause statement
- Hello
- I have a research procedure where the user can search on the city, street, zip code.
- I need meet the 6 different combinations as I don't know what value the user will pass.
- It should be checked if the user passes the value or not, and then look on values passed.
- But the procedure below is out.it the slightest mistake can be transformed with if-then-else, but case statement seems much cleaner in the code.
- procedure searchaddress (pc_town IN SEARCHADDRESS. CITY % TYPE,
pc_street IN SEARCHADDRESS. TYPICAL STREET %,
pc_postcode IN SEARCHADDRESS. POSTCODE % TYPE,
pResultSet to ref_cursor) as
Start
Open the pResultset for
Select searchaddress_pk from searchaddress
where
case
When pc_town is null then ((street = pc_street) and (ZipCode = pc_postcode))
When pc_street is null then ((town = pc_town) and (ZipCode = pc_postcode))
When pc_postcode is null then ((town = pc_town) and (street = pc_street))
When pc_town is null and pc_street is null then (postal code = pc_postcode)
When pc_street is null and pc_postcode is null then (city = pc_town)
When pc_town is null and pc_postcode is null then (street = pc_street)
end
end searchaddress;
Thank you
CenterB
A basic concept that is important to understand - sliders aren't 'sets of results' (sets of data in memory). A cursor is a series of executable steps (see plans run to cursor). It's like a program. An extraction run the program and output data. In general, which is repeated until the cursor (aka program) is no longer found the corresponding lines.
A ref cursor is a pointer or a handle for a such slider, passed to a caller, allowing the appellant to interface directly with this slider/program.
The slider more effective to create a search would be one without superfluous code and predicates and filters. Consider the following approach - a beefier PL/SQL procedure, do not try and play little tricks with SQL predicates in an attempt to create one (and probably not optimal) SQL.
(not tested/compiled code)
create or replace procedure SearchAddress( town IN SEARCHADDRESS.TOWN%TYPE, street IN SEARCHADDRESS.STREET%TYPE, postcode IN SEARCHADDRESS.POSTCODE%TYPE, refCur out ref_cursor ) is curHandle integer; res integer; searchSQL varchar2(1000); begin -- create base query searchSQL := 'select searchaddress_pk from searchaddress where 1 = 1 '; -- add dynamic predicates as needed if town is not null then searchSQL := searchSQL || 'and town = :town'; end if; if street is not null then searchSQL := searchSQL || ' and street = :street'; end if; if postcode is not null then searchSQL := searchSQL || ' and postcode = :postcode'; end if; -- create a DBMS_SQL cursor curHandle := DBMS_SQL.open_cursor; DBMS_SQL.parse( curHandle, searchSQL, DBMS_SQL.NATIVE ); -- bind the dynamic bind variables added as predicate values if town is not null then DBMS_SQL.Bind_Variable( curHandle, 'town', town ); end if; if street is not null then DBMS_SQL.Bind_Variable( curHandle, 'street', street ); end if; if postcode is not null then DBMS_SQL.Bind_Variable( curHandle, 'postcode', postcode ); end if; -- execute cursor (to create the cursor program) and pass it back as a ref cursor res := DBMS_SQL.Execute( curHandle ); refCur := DBMS_SQL.To_RefCursor( curHandle ); end;
-
Dynamic WHERE Clause with multiple ORs
I need to build a dynamic SQL statement such as the clause WHERE looks / works as follows:
WHERE x LIKE '%1% ' OR LIKE '%2% ' x OR x LIKE '%3%...
I can do the above, no problem, but I wonder if there is a better way?
Thank you
Mark
Hi, Mark,.
You should not need dynamic SQL for that.
For example, if you are still interested in substrings of characters suingle, and you get entry as a unique string called str (e.g. '123' it which means you want to find the rows where x contains '1', '2' or 3'), so you could say:
...
WHERE (x REGEXP_LIKE
, '[' || str || ']'
)
I hope that answers your question.
If not, post a small example data (CREATE TABLE and INSERT statements), a few entries and also post the desired results of each input given the same data.
Explain, using specific examples, how you get these results from these data.
Always say what version of Oracle you are using (for example, 11.2.0.2.0).See the FAQ forum: https://forums.oracle.com/message/9362002#9362002
-
Where clause with XMLExists and join to another table
Hello
We have table as:
drop table xml_tbl;
create table xml_tbl)
whole xml_msg_id
xmltype xml_msg_text
);
insert into xml_tbl values
(1, "< principal > < id > 1 < /ID > < / hand > '");
insert into xml_tbl values-(xml_msg_id, xml_msg_text)
(1, "< principal > < id > 2 < /ID > < / hand > '");
Another table like:
create the table1 Table:
(id1 int);
Insert into Table1 values (2);
Insert into Table1 values (3);
We need to have a view on top of the table xml_tbl where/hand/IDs should only have the values located in id1 column of the Table1 table.
Something like
CREATE OR REPLACE VIEW V_xml_tbl
(
xml_msg_text
)
AS
SELECT T.xml_msg_text
OF xml_tbl T
WHERE (XMLEXISTS)
' declare namespace Namesp1 = "Abc: Set";
Let $Results as XS: Boolean: = fn:exists($p/main/id_in_(Select_id1_from_Table1))-now, here I know that I can't select id1 of
Table 1
return if ($Results) then true() (else)"
PASSAGE T.xml_msg_text AS 'p');
In fact, in the scenario real Table1 will have several IDs and xml_tbl a lot of XML files...
So I'm stuck on how to do it. Help, please.
Thank you...
Published by: user8941550 on November 20, 2012 19:19One of these two:
SQL> select t.xml_msg_text 2 from xml_tbl t 3 where exists ( 4 select null 5 from table1 t1 6 where t1.id1 = xmlcast( 7 xmlquery('/main/id' passing t.xml_msg_text returning content) 8 as integer 9 ) 10 ); XML_MSG_TEXT --------------------------------------------------------------------------------
2 SQL> select t.xml_msg_text 2 from xml_tbl t 3 , xmltable('/main' passing t.xml_msg_text 4 columns id integer path 'id' 5 ) x 6 where exists ( 7 select null 8 from table1 t1 9 where t1.id1 = x.id 10 ); XML_MSG_TEXT --------------------------------------------------------------------------------
2 And a third, using XMLExists:
SQL> select t.xml_msg_text 2 from xml_tbl t 3 where xmlexists ( 4 'fn:collection("oradb:/DEV/TABLE1")/ROW[ID1=$d/main/id]' 5 passing t.xml_msg_text as "d" 6 ); XML_MSG_TEXT ------------------------------------------------------------------------------------------------------------------------
2 The plan is similar to that of the second query above (XMLTable/EXISTS).
Still using XMLExists, a plan similar to the first query (EXISTS, XMLCast, XMLQuery) can be achieved by id of casting to an integer data type:
SQL> select t.xml_msg_text 2 from xml_tbl t 3 where xmlexists ( 4 'fn:collection("oradb:/DEV/TABLE1")/ROW[ID1=xs:int($d/main/id)]' 5 passing t.xml_msg_text as "d" 6 ); XML_MSG_TEXT ------------------------------------------------------------------------------------------------------------------------
2 Check each on your real-world scenario to see that present better performance.
(I would say those involving streaming of assessment)Published by: odie_63 on 5 nov. 2012 12:24
Published by: odie_63 on 5 nov. 2012 12:38
Maybe you are looking for
-
Satellite C50t-A-10J: screw loose around the hinges
Someone had problems with housing screws loosened around the hinges on a laptop via Satellite, and if so do they have suggestions for a solution? I have a C50t-A-10J. Within 4 months from first use hinges fixing screws loose and three is out.First of
-
Programs and the thing of parameters at the bottom of my desktop disappeared. I have to have it turned off. Does anyone know how to turn it on? Thank you! Power Mac G4 (AGP Graphics)
-
I posted this problem once before to http://h30434.www3.hp.com/t5/Printer-All-in-One-Install-Setup-e-g-Windows-8/Help-Cannot-install-soft... and I thought that my problem was resolved, but it was not. So, here I am again. With the 'solution' to the
-
Windows says that my copy is authentic, but update Windows 10 says that it is not
I built my PC myself four years ago and have not had any problems with the copy of Windows 7 Pro that I bought, until I started trying to pass to Windows 10 free. The update of Windows 10 says that I need to activate my copy of Windows 7. However, wh
-
Removal and transfer of files to blackBerry Smartphones
How can I transfer photos from the memory of the device to the press card? Also, is there a way to mass - delete old text messages? Thanks for any help.