Where-Clause-Question by using "defined values.
HelloI use 10 gr 2
It is possible to filter the lines using sets of values in the where clause?
As for example:
SELECT a, b, c
FROM mytable
WHERE (b,c) IN
(
(3,4),
(6,7),
(9,1),
(0,2)
)
.. must retrieve only the rows from myTable with sets (pairs) over the top of the list
It is not difficult to test:
with my_tab as (select 1 a, 2 b, 3 c from dual union all
select 2 a, 2 b, 2 c from dual)
select * from my_tab
where (b, c) in ((1,2), (2,3));
A B C
---------- ---------- ----------
1 2 3
Tags: Database
Similar Questions
-
Hello Forum!
SELECT job_id, last_name, salary,
AVG (salary) OVER (PARTITION BY job_id) average
Employees
where (select job_id, count (number)
employees
Job_id group) > 1;
This Script returns an error... to values much
IM new to SQL and Oracle, so please be patient for me :-).
I want to get back from the instruction of subselects only where this job_id are used more than 1 by job_id...
but there is nothing wrong in my script.
Thanks in advance.Hello
Welcome to the forum!
919787 wrote:
Hello Forum!SELECT job_id, last_name, salary,
AVG (salary) OVER (PARTITION BY job_id) average
Employees
where (select job_id, count (number)
employees
Job_id group) > 1;This Script returns an error... to values much
Whenever you have a problem with an error message, view the exact error message, including line numbers.
IM new to SQL and Oracle, so please be patient for me :-).
I want to get back from the instruction of subselects only where this job_id are used more than 1 by job_id...
but there is nothing wrong in my script.Thanks in advance.
I think that's what you want:
SELECT last_name, job_id, salary , AVG (salary) OVER(PARTITION BY job_id) durchschnitt FROM employees WHERE job_id IN ( SELECT job_id FROM employees GROUP BY job_id HAVING COUNT (employee_id) > 1 ) ;
Whenever you post a question, please post a small example of data (CREATE TABLE and INSERT statements) and the results desired from these data. Explain how you get these results from these data.
If you use other tables commonly available (such as hr.employees) so you don't have to display the sample data; just results and explanations. The tables in the schema scott feel generally better than those in the hr schema, because they are smaller. When I run the above query, I have 97 lines. It is difficult for you to produce 97 lines of output desired and difficult for people who want to help you to compare their results to your desired output when there is so much of it. I would like the problem using scott.emp and pretneding simplicy you want jobs with more than 3 people, so would be the desired output:ENAME JOB SAL DURCHSCHNITT ---------- --------- ---------- ------------ SMITH CLERK 800 1037.5 ADAMS CLERK 1100 1037.5 JAMES CLERK 950 1037.5 MILLER CLERK 1300 1037.5 ALLEN SALESMAN 1600 1400 WARD SALESMAN 1250 1400 MARTIN SALESMAN 1250 1400 TURNER SALESMAN 1500 1400
and a query which produces:
SELECT ename, job, sal , AVG (sal) OVER (PARTITION BY job) durchschnitt FROM scott.emp WHERE job IN ( SELECT job FROM scott.emp GROUP BY job HAVING COUNT (empno) > 3 ) ;
See the FAQ forum: {message identifier: = 9360002}
Published by: Frank Kulash, may 2, 2012 10:45 -
How only include a WHERE clause only when a connection variable has a value?
I use JDeveloper 11 g using business components of the tables. I'm now modify the auto-generated SQL code to include WHERE clauses which depend on the values of bind variables. For example I have something like this:
However, this means that when VariableValue is null SQL would fail and I get an error. Is there a way I can include the WHERE clause (or clause AND according to the position in SQL) only when a bound variable has a value (or a particular value)?SELECT mytable.firstColumn FROM myTable WHERE myTable.secondColumn= :VariableValue
Or use: WHERE NVL(:VariableValue,myTable.secondColumn) = myTable.secondColumn
-
Hello
It 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 -
What line in where clause is executed first
Hello world!
I have some sqls that looks like this
Now, which one of it is executed first? where clause or the clause and?select ... from table A, table B where a.name = b.name and a.name in (....)
Join the tables is done preferably in where clause?
I use Oracle 10 g.
Please give me some advice.
Thank you.
NithThere is no one "and the clause".
Your where clause contains two conditions:
a.name = b.name -- condition 1 and a.name in (....) -- condition 2
It is immaterial to the result in the order in which they are executed. And it does not matter in what order you write.
The exact order of execution will be defined by the optimizer. It depends on the table statistics. You can see in your query execution plan. -
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
-
Hello
Oracle version: 11.1.0.7.0 - 64 bit
I read the documentation online at joins. The page is avialable here: joins at
My question is about the join order of evaluation of the conditions in clause and the conditions of those
are not the join conditions and are placed in the WHERE clause.
Consider the following pseudocode
SELECT
T1. Col1,
T2.Col1
Of
Table1 t1 LEFT OUTER JOIN table2 t2
WE
(condition_expression1)
WHERE
(condition_expression2)
Is it correct to say that if there is no column on the status of join (condition_expression1) in condition_expression2, then condition_expression2 is executed before condition_expression1? In other words, oracle always trying to filter based on the WHERE clause individually each table as much as possible before joining them based on the conditions on the article?
Thanks in advance,
Hello
dariyoosh wrote:
Hello
Oracle version: 11.1.0.7.0 - 64 bit
I read the documentation online at joins. The page is avialable here: joins at
My question is about the join order of evaluation of the conditions in clause and the conditions of those
are not the join conditions and are placed in the WHERE clause.
Consider the following pseudocode
SELECT
T1. Col1,
T2.Col1
Of
Table1 t1 LEFT OUTER JOIN table2 t2
WE
(condition_expression1)
WHERE
(condition_expression2)
Is it correct to say that if there is no column on the status of join (condition_expression1) in condition_expression2, then condition_expression2 is executed before condition_expression1? In other words, oracle always trying to filter based on the WHERE clause individually each table as much as possible before joining them based on the conditions on the article? ...
The reverse is actually closer to the truth, but we can't really make general statements like that.
SQL is not a language of the proceedings. Looking at the code SQL, we could say that the code does, but we cannot say much about how that code it. In other words, SQL is a language that describes the results you get, not the way to get them.
The optimizer will do everything what he thinks is faster if it does not change the results. If any order in which they are applied (in outer joins or CONNECT BY queries, for example), then think of the join is done first, and the value of the WHERE clause is applied to the result of the join.
Here is a query looks very much like you posted:
SELECT d.deptno
e.ename, e.sal
OF scott.dept d
LEFT OUTER JOIN scott.emp e ON e.deptno = d.deptno
WHERE e.sal > = 3000
ORDER BY d.deptno
;
Output:
DEPTNO ENAME SAL
---------- ---------- ----------
10 KING 5000
20 FORD 3000
20 3000 SCOTT
The scott.dept table contains deptnos 30 and 40; Why are they not in the result set? The query behaves as if the outer join is made first (production 15 rows), then the WHERE clause has been applied. All lines with deptno = 30 had sals down han 3000 and all single line with deptno = 40 was NULL in the sal column, then these lines are excluded (as well as other lines of deptnos 10 and 20), and only 3 lines above are left.
-
Using cfif in a where clause clause
Hi all
This question is somewhat related to a previous post of mine on the polling dates. I'm trying to use a cfif statement in my where clause to determine if a field is empty or not. Here is the code:
< cfquery name = "GetPastEvents" datasource = "DSN" >
SELECT *.
SITE: calendar
WHERE DatePart ("yyyy", [StartDate]) = < cfqueryparam value = ' #Dateformat (Today, 'yyyy') # "cfsqltype = 'CF_SQL_DATE' / >
and < cfif EndDate NEQ "> < cfelse > StartDate, EndDate < / cfif > < < cfqueryparam value =" "#Today #" cfsqltype = 'CF_SQL_DATE' / > "
and Archive = < cfqueryparam value = '0' cfsqltype = "CF_SQL_INTEGER" / >
ORDER BY StartDate ASC, StartTime ASC
< / cfquery >
My question that this CF tells me EndDate is not defined. EndDate is a field in the SITE table: calendar. There must be a way to make this work, no? Thank you!
You mix the ColdFusion variables (required by cfif) and SQL column names. Think of it this way, all CF tags and function run before the SQL query is sent to SQL server. You are this mixture and try to run CF instruction on SQL Server and thus fail.
You need something like this:
SELECT *.
SITE: calendar
WHERE DatePart ("yyyy", [StartDate]) =
and)
(enddate is not null and EndDate <>
or (enddate is null and StartDate <>
)
and Archive =
ORDER BY StartDate ASC, StartTime ASC
Also, I think your logic cfif was back. Instead of NEQ I think you meant EQ because having an EndDate EQ "and then comparing EndDate until today (else clause) makes no sense.
-
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')
)
-
Version of DB: database Oracle 11 g Enterprise Edition Release 11.2.0.3.0 - 64 bit Production
I have a table my_table as below:
create table my_table
(
my_code varchar2 (6).
my_id varchar2 (24).
forced pk_1 primary key (my_code, my_id)
);
Primary_key here's a composite key that contains columns 1 (my_code) and 2 (my_id).
Is there that a difference in the way below queries is executed in terms of performance (use of indexing in the extraction).(a) select * from my_table where my_code = '123' and my_id = "456";
(b) select * from my_table where my_id = '456' and my_code = '123';
The understanding I have the order of the column in the where clause should be identical to the sequence in
What primary key draws for indexing to be used by oracle in oracle other DML queries ignores indexing
However when I used explain plain both show the same query cost with single scan with index rowid.
so I don't know if I'm wrong in the concept that I have. Kindly help.Thanks in advance,
GerardYour question is answered in the Performance Tuning Guide
14.1.4 choosing composite indexes
A composite index contains several key columns. Composite indexes can provide additional benefits compared to the index to single column:
- Improved selectivity
Sometimes the two or more columns or expressions, each with a low selectivity can be combined to form a composite with a high selectivity.
- Reduced IO
If all columns selected by a query are a composite index, then Oracle may return these values in the index without access to the table.
A SQL statement can use a path on a composite index if the statement contains constructions that use a main part of the index.
Note:
This is no longer the case with the skip index scans. See "Index Skip Scans".
A main part of an index is a set of one or more columns that have been specified first and consecutively in the list of columns in the
CREATE
INDEX
statement that created the index. - Improved selectivity
-
Question of WHERE Clause.
All, I was just doing some checking at random and came across the following query
SELECT * FROM emp WHERE +empno > 0;
My question is that oracle runs the query above without any error. What is the use of such expressions in where clause and why the compiler does not throw error for these?
I've never met such scenario. Just tried your query and it works. The reason is below.
Look at what makes this request.
SELECT - empno FROM emp;
OUTPUT:
-EMPNO
----------
-7369
-7499
-7521
-7566
-7654
-7698
-7782
-7788
-7839
-7844
-7876-EMPNO
----------
-7900
-7902
-793414 selected lines.
So you might see if you add a minus sign before the name of the column, it converts only for negative values.
So, even if you add a sign "+", since these are positive values (> 0), your condition succeeds and gives the result. See what would happen if you used - empno in which your condition.
SQL > SELECT * FROM emp WHERE empno - > 0;
OUTPUT:
no selected line
Hope you clear how it works.
-
where clause to see if they contain the null value
So I've finalized my function but now am having some problems:
the bl field (or the v_bl parameter) has null values in it. When I run the function using the "Select FH ('ACCESS', NULL, 8675309') From dual; I get a NULL return value because it uses the variable to compare with q.bl and you can not have q.bl = null in a Where clause.
The main problem is when the parameters are passed, a line can have the same prob and site, but the bl might be different as null, which would give a different lname.
In where clause I need to have something that will compare the parameter with the bl field. Sometimes it's null sometimes is not, but we need to find the line concerned. I made the "BOLD" in the question police
Here are two possible lines in the data
prob bl site lname
ACCESS Smith 8675309 (null)
54321 8675309 Johnson ACCESS
so in theory, if the function is called with the parameters FH ('ACCESS', NULL, 8675306')
He would return the lname: Smith
and conversely FH ("ACCESS", "54321 ', 8675309") would return Johnson
Here's the function
create or replace
Function FH
(v_prob IN varchar2, v_bl IN varchar2, v_site IN varchar2)
RETURN varchar2
AS
v_lname varchar2 (16);
BEGIN
S.Lname SELECT INTO v_lname
Of
request q
JOIN THE
s response
On
(q.order = s.order)
WHERE
q.BL = v_bl AND - where it is
q.site = v_site AND
q.prob = v_prob AND
s.Lname IS NOT NULL;
RETURN v_lname;
END;
-When I run the FH ('ACCESS', NULL,' 86753) function, it returns an empty value and not the family name
Published by: user11210446 on May 28, 2009 17:03
Published by: user11210446 on May 28, 2009 17:03user11210446 wrote:
If v_bl is Null in the where clause it would even say q.bl = Null which will not work.Matches the NULL value
(1) either you have to say-> q.bl IS NULL
OR
(2) WHERE the NVL (q.bl-99) = NVL (v_bl-99) - this will be true if q.bl and v_bl both are NULL
NULL = NULL evaluates to TRUE, so you use NVLSS@XE > select * from dual where null = null ; no rows selected SS@XE > select * from dual where null is null ; D - X SS@XE > select * from dual where NVL(null,-1) = NVL(null,-1) ; D - X
SS
-
T/t with the WHERE clause using a list breaks
Hello, all,.
I have a project where I need to use a list as part of the WHERE clause for a t/t, and it is breaking. I don't know what I'm doing wrong.
For some pseudo-code, do I have a complete query of a database called 'people '. A list of values for the t/t with the first query; the second query is my t/t:
<cfquery name="getDIR" datasource="#request.THISDSN#"> SELECT thisName dir FROM orgs WHERE thisID in (<cfqueryparam value="#form.org#" cfsqltype="cf_sql_varchar" list="yes" />) </cfquery> <cfquery name="people" database="people"> SELECT colA, colB, colC, colD FROM people WHERE 1=1 AND ( div IN (<cfqueryparam value="#valueList(getDIR.dir)#" cfsqltype="varchar" list="yes" />) OR dir IN (<cfqueryparam value="#valueList(getDIR.dir)#" cfsqltype="varchar" list="yes" />) ) </cfquery>
I get the error message is "t/t syntax error: encountered" div IN \'thisValue\' ".» Incorrect conditional expression, waiting for one of [as | null | between | in | comparison] condition. »
Can support _not_ QoQ lists of WHERE clauses?
V/r,
^_^
SMH - so much... I just found.
I forgot to give the lists in the second query bracket.
(The pseudocode was manually typed, since my dev system is isolated from the internet, and I added the in my pseudo code when they were not in my original code.)
* headdesk * headdesk * headdesk * headdesk *.
V/r,
^_^
-
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;
-
Not able to connect after changing the password using the VALUES ALTER clause
Hello
John explained earlier the clause VALUES below thread.
Status expired
I created a new account named SURI, and tried to use the password of the user account from the HR by using the VALUES clause. I was able to change the password but not able to connect SURI with HR password.
Please see below for details. And the SQL statements that I have tried.
Thank youSQL*Plus: Release 10.2.0.1.0 - Production on Mon Aug 13 18:44:50 2012 Copyright (c) 1982, 2005, Oracle. All rights reserved. Enter user-name: sys as sysdba Enter password: Connected to: Oracle Database 10g Express Edition Release 10.2.0.1.0 - Production SQL> SELECT password 2 FROM dba_users 3 WHERE username = 'HR'; PASSWORD ------------------------------ 4C6D73C3E8B0F0DA SQL> ALTER USER SURI IDENTIFIED BY VALUES '4C6D73C3E8B0F0DA'; User altered. SQL> SELECT password 2 FROM dba_users 3 WHERE username='SURI'; PASSWORD ------------------------------ 4C6D73C3E8B0F0DA SQL> conn suri/hr -- HR account's password is hr only ERROR: ORA-01017: invalid username/password; logon denied Warning: You are no longer connected to ORACLE. SQL>
SuriIts because you have used a different username.
Oracle produces a hash based on the user name and the password, not only the password.Therefore, you can not use the hashed password of a user to log on to the account of another user.
You need to get the password hashed Suri and then connect you to suri by using the password hashed Suri (using the identified by the syntax of values)
Maybe you are looking for
-
I use Server, version 5.1.7 running on a Mac Pro El Capitan. After that I turned on remote management and tried to access the machine with another Mac, I noticed that there were a bunch of new entries users. I guess there are about 50 of them, and th
-
camera switch with 12 pin hirose
Hello I have DMK theimagingsource 23UV024 (link to cam). There are 12 hirose for trigger connector. I entered TTL under my my data DG2020A generator trigger pulse. I'm confused which 2 pins are supposed to be used for relaxation.
-
New PC with Windows 7 recognizes and installs my old Canon BJC 80 printer using a USB cable to parallel printer. Prints test page and documents OK but with a delay of several minutes between hittin 'Print' and out a page. Have a lot of cartridges so
-
Hello..Can someone answer this?Identify two correct instructions on the Oracle registry service.A. , he recorded references to the active base XML and web services.B. provides reports on management portfolio such as the re-use and compliance measures
-
Impossible to edit documents sent by mobile link
Any document sent by mobile link from my Mac are said "home" and cannot be changed on my ipad, an idea?the PDF is a portfolio.Thank you.