where-clause

Oracle - Can A Bind Variable Be Put In In() Clause If The Variable Can Be Empty

随声附和 提交于 2019-12-02 03:58:09
In Oracle , can a bind variable be put in IN() clause if it can be empty? Asking because in the SQL if Oracle see IN() without any data in it, it shows error ORA-00936: missing expression. Edit: Failed to mention that no PL/SQL can be used... Edit2: Also failed to mention that the variable is either in format 1,2,3 or empty string. The empty string cannot be replaced with NULL. Seems to be working: declare l_statement varchar2(32767); begin l_statement := 'select * from user_tables where table_name in (:a)'; execute immediate l_statement using ''; end; You can do it, it will be syntactically

How to use whereif in LINQ

邮差的信 提交于 2019-12-02 03:16:02
问题 Hi can someone help me how best we can use whereif in LINQ IQueryable<Employee> empQuery; if (empId == "") { empQuery = dbContext.Emps .Include(x => x.Name) .Include(x => x.Code) .Where(x => x.Id == empId); } else { empQuery = dbContext.Emps .Include(x => x.Name) .Include(x => x.Code); } I think we can make this query very simple by using whereif right? Can someone help me how to make this query simple by using whereif? Instead of check if (empid == "") ? Is it possible? 回答1: I believe you

PL/SQL rewrite concatenated query with 'IN' clause

旧巷老猫 提交于 2019-12-02 02:48:07
Currently I have in my pl/sql code following statements: -- vList looks like '1,2,3,4' vStatement := 'SELECT NAME FROM T_USER WHERE ID IN ( ' || vList || ' ) '; Execute Immediate vStatement BULK COLLECT INTO tNames; I think that concatenating of query if bad practice, so I want to make this query without using stings. What is the way to rewrite this ? P.S. maybe people here can point out why concatenation of queries is bad, because i don't have enough reasons to prove that this style is bad. my guess is that you took some steps previously to get vList id's into a delimited string (you don't

SQL Server 2005: Call a stored procedure from a WHERE clause

自闭症网瘾萝莉.ら 提交于 2019-12-02 02:07:27
I need to make a SELECT with a call of a stored procedure in the WHERE clause. It should be something like that.... SELECT distinct top 10 i.x, d.droit FROM v_droit d, v_info i WHERE d.nomdroit='yy' AND i.id<>2 AND (select val from (exec up_droits(i.x, d.droit)) <>3 But it does not work... Any idea? Don't say to replace the stored procedure with a function because is not possible to use the existing code in a function. So the function is not a valid option. I really need to be able to use a stored procedure Remus Rusanu This is achieved by first executing the stored procedure, capturing the

LINQ: Split Where OR conditions

回眸只為那壹抹淺笑 提交于 2019-12-01 17:13:04
问题 So I have the following where conditions sessions = sessions.Where(y => y.session.SESSION_DIVISION.Any(x => x.DIVISION.ToUpper().Contains(SearchContent)) || y.session.ROOM.ToUpper().Contains(SearchContent) || y.session.COURSE.ToUpper().Contains(SearchContent)); I want to split this into multiple lines based on whether a string is empty for example: if (!String.IsNullOrEmpty(Division)) { sessions = sessions.Where(y => y.session.SESSION_DIVISION.Any(x => x.DIVISION.ToUpper().Contains

Using insertWithOnConflict for update or insert

怎甘沉沦 提交于 2019-12-01 16:23:05
I need to insert or update and I found the method insertWithOnConflict of the SQLiteDatabase, but I do not know how it checks if the entry already exists. Theoretically I need a "Where" argument to check if a certain ID exists, and if so, it should replace all other columns. This is what I have now, but I don´t think that the second argument is the unique id ContentValues args = new ContentValues(); args.put(AppDatabase.COLUMN_ID, entry.getId()); args.put(AppDatabase.COLUMN_NAME, entry.getAppname()); args.put(AppDatabase.COLUMN_URL, entry.getAppUrl()); database.insertWithOnConflict(AppDatabase

Ignore Hibernate @Where annotation

99封情书 提交于 2019-12-01 15:03:40
I have an Entity which has an association to another Entity annotated with @Where, like so public class EntityA { @OneToMany @Where(...) private List<EntityB> entityBList; } Recently the inevitable has happened, I need to load EntityB's that don't conform to the @Where clause. I could remove the @Where annotation, but it is used a lot, so ideally I don't want to do that. Apart from loading the list of EntityB's manually, with another query, what are my options? Can I tell Hibernate to ignore the @Where annotation? After lots of research it appears that this is simply impossible. I'd strongly

percentile by COUNT(DISTINCT) with correlated WHERE only works with a view (or without DISTINCT)

半城伤御伤魂 提交于 2019-12-01 14:21:36
I've got a weird one, and I don't know if it's my syntax (which seems straightforward) or a bug (or just unsupported). Here's my query that works but is needlessly slow: UPDATE table1 SET table1column1 = (SELECT COUNT(DISTINCT table2column1) FROM table2view WHERE table2column1 <= (SELECT table2column1 FROM table2 WHERE table2.id = table1.id) ) / (SELECT COUNT(DISTINCT table2column1) FROM table2) + (SELECT COUNT(DISTINCT table2column2) FROM table2view WHERE table2column2 <= (SELECT table2column2 FROM table2 WHERE table2.id = table1.id) ) / (SELECT COUNT(DISTINCT table2column2) FROM table2) +

Ignore Hibernate @Where annotation

跟風遠走 提交于 2019-12-01 13:54:09
问题 I have an Entity which has an association to another Entity annotated with @Where, like so public class EntityA { @OneToMany @Where(...) private List<EntityB> entityBList; } Recently the inevitable has happened, I need to load EntityB's that don't conform to the @Where clause. I could remove the @Where annotation, but it is used a lot, so ideally I don't want to do that. Apart from loading the list of EntityB's manually, with another query, what are my options? Can I tell Hibernate to ignore

PostgreSQL - count data as zero if it is null (when where clause is used)

孤街醉人 提交于 2019-12-01 07:00:37
Now I have this query: SELECT opp.name as name, count(log.stage_id) as stage_count FROM crm_lead as opp LEFT OUTER JOIN crm_lead_stage_log as log ON (opp.id = log.opportunity_id) GROUP BY name And it outputs this result: name | stage_count | name1 | 2 name2 | 1 name3 | 0 And it outputs what I need. But if I put any condition to it, then it skips rows with zero count, which I need to be able to see. For example if I write this query: SELECT opp.name as name, count(log.stage_id) as stage_count FROM crm_lead as opp LEFT OUTER JOIN crm_lead_stage_log as log ON (opp.id = log.opportunity_id) WHERE