Label:To create a function: Create or Replace function My_fun (in_no in number) return VARCHAR2 isOut_name VARCHAR2 (64);BeginSelect Ename to Out_name from EMP where emp.empno=in_no;return out_name;End My_fun; Java Program Demo: Import java.sql.CallableStatement;Import java.sql.Connection;Import Java.sql.DriverManager;Import java.sql.SQLException;Import Java.sql.Types; public class Javacallmath {public static void Main (string[] args) {String driver= "Oracle.jdbc.driver.OracleDriver";String ur
Syntax Overview
Analytic-Function
PARTITION clause of Analytic_Clause
Order by clause of Analytic_Clause
Analyze wing clause of Analytic_Clause
Example:
The following is an example of a simple Syntax:
Example:Sum (sal) over (partition by deptno order by ename) new_aliasSum is the function name.(Sal) is the parameter of the analysis function. Each function has 0 ~ Three parameters, which can be expressions, such as sum (sal + comm)Over () is a wi
Syntax Overview
Analytic-Function
PARTITION clause of Analytic_Clause
Order by clause of Analytic_Clause
Analyze wing clause of Analytic_Clause
Example:
The following is an example of a simple Syntax:
Example:Sum (sal) over (partition by deptno order by ename) new_aliasSum is the function name.(Sal) is the parameter of the analysis function. Each function has 0 ~ Three parameters, which can be expressions, such as sum (sal + comm)Over () is a w
Label:Oracle provides analytic functions starting from 8.1.6, which are used to calculate some sort of aggregate value based on a group, which differs from aggregate functions in that multiple rows are returned for each group, whereas aggregate functions return only one row for each group.Grammar: SQL code
Syntax for building functionsCreate or Replace function name (parameter input or output parameter type) return data typeis return value data type of return valueBeginAction to be done by the functionEndSQL Statement Demo:Create or Replace function My_fun (in_no in number) is Out_name VARCHAR2 (64);BeginSelect Ename to Out_name from EMP where emp.empno=in_no;return out_name;End My_fun;Note: There is no longer end my_fun and end;Function call:DeclareVar_name VARCHAR2 (32);BeginVar_name:=my_fun (73
Common Oracle functions: nvl/nullif/case when/wm_concat/replace 1. nvl function nvl converts a null value to an actual value. The data type can be date, number, character, and data type must match: nvl (commision, 0) nvl (hiredate, '01-JAN-87 ') nvl (job_id, 'no manager') nvl (to_char (job_id), 'no manager') nvl can convert any data type, however, the returned value of the converted data type must be of the
Emp.salary DESC1. Basic Concept UnderstandingAnalytic functions1. As the name implies, the analysis function is the main query results based on a certain analysis, such as sub-departmental summary, sub-departments to find the average value and so on. Data window1. Oracle analysis functions are built on the so-called Data window, which can be understood as a data set. The data of the main query can be divid
Oracle broadly divides functions into single-line functions, aggregate functions, and analytic functions.Single-line functions are divided into character functions, date
ORACLE Advanced Function Application
--Grouping functions
1, ROLLUP
--Subtotal, total of statistical standard grouping and corresponding dimensions
The Oracle GROUP BY statement also supports rollup and cube statements in addition to the most basic syntax. In the case of rollup (a, B, c), group by IS first performed on (A, B, c), then group BY, then (a) for group
Tags: style class blog Code java HTTPabout several Oracle functions that handle the number of decimal places ()1. Take a few decimals roundedSelect round(1.2345,3) fromdual; Results:1.2352. Keep two decimal places, onlySelectTrunc1.2345,2) fromdual; Results:1.23SelectTrunc1.2399,2) fromdual; Results:1.233take an integer to return the largest integer greater than or equal to x: SQL> SelectCeil (23.33
Functions in oracle are divided into character functions, number functions, date functions, empty processing functions, conversion functions, and other common
Label:This article describes Oracle Analytic function usage, first building the library:SQL code
CREATE TABLE earnings --working Money table
(
Earnmonth VARCHAR2 (6), --Working month
Area VARCHAR2 (a), --working areas
Sno Varchar2 (Ten), --migrant worker number
Sname Varchar2 (a), --the name of the working person
times int, --Number of jobs this month
Singleincome number (10,2),
rollup The first column of the grouping is counted and the last subtotal cube the statistics and the final subtotal of all the columns grouped by select deptno,job, sum (SAL) from the EMP Group by Rollup (Deptno,job); cube generate statistics and final subtotals for all columns in the group select Deptno, Job, SUM (SAL) from the EMP Group by Cube (deptno,job); See also: http://www.javaeye.com/topic/201757Vii. Temporary tablesA table that exists only during a session or during tr
There are 3 kinds of analytic functions commonly used by Oracle for sorting, rank (), Dense_rank (), row_number ();
The test table is as follows:
1, rank () Jump ranking
With temp as
(
Select T_id,t_age, rank (t_age desc) sec from AAA
)
SELECT * FROM Temp
--where sec=1--, Plus this filter, you can find records that are ranked 1
If you specify a group
Oracle's analytic functions are very powerful and have been used frequently over the years. This time you will often use the analysis function to sort out, for future viewing.
It's easier to understand that we learn from cases.
1, build the table
CREATE TABLE earnings----Working Money Table
(
earnmonth varchar2 (6),--Working month
area VARCHAR2 (20),--wage-earners
Sno VARCHAR2 (1 0),--migra
The analysis function calculates the aggregation value based on a row set. Different from the aggregate function, the analysis function returns multiple rows. Except for the last orderby clause, the analysis function is in a query.
The analysis function calculates the aggregation value based on a row set. Different from the aggregate function, the analysis function returns multiple rows. Except for the last order by clause, the analysis function is a query.
) | |' from Tb_index t ' from User_tab_columns where table_name= ' Tb_index '; Sys_connect_by_path (ColumnName, seperator): Used to construct a tree path, so it needs to be used with connect by. The main function of the Sys_connect_by_path function is that all child nodes under a parent node can be distinguished by a character, and then the connection is displayed in a columnSelect T.areaid, T.parentareaid, T.areaname, Sys_connect_by_path (T.areaname, '-') area from Tb_index t Start with t.arean
Tags: ORDER by 0.00--Between data xxx TNO sel differentThe lag and the lead function are two analytic functions that are related to the offset, through which we can take the value of the offset n rows of the current row and column, and the lag can be looked at as positive upward offset the lead can be considered a negative downward offset specifically we look at a few examples:Let's look at two columns of S
Label:Oracle's analytic functions are powerful, and work is often used over the years. This time, the usual analysis functions are sorted out for later viewing. We learn by taking cases, so it's easier to understand them.1. Build a table CREATE table earnings--Working Money Table
(
earnmonth varchar2 (6),--Working month
area VARCHAR2 (20),--working area
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.