alias in where clause
HelloIt is a question of OCA certification.
1. SQL > SELECT prod_name, prod_list_price, prod_list_price-(prod_list_price*.25) "DISCOUNTED_PRICE".
PRODUCTS
WHERE the discounted_price < 10;
The query generates an error.
What is the reason for generating fault?
A. the parentheses should be added to frame the entire expression
B. the quotes should be removed from the column alias
C. column aliases must be replaced by the expression in the WHERE clause
D. column aliases must be capitalized and closed double quotes in the WHERE clause
Answer: D
My question is how we can use aliases ("DISCOUNTED_PRICE") in where clause (WHERE "DISCOUNTED_PRICE" < 10)?
Please specify.
Hello
C. response (and I think, you not write review at this time)
You cannot use alias name in the WHERE clause.
And if you want to continue to use DISCOUNTED_PRICE in the WHERE clause, you can use view inline.
SELECT *
FROM (SELECT prod_name,prod_list_price,prod_list_price-(prod_list_price*.25) "DISCOUNTED_PRICE"
FROM products
)
WHERE WHERE discounted_price<10;
See you soon,.
Suri
Tags: Database
Similar Questions
-
Case with where clause - ORA-00920: invalid relational operator
Hi all, when I try to run the following query, I get the following error...
ORA-00920: invalid relational operator
00920 00000 - "invalid relational operator.
* Cause:
* Action:
Error on line: column 16: 5
Anyone know what the problem with my request? Thanks in advance.
SELECT concat (year, period)
OF DD_ACTUALS_FACT
CASE WHERE period
WHEN 'JAN' THEN '01'
WHEN 'FEB' THEN '02'
WHEN 'MAR' THEN ' 03 "
WHEN "APR" THEN ' 04 "
WHEN 'CAN' THEN ' 05 "
WHEN "JUN" THEN '06'
WHEN 'JUL' THEN '07'
WHEN 'AUG' THEN '08'
WHEN 'MS' THEN '09'
WHEN 'OCT' THEN '10'
WHEN 'NOV' THEN '11'
WHEN 'DEC' THEN '12'
END as number 'months '.
ORDER OF CONCAT (year, number 'months') / / DESC
The problem is the number 'month' - you cannot give an "ACE" alias for an expression in a where clause clause.
You have not really given any condition, that a set of translations of period in a number.
Also, you didn't say what you're trying to do.
Maybe you want to:
SELECT concat (year, period)
OF DD_ACTUALS_FACT
WHERE something
ORDER OF CONCAT (year, period of the CASE
WHEN 'JAN' THEN '01'
WHEN 'FEB' THEN '02'
WHEN 'MAR' THEN ' 03 "
WHEN "APR" THEN ' 04 "
WHEN 'CAN' THEN ' 05 "
WHEN "JUN" THEN '06'
WHEN 'JUL' THEN '07'
WHEN 'AUG' THEN '08'
WHEN 'MS' THEN '09'
WHEN 'OCT' THEN '10'
WHEN 'NOV' THEN '11'
WHEN 'DEC' THEN '12'
END DESC)
/
-
Hi Master,
I have a small doubt regarding where clause of a select query. I have a select query with 3 tables. I joined like that.
Select * from
ABC one
XYZ x
PQR p
where a.column1 = b.column1
and a. column 2 = value
and b.coumn1 = c.column1
and c. column2 = value
and b. Column3 certain condition
How oracle work where condition? average which condition will run first... is there a systematic order? Please advise... !!
Concerning
AR
Hi, Ar,
874273 wrote:
Hi Master,
I have a small doubt regarding where clause of a select query. I have a select query with 3 tables. I joined like that.
Select * from
ABC one
XYZ x
PQR p
where a.column1 = b.column1
and a. column 2 = value
and b.coumn1 = c.column1
and c. column2 = value
and b. Column3 certain condition
How oracle work where condition? average which condition will run first... is there a systematic order? Please advise... !!
Concerning
AR
There is no predefined order. The optimizer uses any order that it deems will get faster results. You can check the execution plan to see how she chose in a particular case.
SQL is a non-procedural language. When you write code in a procedural language, tell you How you want to do something. When you write code in SQL, you say what you want to do.
-
Try adding conditions to clause "and" stored in the table for the where clause, unknown syntax
I am trying to add additional segments to the 'where' clause, and I don't know exactly how to proceed. I am currently using another table to search for keywords and sometimes there aren't everything. I use this table containing the key words to search the description and associate a symbol with a path.
The code loops through the keywords with the keywords most associated and try to find links to a symbol then excludes those and search for symbols that correspond to those with less keywords and all. I am able to do this with 6 queries and manually changing the arguments, but I want to loop together so that if the changes need to be made in the future, I won't need to go digging in the code.
Thanks, but that's ok. I already have a solution for this.
-
Hi Experts,
I have a VO with query like select * ministries dept, emp where dept.dept_id = emp.dept_id group... by order of dept.dept_id employees
At runtime, I need to add where clause with (and in dept.dept_id (select dept_id from table2))
I tried to use the vo.setWhereClause () method. But it does not work
Is there another solution?
I use Jdeveloper 12.1.3
Thanks in advance.
There are various possible solutions for this. You can either use setQuery that defines the entire sql statement. However, you then need to delete where condition adding yourself too.
Or you use viewCriteria as explained in this blog http://www.ahsanscorner.com/content/2015-11-16-1942-simulating-sql-clause-adf-viewcriteria-api.
Another approach is described by this blog Jet binary: using bind variable for SQL statements with the paragraph who uses a SQL table to build the in clause.
Timo
-
ViewObject where Clause SET based on logged in user roles
Hello Experts
I have a view object based on a custom query to get distinct values from a table. My requirement is to display the results as a listview. The listview is is filled without any problem. But I need to add a where clause clause the object view based on the user roles.
I have a method that generates the where clause and returns one string something like "COUNTRIES ('USA', 'UK').
I created a class of the view object Impl and put WhereClause as below: but where clause is not applied when I run the page. I see everywhere instead of just USA & UK.
Can you let me know at what time should I set the where the clause?
SerializableAttribute public class CountriesVOImpl extends ViewObjectImpl {}
/**
* This is the default constructor (do not remove).
*/
public CountriesVOImpl () {}
this.setWhereClause (getCountries ());
}
public String getCountries() {}
return '('USA', 'UK') COUNTRIES. "
}
}
In class ViewImpl try to replace "executeQueryForCollection" and setWhereClause in this function as:
protected void executeQueryForCollection(Object object, Object[] object2, int i) { setWhereClause("COUNTRY in ('USA','UK')"); super.executeQueryForCollection(object, object2, i); }
-
where clause to query the hierarchy in the tree Apex area does not
Hi all
I am building a tree Menu in Apex 5.0.3 (Oracle 11 g XE), when using when the clause, it does show all the data, but without him, showing all the data.
I'm trying to populate Tree Menu with data specific to a user successfully logged on.
(A) table created as HR2. TREE_MENU
menu_name varchar2 (50).
number of menu_parent
number of menu_child
menu_id varchar2 (12),
menu_path varchar2 (100),
number of user_no
(B) SQL statement for the tree in the Apex region
Select case when connect_by_isleaf = 1 then 0
When level = 1 then 1
else -1
end the status,
level,
'Menu_name' as the title,
NULL as an icon,
"MENU_CHILD" as a value.
NULL as ToolTip,
NULL as link
to HR2. "" TREE_MENU ".
-WHERE USER_NO =: P_USERNO
Start with 'MENU_CHILD' is null
connect prior "MENU_PARENT" = "MENU_CHILD."
brothers and sisters of order by 'MENU_ID '.
Note: also used static value where clause but is not workd.
that the mistake of me or something else? When using the wizard, she asks (possibly) where clause, this means that when the clause can be used in the SQL statement.
Help, please.
Kind regards.
If you want to prune your tree to show only the elements of the No. 7 usermenu, copy the following code helps you
select case when connect_by_isleaf = 1 then 0 when level = 1 then 1 else -1 end as status, level, "MENU_NAME" as title, null as icon, "MENU_CHILD" as value, null as tooltip, null as link from HR2."TREE_MENU" start with "MENU_CHILD" is null connect by prior "MENU_PARENT" = "MENU_CHILD" and "USER_NO" = 7 order siblings by "MENU_ID"
Concerning
Mahmoud
-
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')
)
-
Cannot run a «BUSINESS...» WHEN ' with a date in a WHERE CLAUSE condition
Hello
I need to check for a condition and date according to the date, he would check a set of host names or the other game... so I thought I could write something like this in the WHERE clause:
AND HOST_NAME IN (
CASE
WHEN TO_DATE (: StopDate, 'MON-DD-YYYY') > = TO_DATE ('22 - DEC - 2015 "," DD-MON-YYYY ') THEN
('SERVERNAMEA', 'SERVERNAMEB', 'SERVERNAMEC') ON THE OTHER
("SERVERNAME1", "NAMESERVER2", "SERVERNAME3")
END
)
I get the following:
ORA-00907: lack of right parenthesis
00907 00000 - "lack the right parenthesis.
But there is no missing parentheses!
If I take the case... when... end, and run the host_name in ('SERVERNAMEA', 'SERVERNAMEB', 'SERVERNAMEC') (separately, they run fine)...
I also tried:
AND
( CASE
WHEN TO_DATE (: StopDate, 'MON-DD-YYYY') > = TO_DATE ('22 - DEC - 2015 "," DD-MON-YYYY ') THEN
HOST_NAME IN ('SERVERNAMEA', 'SERVERNAMEB', 'SERVERNAMEC') ELSE
HOST_NAME IN ('SERVERNAME1","NAMESERVER2","SERVERNAME3")
END
)
the error I get is:
ORA-00905: lack of keyword
00905 00000 - 'lack the key word'
What keyword miss me?
Post edited by: c75d2e42-06a0-4eb1-a576-5652edcbfbe8
Hello
c75d2e42-06a0-4eb1-A576-5652edcbfbe8 wrote:
It was a typo when transferred to the Oracle forum... the version of Oracle is: PL/SQL version 10.2.0.3.0 (10 G)
I also used IF the statement and that has not worked (in error "missing parenthesis") which I'm sure is a matter of "syntax"... I did not know that the CASE statement returns the value single only, so it's probably the problem. Is it possible to re - write this?
...
IF only works in PL/SQL. It does not in SQL, even if that SQL is embedded in PL/SQL.
There are many ways to re - write the condition. And here's one:
AND ((host_name IN ('SERVERNAMEA', 'SERVERNAMEB', 'SERVERNAMEC')
AND TO_DATE (: StopDate, "MON-DD-YYYY") > = TO_DATE ('22-DEC-2015', "MON-DD-YYYY")
)
OR (host_name IN ('servername1","Nameserver2","SERVERNAME3")
AND TO_DATE (: StopDate, "MON-DD-YYYY")< to_date="" ('dec-22-2015', =""> >
)
)
If: StopDate can be NULL, it must be a bit more complicated.
You can also use nested, such as CASE expressions
AND THE CASE
WHEN TO_DATE (: StopDate, "MON-DD-YYYY") > = TO_DATE ('22-DEC-2015', "MON-DD-YYYY")
WHILE CASE
WHEN host_name IN ('SERVERNAMEA', 'SERVERNAMEB', 'SERVERNAMEC')
AND THEN 'OK '.
END
OTHER CASES
WHEN host_name IN ('servername1","Nameserver2","SERVERNAME3")
AND THEN 'OK '.
END
END = 'OK '.
I wonder if this in your application is the best way, however. If SERVERNAMEA was put into service on December 22, maybe that that fact should be recorded in a table. If you have a table with 1 row per server, you can consider adding 2 columns DATE to show when the server was first and last used. Then, rather than use a WHERE clause to test servers appropriate, you could do an inner join.
-
Hello world
I have an argument to function entry, lets call this file number. This argument can be 0 (zero) or any number like 9800. No negative number.
My where clause, I would like to say, if the number is 0 (zero), then extract all the cases, otherwise just retrieve the lines/records that belong to the passed in file number.
select * from table1 where case_num = (if case num is 0 then retrieve all cases, otherwise retrieve only the records that belong to the number passed in)
Thanks in advance.
Select *.
FROM table1
where case_num = num
or num = 0;
SY.
-
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 -
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
-
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.
-
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
-
Optimize query with function in where clause
Hello
I have a query like this:
SELECT * FROM table_1 t WHERE ( -- Clause A (very long clause that filters a lot of rows) ) AND f(t.field) = 'Y' -- This function is heavy but it should filter few rows
This query, it is very slow because I think he's trying to evaluate f() for all rows in table_1.
Howerver, if I have database query:
SELECT f(t.field) FROM table_1 t WHERE ( -- very long clause that filters a lot of rows )
It's very fast.
How can I reference the query to filter the lines of division A, then by function?
Thanks in advance!
If you wrap the function in a select clause then the optimizer can use a scalar subquery caching:
SELECT * FROM table_1 t
WHERE ( -- Clause A (very long clause that filters a lot of rows) )
AND (Select f(t.field) From Dual) = 'Y' -- This function is heavy but it should filter few rows
Maybe you are looking for
-
When Apple's QuickTime Windows available 10?
For those of us in the video editing field that surprise us in the Apple no longer offers QuickTime for Windows 10. I guess that's the way to Apple to force us to use Final Cut Pro. Not going not to happen...
-
can not sign on my own
-
I know there is a tutorial to use Eclipse to develop and simulate BlackBerry applications. Y at - it tutorials that illustrate how to use the RIM BlackBerry JDE [outside the menu [help]? I get the following error: UserInterface building......I/o Erro
-
I have a 7 in windows system and use a Toshiba 1 t external hard drive to back up my files.When I click on the desktop icon to launch the backup application... NTI EZ Module the application crashes. It worked when I installed it all first, been like
-
Using a new dell with windows 7 - I get a message: Mircosoft windows network: network path not found. Network location (1) C$(\\192.168.1.253) (o) what does that mean?