Oracle analysis function PERCENTILE_CONT, percentile Function
Query the salaries of people with the salary distribution of 25%, 50%, and 75% in each department. percent_rank () is the relative position in the ranking.
Create table EMP(Empno number (4) not null,ENAME VARCHAR2 (10 ),JOB VARCHAR2 (9 ),Mgr number (4 ),Hiredate date,Sal number (7,2 ),Comm number (7, 2 ),Deptno number (2));Insert into emp (EMPNO, ENAME, JOB, MGR, HIREDATE, SAL,
Oracle Advanced query over (partition by...), advanced query ..
To facilitate learning and testing, all examples are created under Scott, an Oracle user.
create table EMP( empno NUMBER(4) not null, ename VARCHAR2(10), job VARCHAR2(9), mgr NUMBER(4), hiredate DATE, sal NUMBER(7,2), comm NUMBER(7,2), deptno NUMBER(2))alter table EMP add constraint PK_EMP primary key (EMPNO);insert into EMP (empno, ename, job, mgr, hiredate, sal,
necessary for our development, if we have no special needs. Let's say you've installed SQL Server, 2005 or 2008, and if you don't know how to install SQL Server, I recommend bing.com SQL Server 2005 installation diagram.So, the database is installed, the first thing is to create a database to connect it? OK, take a look at our example:Four: VideoNon-public section, please contact the best course (www.zuikc.com)Five: Create a sample databaseThe next step is to create our sample database, which w
employee is in. You can have a searched case statement can have many different when clauses, and so you can apply many the criteria in T Hose clauses to get the answers for you need.
Nullif and COALESCETo further comply with SQL 1999, the NULLIF and coalesce statements have been to added. The NULLIF statement is very simple. It takes two arguments. If they are equivalent, then the result is a NULL. If They are not equivalent, then the ' the ' the ' the ' the ' is ' argument by the function. Thi
Tags: Oracle overIn order to facilitate learning and testing, all examples are created under the Oracle's own user Scott.CREATE TABLE EMP ( empno number (4) Not null, ename NBSP;VARCHAR2 (Ten), job NB Sp NBSP;VARCHAR2 (9), Mgr number (4), hiredate date, sal number ( 7,2), Comm Number (7,2), deptno Number (2)) ALTER TABLE emp add constraint pk_emp Prim ary Key (EMPNO); insert into EMP (EMPNO, ename, Job, Mgr, HireDate, Sal,
digital format: century, year, month, day, hour, minute, second
The default date format is DD-MON-YY. You can use the sysdata function to obtain the current system date and time.
Calculation: The date type data can be directly added or subtracted by a number, and the result is that the date. The agreed value indicates the number of days of addition and subtraction.
The two date data types can be subtracted, and the result is how many days the two data types differ. No, because the addition of d
agreed value indicates the number of days of addition and subtraction.
The two date data types can be subtracted, and the result is how many days the two data types differ. No, because the addition of dates is meaningless.
NVL () function
Overview: it is used to replace null with the specified default value, applicable to character, number, date, and other types of data
Format: NVL (exp1, exp2) -- if the expression exp1 value is null, The exp2 value is returned; otherwise, the exp1 value is ret
exp2 value is returned; otherwise, the exp1 value is returned.Example: Select empno, ename, Sal, comm, Sal + nvl (Comm, 0) from EMP;Select empno, ename, job, nvl (job, 'no job yun') from EMP;
Nvl2 () functionOverview: it is used to implement the conditional expression function.Format: nvl2 (exp1, exp2, exp3) -- if the expression exp1 value is not null, The exp2 value is returned; otherwise, the exp3 val
two string types with "+" in Java.
5)
Select Replace (ename, 'A', 'A') from EMP;
Replace all 'A' in the ename field with 'A'. Of course, this replacement only applies to the display of the query results and will not be replaced in the database.
6) to_date Function
Insert into myemp values (7903, 'morflame', 'analyst', 7566, to_date ('2017-1-1 ', 'yyyy-mm-dd'), 1988, 2345.23, 20 );
The default date format of Oracle is '01-January-1988, so we can use this oracl
In Oracle functions in addition to character functions, date functions, mathematical functions, and conversion functions, and so on, there are some functions are common functions, such as: NVL, NVL2, Nullif, coalesce.Let's take a look at their usage:1.NVL functionNVL (EXPR1,EXPR2)If the data type of the EXPR1 and Expr2 is the same:If the expr1 is empty (null), then the EXPR2 is displayed,If the value of the EXPR1 is not empty, the expr1 is displayed. For example:Sql> Select ENAME,NVL (
Practice One:"Construct implementation environment----execute under any user"DROP TABLE DEPT;CREATE TABLE DEPT (DEPTNO number (2) CONSTRAINT pk_dept PRIMARY KEY,
Dname VARCHAR2, LOC VARCHAR2 (13)); DROP TABLE EMP;CREATE TABLE EMP (EMPNO number (4) CONSTRAINT pk_emp PRIMARY key,ename VARCHAR2 (Ten), job VARCHAR2 (9), mgr Number (4), hiredate date,sal number (7,2), comm number (7,2), deptno number (2) CONSTRAINT Fk_ DEPTNO REFERENCES dept); insert into
of 0.
Nvl data
Next region in the previous region to zookeeper
Nvl functions can convert null values into another item. If you want to calculate the total salary of each employee in the EMP table, the total salary is calculated by Sal + comm. You can calculate the total salary:
SQL> SELECT ENAME, SAL, COMM, (SAL + COMM) TOTAL_SALARY FROM EMP;
1. General method for calling a stored procedure
Assume that there is a stored procedure dt_users in SQL Server:
Create procedure [DBO]. [dt_users]
As
Select * from users
Return
Go
The first method is to directly use the recordset object without using the command object.
Set rs = server. Createobject ("ADODB. recordset ")
SQL = "Exec dt_users"
Rs. Open SQL, Conn ,.
The second method is to use the command object
Set comm = server. Createobject ("ADODB.
/* 1. Select all information about employees in department 30 */Select * from Scott. EMP where deptno = '30'/* 2. List the number and name of the employee whose position is Manager */Select empno, ename from Scott. EMP where job = 'manager'/* 3. Find out employees whose bonuses are higher than their salaries */Select * from Scott. EMP where comm> Sal/* 4. Find out the sum of each employee's bonus and salary */Select ename, Sal + nvl (
Phase III
Q. Use a REF CURSOR to display the values in the EMP table.
A.
DECLARE
TYPE Emprectyp is record
(
EMPNO Emp.empno%type,
Ename Emp.ename%type,
JOB Emp.job%type,
MGR Emp.mgr%type,
HireDate Emp.hiredate%type,
SAL Emp.sal%type,
COMM Emp.comm%type,
DEPTNO Emp.deptno%type
);
TYPE Emp_cursor is REF cursor return emp%rowtype;
Vemp_cur Emp_cursor;
Vemp_rec Emprectyp;
BEGIN
OPEN vemp_cur for SELECT * from EMP;
LOOP
FETCH vemp_cur
data will become the redundant data of the first picture (this point is universal, but not absolute, depending on the format of the picture), thereby following the "person info successfully retrieved! "The information is naturally not shown, because the information is already encoded in the image file.
2, the right way
A, the image into the database, the following is a picture into the database code snippets: (Complete demo program See appendix I)
FileStream Fs=file.openread (Filepath.tex
/*--The following code is the display width setting for the EMP tableCol empno for 9999;Col ename for A10;Col job for A10;Col Mgr for 9999;Col hiredate for A12;Col Sal for 9999;Col Comm for 9999;Col deptno for 99;Set pagesize 20;--Create a new table new_emp, copy the structure and data from the EMP table into the New_emp tableCREATE TABLE XXXAsSELECT * from EMP;--Delete xxx tabledrop table xxx Purge;*/The Oracle database server consists of two parts:A
Oracle analysis function PERCENTILE_CONT
Query the salaries of people with the salary distribution of 25%, 50%, and 75% in each department. percent_rank () is the relative position in the ranking.
Create table EMP(Empno number (4) not null,ENAME VARCHAR2 (10 ),JOB VARCHAR2 (9 ),Mgr number (4 ),Hiredate date,Sal number (7,2 ),Comm number (7, 2 ),Deptno number (2));Insert into emp (EMPNO, ENAME, JOB, MGR, HIREDATE, SAL,
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.