Learn about sql oracle case statement in where clause, we have the largest and most updated sql oracle case statement in where clause information on alibabacloud.com
Oracle SQL statement optimization, oraclesql statement
Although orm ing is used in the project, the optimization of the Oracle system is very valuable. Here we will summarize the commonly used statements from the perspective of SQL
An SQL statement is used in the project, such:
Select sum (price * xiaoliang)/sum (xiaoliang) price from ......
When sum (xiaoliang) = 0, the error of division by 0 will occur. What should I do? At first, I wantProgramProcessing, that is, moving the computing process to the program is obviously troublesome. Later, I found the method of using the case
Many students on the optimization of SQL seems to know very little, recently summed up the following 34 articles for reference only.
(1) Select the most efficient table name order (valid only in the Rule-based optimizer):
The Oracle parser processes the table names in the FROM clause in Right-to-left order, the last table (driving table), which is written in th
meaningful in practical work. (14) using the alias of the table:When you concatenate multiple tables in an SQL statement, use the alias of the table and prefix the alias to each column. This reduces the time to parse and reduces the syntax errors caused by column ambiguity. (15) Replace in with exists with not exists instead of in:In many base-table-based queries, it is often necessary to join another ta
likelihood of being shared.
the shared statement must meet three criteria:
A, character-level comparisons: The statements that are currently executed and the statements in the shared pool must be identical.
the objects referred to in B, two must be exactly the same:
C, two SQL statements must use the same name of the binding variable (bind variables).
4. Select the most efficient table name order (vali
Tags: des io ar using SP java for on dataVery good SQL statement optimization 34 article1) Select the most efficient table name order (valid only in the rule-based optimizer):The ORACLE parser processes the table names in the FROM clause in a right-to-left order, and the FROM claus
the database (that is, files on the hard disk)The data in the disk can only be achieved through the instance, and files on the hard disk cannot be directly read.
Differences:An instance can operate databases. At any time, an instance can only be associated with one database. In most cases, only one instance can operate on a database.
3. Note
The SQL language is case insensitive, but the words in the where
indicates passing the test. If the value is less than 60, it indicates failing.Display format:Chinese, mathematics, and EnglishPass excellent fail------------------------------------------Select(Case when language> = 80 then 'excellent'When language> = 60 then 'pass'Else 'failed') as language,(Case when mathematics> = 80 then 'excellent'When mathematics> = 60 then 'pass'Else 'failed') as mathematics,(
statement syntax
The code is as follows
Copy Code
case [Expression]When Condition_1 THEN result_1When Condition_2 THEN result_2...When Condition_n THEN result_nELSE resultEnd
expression is optional. It's worth the list of conditions that you compare. (ie: condition_1,condition_2, ... condition_n)
Condition_1 to Condition_n must be of the same data type. The order that
This afternoon colleagues asked me a more basic question, when splicing SQL statements, if encountered like the situation what to do.My original writing is a simple concatenation of strings, and later colleagues asked me what to do if I encountered SQL injection. I think about it, it's really a problem.Just on the Internet to find the relevant instructions, the original is so written.As such an
statements with simple statements. They are useful when you need to select rows from a table with data that depends on the table itself. You can put subqueries in many SQL clauses, including: WHERE clause, HAVING clause, FROM clause, CREATE VIEW statement, CREATE TABLE
SQL statement case when then else end returns a qualified value, sqlcase
Case has two formats
Simple Case functions and Case search functions:
-- Simple Case function
specifically responsible for data extraction in the server-side process. The function is to return the queried data results to the client process to complete the entire query.
Oracle SQL statement execution sequence
(8) SELECT (9) DISTINCT (11)
(1) FROM
(3) JOIN
(2) ON
(4) WHERE
(5) GROUP
(6) WITH {CUBE | ROLLUP}
(7) HAVING
(10) ORDER
1) FROM: Perform Cartesian
Oracle SQL statement Optimization
Although orm ing is used in the project, the optimization of the Oracle system is very valuable. Here we will summarize the commonly used statements from the perspective of SQL statements.
1. Optimization in the from field:
) b where a date=b. Date We might as well review the syntax of case.Case when there are two uses, one is similar to the example in the above simple cases function:Result ' wins '1' negative '20END There is also a case search function:Result=' win '1result=' Negative '20END Where result= ' wins ' can be replaced by other conditional expressions. If more than one case-when expre
Case has two formats. Simple case functions and case search functions.
-- Simple case Function Case Sex When '1' Then Male' When '2' Then Female' Else 'Others' End -- Case search function
> Salary When salary > Salary ELSE NULL End Salary_class,--alias name
COUNT (*)
From Table_a
GROUP by
Case when salary When salary > Salary When salary > Salary When salary > Salary ELSE NULL end;
3. Other implementations of If-then-else3.1 DECODE () function
Copy Code code as follows:
Select decode (Sex, ' M ', ' Male ', ' F ', ' Female ', ' Unknown ')
From employees;
It appears that only
Grammar:Case SelectorWhen Exp1 then Res1When Exp2 then Res2When Exp3 then Res3...[ELSE RESN]EndSql> Declare2 Mygrade char (1): = ' A ';3 res varchar2 (20);4 begin5 Res: =6 Case Mygrade7 when ' A ' and ' The mark is 90-100 '8 when ' B ' and ' The mark is 80-90 '9 when ' C ' and ' The mark is 70-80 'When ' D ' and ' The mark is 60-70 'Once ' E ' then ' the mark is 0-60 'The END;Dbms_output.put_line (RES);The end;15/The Mark is 90-100PL/
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.