several instructions box in where clause
Hello
I'm trying to create report filters using substitution variables in a case statement in a where clause clause. I have several instructions box running on the same column. I don't really know how to write it. Here's what I have so far but I know I'm going in the wrong direction.
where
i.compute_zone =
case
When: P14_zone is NOT NULL
then: P14_zone
of other i.compute_zone
end
AND
i.compute_zone =
case
When: P14_zone_2 is NOT NULL
then: P14_zone_2
other: P14_zone
end
AND
i.compute_zone =
case
When: P14_zone_3 is NOT NULL
then: P14_zone_3
of other i.compute_zone
end
AND
i.compute_zone =
case
When: P14_zone_4 is NOT NULL
then: P14_zone_4
of other i.compute_zone
end
any suggestions?
Thank you
MICAH
Hi, Micah,
User12611868-Oracle wrote:
Hello
I'm trying to create report filters using substitution variables in a case statement in a where clause clause. I have several instructions box running on the same column. I don't really know how to write it. Here's what I have so far but I know I'm going in the wrong direction.
where
i.compute_zone =
case
When: P14_zone is NOT NULL
then: P14_zone
of other i.compute_zone
end
AND
i.compute_zone =
case
When: P14_zone_2 is NOT NULL
then: P14_zone_2
other: P14_zone
end
AND
i.compute_zone =
case
When: P14_zone_3 is NOT NULL
then: P14_zone_3
of other i.compute_zone
end
AND
i.compute_zone =
case
When: P14_zone_4 is NOT NULL
then: P14_zone_4
of other i.compute_zone
end
any suggestions?
Thank you
MICAH
How get the desired results of your data depends on the desired results and your data. What do you do? (I can't tell just by looking at the aat code that do not do). After CREATE TABLE and INSERT statements for some sample data and a couple of sets of parameters (variables such as p14_zone) and the exact results that your choices in each set of parameters, given the same sample data.
Check out the Forum FAQ: Re: 2. How can I ask a question on the forums?
CASE expressions are generally not useful in a WHERE clause. CASE expressions are a convenient way to IF-THEN-ELSE logic of the places where you can't do anything other than (the SELECT clause), but WHERE the clauses allow IF-THEN-ELSE logic in any case
Maybe you want something like
WHERE MERGE (: p14_zone,: p14_zone_2,: p14_zone_3,: p14_zone_4) IS NULL
OR IN i.compute_zone (: p14_zone,: p14_zone_2,: p14_zone_3,: p14_zone_4)
It returns TRUE if all 4 parameters are set to NULL. If 1 or more of them are not NULL, then it will return TRUE if i.compute_zone is equal to one of them.
Tags: Database
Similar Questions
-
How to use the instruction box in where clause
Hi all
I need to use cases where clause guide me please how I can do it.
AND WHEN BOX: KAPCO = "KAPCO" THEN cla. CLASS_NAME LIKE '% KAPCO % '.
WHEN: KAPCO = "NON_KAPCO" THEN SUPERIOR (cla. CLASS_NAME) NOT LIKE '% KAPCO % '.
WHEN: KAPCO = 'ALL' GOLD: KAPCO IS NULL SO SUPERIOR (cla. CLASS_NAME) LIKE '% '.
END
Concerning
Published by: user10941925 on March 4, 2012 22:31Hello
CASE expressions return a single value, for example a VARCHAR2. They do refer to code fragments.
You usually don't need (or want) an expression BOX in a WHERE clause, or any other condition. I think that you were trying to do the equivalent of:
AND ( (:KAPCO = 'KAPCO' AND cla.CLASS_NAME LIKE '%KAPCO%') -- Don't you want UPPER on this line? OR (:KAPCO = 'NON_KAPCO' AND UPPER(cla.CLASS_NAME) NOT LIKE '%KAPCO%') OR (NVL (:KAPCO, 'ALL') = 'ALL' AND cla.CLASS_NAME IS NOT NULL) )
If you would care to post some sample data (CREATE TABLE and INSERT statements) and the results desired from this data, I was able to test this.
-
problem with an instruction box in where clause getting ora-00905
The query runs @ 07:00 every day and must return data for the last day, except Monday when the previous 3 days must be returned.
Select ip.adm_date+ip.adm_time/86400 as admDateTime,
IP.pt_code,
ICC. Surname,
CPI.first_given_name,
IP.w_code,
"as 'MR < 24."
"as"MR 24-36"
"as 'MR 36-48."
"as"MR 48-60,"
"" as "MR 60-72",.
"as 'MR > 72."
"as 'MR finalized."
«like "Pharm/Tech",
"as 'MR criteria."
Of
k_ipreg ip, k_cpireg ICC
where ip.pt_code = cpi.pt_code
and ip.disch_date is null
and ip.adm_date between ((affaire quand (select to_char (sysdate,'d ') of double) = 1 then ip.adm_date > sysdate-3))
of another ip.adm_date > sysdate-1
end)) and sysdate
and w_code not in ("ICW", "OEN", "ANTE", "BABY", "CHILD", "DELI", "ED", "MATY", "USSN")
Try to learn to use properly the functions of Oracle:
SELECT Ip.Adm_Date + Ip.Adm_Time / 86400 AS Admdatetime , Ip.Pt_Code , Cpi.Surname , Cpi.First_Given_Name , Ip.W_Code , '' AS "MR < 24" , '' AS "MR 24-36" , '' AS "MR 36-48" , '' AS "MR 48-60" , '' AS "MR 60-72" , '' AS "MR>72" , '' AS "MR Finalised" , '' AS "Pharm/Tech" , '' AS "Met MR Criteria" FROM K_Ipreg Ip, K_Cpireg Cpi WHERE Ip.Pt_Code = Cpi.Pt_Code AND Ip.Disch_Date IS NULL AND Ip.Adm_Date BETWEEN ( ( CASE WHEN TO_CHAR ( SYSDATE, 'd' ) = 1 THEN SYSDATE - 3 ELSE SYSDATE - 1 END ) ) AND SYSDATE AND W_Code NOT IN ('ICW', 'NWB', 'ANTE', 'BABY', 'CHILD', 'DELI', 'ED', 'MATY', 'SCBU');
-
Case instructions within a Where clause clause
Hello group,
I know this has been asked several times, but I do not enter simply to a tuition assistance box in a WHERE clause. So I need help:
My current WHERE the clause reads:
A16. FULL_DATE between (SELECT (TRUNC (SysDate - 8)) From Dual) and (select (TRUNC (SysDate - 2)) double)
However, I need to 'automate' a bit, based on the current time/day of the month. I need my instruction box to say:
(Case when to_char (sysdate-3, 'mm') <>to_char (sysdate, 'mm')
then the a16. FULL_DATE (between SELECT (trunc (ADD_MONTHS ((LAST_DAY(SysDate-3)),-1)+1) and (SELECT (add_months (trunc(SysDate-2)-1)) of double)))
Of another a16. FULL_DATE between (SELECT trunc (ADD_MONTHS ((LAST_DAY (SysDate)),-1)+1) From Dual) and (select (TRUNC (SysDate - 2)) From Dual)
However, I have an error on "Else". Can someone explain what is the problem and how to fix it? I tried both 'then' and 'Else' syntax and both will run individually. So I'm quite sure that he does not like my CASE statement in general.
In advance, thank you for your help.
Don
I can't tell what your business logic, so here's a simple example of an instruction box in the where clause:
SQL > select *.
2 double
3 where dummy = case when extracted (sysdate months) = 9 then 'W '.
4 Once extracted (sysdate months) = 10 then 'X '.
When 5 extract (month from sysdate) = 11 then 'Y '.
6 else 'Z'
7 end
8;D
-
X -
several conditional parameters in where clause
How to select records in a table, when I say emp, a parameter for where the condition as
If empno is known then use in where clause,
If ename is known then use ename in where clause,
If both are known then use two parameters in where clause.
I use Oracle 9i.
How can I do this in sql and plsqlpsuedo code. ... if p_empno is not null and p_ename is not null then select * from emp where empno=p_emp and ename = p_ename ; elsif p_empno is null and p_ename is not null then select * from emp where ename = p_ename ; elsif p_empno is not null p_ename is null then select * from emp where empno=p_emp ; else select * from emp end if ; ...
Thank you
Published by: user10999538 on July 15, 2009 03:29Solution
SELECT * FROM emp WHERE Nvl(empno,-9999) = Coalesce(p_empno,empno,-9999) AND Nvl(ename,'X') = Coalesce(p_ename,ename,'X') /
SS
-
Why can't put several instructions box here?
I am currently having a case statement and instruction decode in the same query, and whenever I run it, it gives me the same error-
KEYWORD not found or planned.
The query that I am running is.
Select ctn_nbr, plt_id, locn_brcd, ctrl_nbr, substr(ref_field_1,3,8),
ship_via, user_id, mod_date_time, TRUNC (sched_dlvry_date), trkg_nbr as tracking_number,
DECODE (STAT_CODE,
"10', 'not selected."
'20', 'printed ',.
"35', 'in packaging."
"40", "complete package"
"70', 'loaded on truck."
"90', ' delivered/billed."
"99', 'cancellation."
'Unknown') THAT the status.
case
When SUBSTR (SOLDTO, 0, 6) = "BATH" and "special order".
else "Standard order"
end up like "order type".
Table A
Is this something ridiculously simple that I'm missing like a comma? I do not understand why this error message keeps coming up. Help, please!end as "order type".
-
by the way check box values in the WHERE clause
Hello
I created a data block - 'CONTACT' (block of data in database)
and has an element of database - 'Code', 'Descr '.
The number of records displayed has the value 5.
When enabled - value 'Y '.
Value when disabled - n
Box mapping of other values - "unchecked."
I write the code inside "WHEN the BUTTON PRESS. My main goal is to return the number of records from
According to several conditions and one among them is the CODE which can be single or multiple based on the checked checkbox.
The requirement is when I check one or more boxes, I should pass the "Code" element values in the WHERE clause.
I tried to use the simple loop but things havmt worked as shown below.
The next_record refers to the COCHEE BOX as well, and thus return all the eventhough lines if it is not checked.
----------------------------------------------------------------------------
-LOOP
IF: contact.cb = 'Y' THEN
LOOP
IF p_where is null then
p_where: =: contact.code;
on the other
p_where: = p_where | «, » || : contact.code;
end if;
When the output: system.last_record = "TRUE";
next_record;
END LOOP;
end if;
-END LOOP;
MESSAGE ("p_where :'|| p_where);
MESSAGE (' ');
END;
------------------------------------
And even if I write the LOOP before the first CASE, it returns me the current value and move to the last record.
Please suggest
Try something like this:
FIRST_RECORD; LOOP IF :contact.cb = 'Y' THEN IF p_where is null then p_where := :contact.code; else p_where := p_where ||','||:contact.code; end if; END IF; exit when :system.last_record = 'TRUE'; next_record; END LOOP; -- END LOOP; MESSAGE ( 'p_where :'||p_where); MESSAGE (' '); END;
-
How to set a null column in a where clause clause involving a statement box
In oracle APEX, I a (selection list) element called: P32_STATUS. It contains two values of interest (for this discussion): 'Available' and 'checked '. In my report, I have a column called vc_status that contains two values: "Checkbox" and NULL. In my application I want to use a case statement in my where clause similar to the lines of
where
.
.
.
AND (vc_status = CASE WHEN: P32_STATUS = "Checkbox" THEN : P32_STATUS )
WHEN : P32_STATUS = 'Available' THEN NULL END)
The 'box' filtering works but the filtering to try to vc_status the NULL value does not work. Can someone help me? Thank you!
(P.S. My intuition says that there because I can not put vc_status = NULL, but I must say that vc_status IS NULL... However, I don't know how to do execution IS ZERO inside a CASE statement)
Hello
Your intuition is right...
In Oracle NULL is a bit special:
NULL = NULL is false
NULL <> NULL is false
Thus, instead of the parameter a NULL value in the CASE WHERE there is just set a value on the other side:
NVL (vc_statut, 'Available') =: P32_STATUS
That's all! Simple, clean and functional
-
Creation of a where clause clause in the LOV query box
Hi guys is any able to help me with this one
I have a page in my application where there down LOV down now values this menu drop-down comes from a table that looks like this
users_for _form_TBL
E_MAIL Name of the vendor [email protected] Oracle [email protected] SAP [email protected] IBM [email protected] Oracle [email protected] Intergraph So my syntax for the LOV I mentioned looks like this
Select PROVIDER as display_value, SELLER as return_value
of form_user_tab where email =: APP_USER
order by 1;
so if [email protected] connects to the application and to make a selection on the LOV it would only show suppliers compared to his E_MAIL like oracle, sap, IBM , and then he clicks the submit button on the page then the seller that he chose is inserted into another table. What I did on the table of insertion has been to create a trigger that after inserting a seller the trigger inserts a 1 in a column called assessed.
What I did after that is add a select statement in the where clause of the LOV so that she would check in the table insert if this seller had been chosen before and not show them again to be selected my syntax, the second time around in the SQL query box has been
Select PROVIDER as display_value, SELLER as return_value
to users_for _form_TBL where email =: APP_USER
and (select "seller", "ASSESSD' of _tbl inserted is null);
order by 1;
But im getting an error of ideas guys. Thank you
rhisingh wrote:
hay man thanks for your response really using the syntax is
Select PROVIDER as display_value, SELLER as return_value
to users_for _form_TBL where email =: APP_USER
and (select provider, ESTIMATED from _tbl of nserted where there is no "seller", "RATED")
order by 1;
im still get and error is the where the clause allowed in the second select statement
He still has basic syntax errors. You posted 4 different "table names" whose only in the first query is valid so far. That can not see your database, I don't know what really is the name of these tables, and to what extent these is wrong helps your problem.
I can tell that you are looking for:
select u.vendor display_value , u.vendor return_value from users_for_form_tbl u where u.e_mail = :app_user and not exists (select null from inserted_tbl_imp i where u.vendor = i.vendor) order by u.vendor
but the table names could be something else...
-
dynamic instruction in where clause?
Hi all
I am writing a procedure and the request will be different according to the input parameters.
I wonder how I can do this inside where clause? simplified example
Select *.
from tableA, tableB b
where a.id = b.id
/ * If input parameter = "abc" then * /.
and a.total = b
/ * If input parameter = "xyz" then * /.
and a.total! = b
I was thinking case statement, but from what I've read, it cannot be used in this situation
Thank youHello
This give a try.
not testedselect * from tableA a, tableB b where a.id = b.id and (a.total= case when :input_param='abc' then b.total end or a.total != case when :input_param='xyz' then b.total end)
See you soon!
Bobin -
Expression box in a WHERE clause
I got a report where users spend a school id to search errors for their school. Is what I want to be able to do, if no school id is passed or they enter a 0 (zero), the report spans the entire district. This is indeed by omitting the last line in the WHERE clause:
and (schoolid = 425 or enrollment_schoolid = 425)
I think that a CASE expression might work but not sure how to do it.
****************************
Select
enrollment_schoolid,
SCHOOLID,
student_number,
state_studentnumber,
LastFirst,
TO_CHAR (entrydate, 'yyyy-mm-dd'),
Case
When entrydate > = to_date ('01 AUG 08') and enroll_status >-1 then "Invalid Pre-Enroll status enroll_status be-1 currently ' |" TO_CHAR (enroll_status)
When state_studentnumber is null and enroll_status >-1 then 'no. SSID must be a new student.
When entrydate = exitdate then "No Show exit Exchange is at 01/08/2008 - Comments | TO_CHAR (transfercomment) | ' - ' || TO_CHAR (ExitComment)
When lastfirst as '%. %' then 'period in the name '.
When ethnicity is null then 'no ethnic group Code.
Else "other error".
End as error
Of
students
where
ENTRYDATE > to_date ('01 AUG 08') - do not check the previous years
and)
ENTRYDATE = exitdate - not the time at school
or like '%. %' lastfirst - period in the name
or (state_studentnumber is null and enroll_status >-1)-check the SSID
or ethnic origin is null - no. ethnicity
)
and (schoolid = 425 or enrollment_schoolid = 425)
Published by: Opus on April 30, 2009 09:46Hello
Tell you if the user enters 425 as a parameter, you want the WHERE clause to include:
and (schoolid = 425 or enrollment_schoolid = 425)
But if the user enters 0 (or NULL) you want to ignore this condition?
Assuming that the parameter is: target_schoolid, you can replace the condition above with this:
AND ( schoolid = :target_schoolid OR enrollment_schoolid = :target_schoolid OR :target_schoolid IS NULL OR :target_schoolid = 0 )
Published by: Frank Kulash, April 30, 2009 12:54
-
Case statement in a WHERE clause
Gurus,
Im trying to avoid Union of several select statements using a CASE inside a WHERE clause. When the parameter is defined as "What's new" it is advisable to use a code and for "Update Items" another condition.
Having a problem with the following... I know that BOX in WHEREs instructions are allowed only can not make it work for this one.
Points for correct and helpful answers!and case when 'New Items' = 'xxx' --p_item_status then msi.creation_date = msi.last_update_date when 'Updated Items' = 'bbb' --p_item_status then msi.creation_date != msi.last_update_date else 1=1 end;
Published by: sreese on March 27, 2012 17:51Hello
The great thing about CASE expressions, is that they allow you to use a login IF-THEN-ELSE in the clause SELECT, the ORDER BY clause or anywhere else. The WHERE clause has its own way to IF-THEN-ELSE logic, so even if you can use a CASE expression in a clause WHERRE, it usually does not help anything. You can do somehting like this:
WHERE ( :p_item_status = 'New Items' AND msi.creation_date = msi.last_update_date ) OR ( :p_item_status = 'Updated Items' AND msi.creation_date != msi.last_update_date ) OR ( :p_item_status NOT IN ( 'New Items' , 'Updated Items' ) )
This guess: p_item_status is not NULL.
If: p_item_status can be NULL, and you want to include all the lines where it is, and then change the last condition toOR ( NVL (:p_item_status, 'OK') NOT IN ( 'New Items' , 'Updated Items' ) )
I hope that answers your question.
If not, post a small example of data (CREATE TABLE and INSERT, only relevant columns instructions), some values of the parameter and the expected results of these data for each value of the parameter.
Explain, using specific examples, how you get these results from these data.
Always tell what version of Oracle you are using. -
Implementation of subqueries in the WHERE clause
Hi all
First of all, here are the technical info:
Oracle JDeveloper 12 c 12.1.3.0.0
Studio Edition Version 12.1.3.0.0
Build JDEVADF_12.1.3.0.0_GENERIC_140521.1008.S
Version of the component
========= =======
Oracle IDE 12.1.3.0.41.140521.1008
Java (TM) Platform 1.7.0_51
Support versioning 12.1.3.0.41.140521.1008
Secondly, the issue I'm facing is I'm trying to implement a query with three sous-sélections them in the (see image below) WHERE clause. I don't know what is the best way to implement something like this.
I have implemented this by creating a display object and add a view criteria. I put the whole SQL fragment in the view as a literal value criteria. Is there a better (or best?) approach to implement something like this?
This implementation is a problem is because as well as query tests out fine when I click on explain Plan even recognized that there is no bind variables in subqueries and allows me to.
When I run this test by the tester of AM, that it fails to recognize and define the binding (projCategory) variable that appears only in subqueries. All your comments and/or help is very appreciated.
Thank you
Vladimir
Vladimir, there is something wrong in the view Definition of criteria dialog box. The button "explain plan...". "running the whole statement generated (as a string) and returns the result. The entire statement is valid and returns the correct result. However, the view criteria, when it is running in the application work differently. Here the literal that you entered is not passed as a string, but the framework does something internally with her (it is necessary to do things as in the research of memory and other things). If you run the criteria to view in the app Tester I get
SQL error in the preparation of the statement. Instruction: SELECT Employees.EMPLOYEE_ID, Employees.FIRST_NAME, Employees.LAST_NAME, Employees.EMAIL, Employees.PHONE_NUMBER, Employees.HIRE_DATE, Employees.JOB_ID, Employees.SALARY, Employees.COMMISSION_PCT, Employees.MANAGER_ID, Employees.DEPARTMENT_ID from employees WHERE (((Employees.SALARY< :vc_temp_1="" )="" )="" )="" ):="" ora-01722:="" invalid="">
Accordingly, for the display criteria
employes.salaire< (select="" max(e2.salary)="" from="" employees="" e2="" where="" e2.department_id="">
As you can see the literal is passed as: vc_temp_1 and my binding variable is not visible at all. You can open an SR and ask for the support of working on it. I guess that they do not see a bug here as help for the dialog box says:
Literal
Select when you want to provide a value for the attribute, or when you want to set a default value for a lookup field specified by the user for a search query-by-example form.
When the criteria of view defines a search query for the user interface form, you can leave the field blank. In this case, the user will provide the value. Alternatively, you can provide a value that will act as a default value to the field search that the user will be able to substitute. This entry can include wildcards * or %.
When the attribute is of type Date, specify the value of the date in the format YYYY-MM-DD; for example, to December 16, 2010, enter 2010-12-16.
Here, it tells you that a value is expected. Your sub query is not interpreted, but is simply converted to the appropriate data type. In my example, I get an invalid number as expected.
So I guess my suggestion to use a custom sql statement stands.
Timo
-
Dealing with the value of the parameter in where clause
Hello
I want to build a where clause condition containing an instruction box with control over a parameter value, something like this:
cases where when +: param + = '1' then column ('01', '04' another column = '02' end
Thank you
MagnusTry something like this:
... where case when :param = '1' and column in ('01','04') then 1 when :param != '1' and column = '02' then 1 end = 1
-
Using a CASE statement in 'IN' where clause clause
Hello
I have a form that users see after they connect with a few items and they type or select values based on the element type. All reports in the application use these values of PAGE 1 in where clause to filter the lines.
One of these question is "Quarter". I have a group of radio buttons on the PAGE 1 on the P1_QTR point.
I need to provide users a way to take the last 4, last 3, last 2 or current quarter and I need to dynamically build a clause WHERE the interactive report based on the selection in the form.
I am trying to use the CASE as shown below and get the syntax error.
AND QTR to (when BOX: P1_QTR = 'CURRENT' then ("T4"))
When: P1_QTR = "LAST" then ("Q3")
When: P1_QTR = 'LAST TWO' then ('Q3, "Q4")
When: P1_QTR = 'LAST THREE' then ("Q2", "Q3,' T4 ')
another ("T1", "T2", "Q3,' T4 ')
END)
How can I achieve this?
Following a simple logic, try
and QTR to
(
Select 'T4' double where: P1_QTR <> 'LAST '.
Union of all the
Select 'Q3' to double where: P1_QTR <> "in PROCESS".
Union of all the
Select "Q2" double where: P1_QTR not in ('CURRENT', 'LAST', "LAST TWO")
Union of all the
Select "Q1" double where: P1_QTR not in ('CURRENT', 'LAST', 'LAST TWO', 'THREE LATEST')
)
Maybe you are looking for
-
Apple TV 3 - crashes, restarts, is delayed without reason
After the update I noticed that our device a1427 began trolling a bit. It is now unusable. The device freeze, restart even when I try to go into the settings. I did wear it all off the wall thing, tried to use Ethernet instead of wifi etc nothing wor
-
2007 iMac OS 10.6.8 trying to update to 10.11
I have an iMac white middle to end 2007 to 20 "using 10.6.8 (Snow Leopard), and I'm trying to update 10.11 (El Capitan). According to the specifications of Apple, it SHOULD work, but when I go to download, I get a message that says that it is "imposs
-
Satellite A100-TA6 - Windows XP Driver needed.
Expensive Clubs, I need * Toshiba Satellite A100-TA6 * (PSAA8C-TA620C) drivers for Microsoft Windows XP SP2.I lost my driver files. Please help me. Best regards Great
-
I have a PXI chassis which has a function (PXI-5412) generator. The function generator exhausted at work but acts after that I reinstalled the drivers to solve a problem. It does not appear in the category DACmx or traditional daq. Using the name
-
Pass the music playback is a problem on all music players.
I have been through the forums and followed many instructions. I still have to solve skip play on music (and video too). I think the problem started when I installed Vista service pack 2 and a series of additional upgrades. I completely deleted the d