QBE generated where clause
I have a filterable table, and when I have a key value in a filter (on a column of varchar/string) I see that the product where the clause contains
AS UPPER (: vc_temp_1 |) '%')
This is the default behavior that is expected to add on a wildcard '%' at the end?
Thank you.
Version 12.1.3.0.0
Yes. See http://docs.oracle.com/cd/E23943_01/web.1111/b31974/web_search_bc.htm#ADFFD1757 for more information.
You can create a view that uses equals instead of "begins by" If you like and use it to filter criteria.
Timo
Tags: Java
Similar Questions
-
How to dynamically generate where clause in Linq
Hi all
Oracle DB: 11 gR 2
Oracle Client: 11.2.0.3.0 (ODP.NET)
Oracle Developer Tools for Visual Studio
VS 2010 (C#)
In a Windows Form, it must query the data based on the values in list dropdown listboxes, which the user selects.
Let's say two combox, one Department and one for salary
Department:
-1 all the
10 Department 1
20 Department 2
30 Department 3
Salary:
-1 all the
1 < 20000
2 20000 to 50000
3 50000 to 100000
4 > 100000
Here is the c# code to query data:
using (var myEDMctx = new HREntities())
{
var LINQrslt = from emp in myEDMctx.EMPLOYEES
Select emp;
}
The default values for the two combox should be everything.
How to write dynamic where clause for this LINQ?
Thanks in advance!That's what I do.
var query = from c in customers
Select c;If (where1 > - 1).
Query = query. Where(c.Where1 > where1);If (where2 > - 1).
Query = query. Where(c.where2 == where2);to return the query;
Published by: Invincible on July 4, 2012 09:25
Published by: Invincible on July 4, 2012 09:27
-
Generating a 'WHERE' clause using a function
Hi, I have provided,
given the function at the bottom are input parameters.
sk_func (salary, dept_no, Job, hire_date)
whatever input is given these entries should be there in a statement,
For example if I contribute as
Select double sk_func(5000,null,null,null);
I need output where salary = 5000;
If I give as
Select double sk_func(5000,null,'Programmer',null);
I need output to where salary = 5000 and job = 'program';
Hope am clear,
In short that never values are non-null, those all should include in my where clause.
I know how to do it, but in light of the considerations, am finding the best way to do it,
Thanks for your answers,I could do that
CREATE OR REPLACE FUNCTION get_where_clause_for_emp_req ( emp_id IN NUMBER, salary IN NUMBER, job IN VARCHAR2, dept IN NUMBER ) RETURN VARCHAR2 IS l_where_clause VARCHAR2 (2000) := 'WHERE 1=1 '; BEGIN IF emp_id is not null THEN l_where_clause := l_where_clause || 'AND emp_id = ' || emp_id || ' '; END IF; IF salary is not null THEN l_where_clause := l_where_clause || 'AND salary = ' || salary || ' '; END IF; IF job is not null THEN l_where_clause := l_where_clause || 'AND job = ' || job || ' '; END IF; IF dept is not null THEN l_where_clause := l_where_clause || 'AND dept = ' || dept || ' '; END IF; RETURN l_where_clause; END;
-
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); }
-
Need help with dynamic where clause.
Hello world. I'm kind of a novice with PL/SQL, so please be patient with me. I am building a web application using Weblogic Oracle 11 g and Oracle database.
To make a long story short, I need to generate the complex dynamic WHERE clause. I don't know what will be the name of the column or the operator of comparison or the value will be until the moment of execution.
I'm not 100% certain, but I think I need to use dynamic SQL statements. Unless there is a better way to do it.
I'm sure that using dynamic SQL opens me up to SQL injection attacks if I use simple string concatenation. I would like to use bind variable if possible.
In any case, it seems like trying to build a dynamic where clause does not seem to work as I want it would be...
bv1 := 'colA = 5 and colB >= 9'; query_str := 'SELECT * FROM view WHERE :bv1'; OPEN CUR FOR query_str USING bv1;
The code above pours out when I try to run it.
Is there a way to build dynamic where the provisions without the use of concatenation of simple string that leaves me open to attacks by SQL injection?
Thank you
Hello. I have read briefly upward on things, you suggested, but it seems a bit abstract for me since I was a novice.
Can you give us an explanation or an example of how to use it to accomplish what I need to do?
Do ypu really plan create a query with a WHERE clause that contains a predicate for all possible columns?
Variable bind offer performance when the same query is executed several times with different values for bind variables.
Select * from emp where empno =: v_empno
After the first run Oracle will always be this query in the library cache. The next running can use the version of the cache even if the bind value is different.
Select * from emp where empno =: v_empno;
Select * from emp where ename =: v_ename;
Select * from emp where sal =: v_sal;
Each one is a DIFFERENT query. Yes - each of them uses a variable binding, but queries are different.
So, if your username select EMPNO, an '=', and a value from the first query can be executed. But the next time that the user can select the ENAME column so that 'stored' first request may not be used given that the query does not match.
The third time your user selects SAL so none of the first two queries can be used in the library cache. The use of bind variables gives performance during the SAME QUERY is used multiple times with DIFFERENT values for the variable binding. Oracle is not to analyze the hard query everything simply because the VALUE is different.
So bind variables do not help you if most of the queries were completely DIFFERENT sets of predicates. And SYS_CONTEXT will not help either since that simply provides a way to define binds the values of the variables.
Just for the simple example above, there are at least SIX possible combinations of columns that could choose your user name: empno, ename, sal, empno ename, empno & sal, ename & sal
-
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
-
Hallo,
I have a request based on VO.
The query contains a where clause clause and a bindi variable.
In a managed bean I would like to access the iterator of VO setting the value of the bind variable and read the result.
I found this code it is good start, but I do not know how to set the variable binding.
BindingContext bctx = BindingContext.getCurrent(); BindingContainer bindings = bctx.getCurrentBindingsEntry(); DCIteratorBinding iter = (DCIteratorBinding ) bindings.get("MyVO1Iterator"); iter.execute();
You kindly help me?
Also, I would like to know if it is generally advisable to use VO directly in controlled beans or whether it would be best to create in the AppModuleImpl methods that do this and return the result.
In my case for example of the VO will return max 1 plug so I'm in doubt, if the creation of a method in the AM that returns a custom class, which attributes contain values of the line of VO.
Sorry if these questions may seem artificial, but I am a beginner, I have many doubts and so I would be happy to receive some tips regarding best practices.
Thank you
Federico
You can use:
iter.getViewObject().setNamedWhereClauseParam("yourBindVar", value);
Note that this approach is used if you have bind variable in the where clause.
To set variables bind to ViewCriteria, you must use VarableValueManager.
This post may be useful for you: binary: how to set the Bind variable values at run time?
Also, I would like to know if it is generally advisable to use VO directly in controlled beans or whether it would be best to create in the AppModuleImpl methods that do this and return the result.
You must set "use VO directly.
For example, from the point of architecture, is probably best to use the method in the model project which will set the bind variable and execute the query.
Or you can use the ExecuteWithParams operation in your the view layer.
In my case for example of the VO will return max 1 plug so I'm in doubt, if the creation of a method in the AM that returns a custom class, which attributes contain values of the line of VO.
Not to complicate your life
All VO lines are represented as ViewRowImpl class if you already have "custom class".
Finally, you can generate your own ViewRowImpl class if it is necessary for this.
Dario
-
How to set SQL that contains 'in' where clause in VO?
I don't want to set "in" would adopt a kind of programatical in VO as below. I want to use a method declariable to set in the clause using bindings varaible.
It can be implemented?
private String getInClauseWithParamNames(List termCodes) { //logic to form the in clause with multiple bind variables StringBuffer inClause = new StringBuffer(); if(termCodes !=null){ for (int i = 1; i < termCodes.size() + 1; i++) { inClause.append(":termC" + (i)); if (i < termCodes.size()) { inClause.append(","); } } } return inClause.toString(); } public Row[] getYardFixedSlots(List termCodes) { if(termCodes != null && !termCodes.isEmpty()){ String inClause = getInClauseWithParamNames(termCodes); //setting the where cluase to use the generated in clause this.setWhereClause("YardFixedSlot.TERMINAL_C in (" + inClause + ")"); ////clearing all existing where clause params if any this.setWhereClauseParams(null); if(getVariableManager() !=null){ this.getVariableManager().clearVariables(); } //setting values for all bind variables one by one in the in clause for (int i = 0; i < termCodes.size(); i++) { //defining the named bind variables programatically this.defineNamedWhereClauseParam("termC" + (i + 1), null, null); //setting the value for each named bind variable this.setNamedWhereClauseParam("termC" + (i + 1), termCodes.get(i)); } this.setRangeSize(-1); //executing the query this.executeQuery(); } //returning the rows from query result return this.getAllRowsInRange(); }
You can only use the link as a parameter to the in clause. You must divide the string inside the binding variable. Sample can be found at decompilation binary ADF: using bind variable for SQL statements with the paragraph
Timo
-
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 -
Foreign key check - possible where clause
I want to create a foreign key referential constraint, but I want to do this only for certain data.
example 2 tables. With 5 rows T1, t1 is to reference col1 in t1, but where the only col2 = "a". If I have all the data of reference I get an error creating the audit as t1.col1 is not unique for all data and is not a PK.
This is an example of a small subset of a much larger table where col1 is not the PK and I can't create a unique index on it as his unique not on its own.create table t1 (col1 varchar(1), col2 varchar(1)) create table t2 (col1 varchar(1), col3 varchar(1)) insert into t1 values ('a','a'); insert into t1 values ('b','a'); insert into t1 values ('c','a'); insert into t1 values ('d','b'); insert into t1 values ('d','b'); commit; alter table t2 add constraint FK_t1_col1 foreign key (col1) references t2(col1); ORA-02270: no matching unique or primary key for this column-list
I could create a materialized view but would rather not if possible. Y at - it solution or method on t1 to create the repository control with a where clause clause in order to do something like the following pseudocode
alter table t2 add constraint FK_t1_col1 foreign key (col1) references t2(col1) where col2 = 'a' ;
961469 wrote:
I want to create a foreign key referential constraint, but I want to do this only for certain data.example 2 tables. With 5 rows T1, t1 is to reference col1 in t1, but where the only col2 = "a". If I have all the data of reference I get an error creating the audit as t1.col1 is not unique for all data and is not a PK.
You don't have to have a primary key as a reference point, it must be unique, and it may be a virtual column. If you are running 11g is easy:
drop table t2; drop table t1; create table t1 ( code_type varchar2(10) not null, code_number number(10) not null, a_code generated always as (case code_type when 'A' then code_number else null end) ); alter table t1 add constraint t1_uka unique (a_code); create table t2( id1 number not null references t1(a_code) ); insert into t1 (code_type, code_number) values('A',1); -- next row is not a duplicate insert into t1 (code_type, code_number) values('B',1); insert into t1 (code_type, code_number) values('B',2); -- next row succeeds insert into t2 values(1); -- next row fails insert into t2 values(2); commit;
Concerning
Jonathan Lewis -
Beginner: Get on the WHERE clause syntax error in SELECT
I am very new to php and mySQL. Use DW master/detail to generate Basic code I need. One thing I have to do is to modify a select statement in the master to include a WHERE clause to limit the selection to a particular value in a field.
I get a syntax error with the select statement in the WHERE clause, I add to the map.
It's the part of the error message showing the location of the error:
"WHERE group = 'Community' LIMIT 0, 10'"
Php that generated the select is:
$query_maps = "SELECT * FROM tblmaps ORDER BY tblmaps.» DispSeq ';
$query_limit_maps = sprintf ("%s WHERE group =' LIMIT %s %d, %d", $query_maps, $selectGroup, $startRow_maps, $maxRows_maps);
This approach to create the select statement is on the generated code for the master page. He added the LIMIT clause. I didn't add the ' WHERE group = '%s' and the variable $selectGroup, which comes from the old code.» You can see that the $selectGroup variable is equal to the "community: group.»
I scanned the web to see what syntax error, I could do, but haven't found anything that explains it.
The resolved full select statement is:
SELECT * FROM tblmaps ORDER BY tblmaps. WHERE DispSeq = 'Community' LIMIT 0,10 group
What I don't see?
Tom
The group is a reserved word in MySQL. You could probably put single quotes around it, but I suggest to rename this column. Do not use reserved words for column names.
-
I need to get only the publications of this year. Here is my where clause:
where pubdate = '2010'
and it generates an error. How can I set the criteria to get only the results of this year?
Thanks,
Jenn
where pubdate = 2010
or
where pubdate = #year (now ()) #.
-
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
-
function defined by the user in where clause
Hello
Please let me know how to use user-defined in the where clause. I need to use the function that returns the date for dateid.
It generates the error...
ErrorSELECT To_char(fnc_get_date_for_dateid(a.postdateid),'DD-MON-YYYY') transaction_date, SUM(A.points) POINTS_OR_MILES_CREDITED, SUM(CASE WHEN a.points is null THEN a.transactionamount ELSE a.points END), FROM accrual a JOIN datecal dc ON dc.dateid = a.postdateid join MemberALL m on m.memberid = a.memberid WHERE a.awardnumber IS NULL AND a.accrualtype = 'B' GROUP BY To_char(fnc_get_date_for_dateid(a.postdateid),'DD-MON-YYYY') ORDER BY a.postdateid;
Thank youORA-00979: not a GROUP BY expression 00979. 00000 - "not a GROUP BY expression"
SandyHi Sandy,
Have you tried like
===========================SELECT To_char (fnc_get_date_for_dateid (a.postdateid), 'DD-MON-YYYY') transaction_date,.
Sum (A.points) POINTS_OR_MILES_CREDITED,
SUM (CASE WHERE the a.points is null THEN a.transactionamount ELSE a.points END),
The ACCRUAL one
JOIN dc datecal ON dc.dateid = a.postdateid
Join MemberALL m on m.memberid = a.memberid
WHERE a.awardnumber IS NULL
AND a.accrualtype = 'B '.
GROUP BY a.postdateid - To_char (fnc_get_date_for_dateid (a.postdateid), 'DD-MON-YYYY')
ORDER BY a.postdateid;
==========================Thank you
Slokam -
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.
Maybe you are looking for
-
I can't format a message correctly when I write in Hebrew, from right to lefteven if I press the left margin and the message starts from the left side, all points mark and end of sentences (periods, etc.) jump to the front of the sentence and quotati
-
Well, for starters, I use a HP Pavilion G6 and it runs Windows 7 Home Premium OS. Well, I personally did the implementation of the PC and fact my user account on the system (with full administrator privileges) while I'm my songs and other stuff on it
-
The upgrade I upgraded from 7 Home Premium 64 - bit-7 Professional 64-bit, then had to wipe the HARD drive and reinstall Home Premium on my drive. Can I upgrade again Professional without having to pay twice? Should I have saved a code which would ha
-
Update CPU in Compaq Presario SR1901WM?
Currently, I have Compaq Presario SR1901WM - with a "stock with the exception of a stick of RAM and the new pci video card e."
-
CC of Photoshop does not download in the application of CC desktop
When you start the download of the CC of Photoshop, a window appears with CC Desktop App to send the download. After that, the application starts, but download does not appear in the App actually there is even no menu for applications inside the CC a