To create a function:format:Create or Replace function func ( parameter parameter type )Return numberIsBegin-------- business logic ---------End;--Create a functionCreate or Replace functionFunc (DNO Number)return Number isT_max Number;begin Select Max(SAL) intoT_max fromEMP TwhereDeptno=DNO; returnT_max;End ;--examples of calling stored procedures and calling functions (differences)DeclareT_maxsal Number;begint_maxsal:=FuncTen); Dbms_output.put_l
This is an oracle-defined function. how can we convert it to mysql worker (in_taskIdvarchar2, in_work_novarchar2) returnvarchar2isv_sumnumber (10); -- Average quality inspection completion quantity v_numNUMBER (10 ); -- individual QC completion quantity v_qualitied_cntNUMBER (10); v_resultvarchar2 (20); -- 0 exception, 1 is higher than the average... mysqloracle functions
This is a custom
Oracle provides the following explanations for ASCII and CHR functions:ASCII (x) gets the ASCII value of the character X, CHR () and ASCII () have the opposite effect.That is, the ASCII function is used to convert characters into their corresponding ASCII code, while the CHR function is opposite;Here are some simple examples:Select ascii ('x'), ASCII ('y'), ASCII ('Z') from dual;The statement execution result is 120,121,122 (the ASCII code correspondi
deleted. In the actual business, can be used to delete some of the exception data, such as Table A field t_no represents a telephone number, and the phone number itself should be a string consisting of numbers, in order to delete those containing non-numeric exception data, I used the Translate function: SQL> Delete fromA,whereLength (Translate (Trim (a.t_no),'0123456789' ||A.t_no,'0123456789'))Length (Trim (a.t_no));2.ReplaceSyntax:REPLACE(Char, search_string,replacement_string) Us
Tags: toolbar alt code infinite RAC Hive--SRC commI. Getting started with Oracle analytics functionsWhat is an analytic function?Analytic functions are powerful functions that Oracle specifically uses to address the statistical re
is the number of strings returned, and if this number is shorter than the length of the original string, the Lpad function will intercept the string as a left-to-right n character;Pad_stringOptional parameter, this string is to be pasted to the right of the string, if this argument is not written, the Lpad function will paste a space on the right side of the string.Rpad (' Tech ', 7); will return ' tech 'Rpad (' Tech ', 2); will return ' Te 'Rpad (' Tech ', 8, ' 0 '); will return ' tech0000 'Rp
As a result of project requirements, SQL Server must be converted to Oracle, some SQL Server views using the IsNull function, the following several Oracle functions and IsNull have a similar effect:
NVL (EXPR1,EXPR2) If EXPR1 is null, returns the value of EXPR2, otherwise returns the value of EXPR1
NVL2 (EXPR1,EXPR2,EXPR3) If EXPR1 is null, returns the value of
SQL single-row functions in Oracle databases-numeric Functions1. trigonometric FunctionsSIN ASIN SINHCOS ACOS COSHTAN ATAN TANHFor the above trigonometric functions, see the name. Do a continuous exercise [SQL] select sin (2), asin (1), SINH (1) from dual;Select cos (1), ACOS (0.5), COSH (0.5) FROM dual;Select tan (1), atan2 (2, 1), tanh (2) from dual; the above
the X field type SQL>SelectMax (distinct Sal), Max (XM) fromTable3; Max (distinctsal) max (XM)---------------- --------5555.55zhumin ([Distinct|all]x) The maximum value of the row x column is selected in the function statistics table. The "parameter" all means the maximum value for all values, distinct only the maximum value for the different values, the default is all if there is a parameter distinct or all, a space is separated from the X (column). "Parameter" x, can be numeric, character, or
The use of the--oracle trunc () function/************** Date ********************/1.select trunc (sysdate) from dual--2013-01-06 today's date is 2013-01-062.select trunc (sysdate, ' mm ') from dual--2013-01-01 returns the first day of the month.3.select trunc (sysdate, ' yy ') from dual--2013-01-01 returns the first day of the year4.select trunc (sysdate, ' DD ') from dual--2013-01-06 return current month day5.select trunc (sysdate, ' yyyy ') from dua
ncharactersreturned is used to specify the number of characters returned, by default returning all characters before the value of the character expression ends.3. Example: STORE ' abcdefghijlkm ' to mystringSUBSTR (mystring, 1,5) displays "ABCDE" 1 characters that are truncated from the first character, including the first characterSUBSTR (mystring, 6) show "FGHIJKLM"SUBSTR (mystring,-2) shows "km" the rightmost character is-1, the rightmost left character is-2, then the default is left to take
, ' W ') from DUAL; -April 26, 2011 is the 4th week The first few days of DDD year. January 1 is 001, February 1 is 032SELECT to_char (sysdate, ' DDD ') from DUAL; DD Day of the monthSELECT to_char (sysdate, ' DD ') from DUAL; Days within D weekSELECT to_char (sysdate, ' D ') from DUAL; DY week abbreviation for the first daySELECT to_char (sysdate, ' DY ') from DUAL; HH or HH12 12 hours of inputSELECT to_char (sysdate, ' HH ') from DUAL; HH24 24-hour systemSELECT to_char (sysdate, ' HH24 ') from
--------------------------------------------------------------------------------------------------------------- -------------Advanced grouping functionsGROUP BY rollup (A,B,C)Select A,b,c,sum (d) from test Group by rollup (A,B,C)The columns after rollup are grouped by one column from right to left until all columns are removed (that is, the whole table is grouped)For rollup of n parameters, there are n+1 sub-groupsThat is, by a,b,c, grouping, union all, and Grouping union all A to group union f
use of functions and cursors in Oracle
--Creates a function and invokes the CREATE function fun1 (v_in_ename varchar2) return number is v_annual_sal number;
Begin Select (SAL+NVL (comm,0)) *13 into V_annual_sal from EMP where ename=v_in_ename;
return v_annual_sal;
End
/-Direct Call function var v_annual_sal number;
Call Fun1 (' FORD ') into:v_annual_sal;
Print v_annual_sal; --Package--demand: Write a pa
Oracle has two functions: lead and lag, which are the analytic functions used to compute offsets, and the two functions are the same in use.
The Oracle official documentation explains:
The lead is a
'Select Replace('000123','0') fromDual--The returned result is ' 123 ' NOTE: Omit the parameter replacement_string, replace the character ' 0 ' with null, i.e. delete all characters ' 0 '4. String connectionconcat (string1, string2) or ||Cases:Select concat (','World' from dual; -- returns the result as ' Hello world ' Select ' '| | ' World ' from dual; -- returns the result as ' Hello world '5. Get the string lengthLength (String)Cases:Select Length ('from- - Returns a result of 76, stri
Single-record functions in SQL1.ASCIIReturns the decimal number corresponding to the specified character;Sql> Select ASCII (' a ') a,ascii (' A ') a,ascii (' 0 ') zero,ascii (') space from dual;
A A ZERO space--------- --------- --------- ---------65 97 48 32
2.CHRGive an integer and return the corresponding character;Sql> Select Chr (54740) ZHAO,CHR () chr65 from dual;
En C-- -Zhao A
3.CONCATConnect two strings;Sql> Select Concat (' 010-', ' 8888
Oracle has two functions: lead and lag, which are the analytic functions used to compute offsets, and the two functions are the same in use.
The Oracle official documentation explains:
The lead is a
policy that tells Oracle to arrange, and First/last tells the criteria for the final filter.
4th question: What if we change Dense_rank to rank?
Copy Code code as follows:
sql> Select min (region_id)
Keep (rank order by sum (customer_sales) desc)
Min (region_id)
Keep (rank last order by sum (customer_sales) desc) Last
From User_order
Group BY region_id;
Select min (region_id)
*
ERROR at line 1:Ora-02000:missing D
Question: Collect Oracle knowledge points that are commonly used at work, constantly update and accumulate, and use them as your own notebook.
Some keywords
1Is not null. Check whether the field is null.
Select*FromT_user uWhereU.NameIsNotNull
2 Case when... THEN... ELSE... END, Condition Statement
SELECTCASEWHEN'Condition'ISNOTNULLTHEN'Condition exist'ELSE'The condition is invalid'ENDASResultFROMT_user
3 EXITS, not exits, to determine whet
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.