1. Password Management Interface
Super administrator account: sys-change_on_install; General administrator: system-manager; [Unlock] Ordinary users: scott-tiger; [Unlock] large data users: sh-sh
2. If you want to uninstall oracle requires three steps
. A uninstall program provided by Oracle; . B enter the registry (regedit.exe), and then delete the Oracle-related configuration items; c. Restart the computer into safe mode, remove all Oracle files
3. After the installation is complete, close the boot from Kai
Oracle in the computer management service all changed [manual] start, a total of eight, two are disabled OracleVssWriterMLDN、OracleDBConsolemldn、OracleMTSRecoveryService OracleOraDb11g_home1ClrAgent、OracleOraDb11g_home1TNSListener、OracleServiceMLDN
4. reduced input: in dos window, enter sqlplus scott / tiger
If you want to know the current login account, which one: show user; Switch account: conn username [/ password] [AS SYSDBA]; If you use the super administrator, you must append "AS SYSDBA" The switching system to account: conn system / manager; Switching to the sys account: conn sys / change_on_install AS SYSDBA; Clear screen: clear scr Each line of the display data length: set linesize length of each line (300); Showing data length set: set pagesize length of each line (30); If no graphical interface, so you can execute SQL statements; edit xx (generate a file of xx.sql) Then @xx, written statement can be executed. In this way you can also perform @ absolute path \ xx, Calls the native command: host copy d: \ a.sql d: \ b.sql
5. SQL Syntax Standard
DML (Data Manipulation Language): Specific database operations, the CRUD four forms, is the most commonly used query; DDL (Data Definition Language): definition of database objects, tables, user index; DCL (Data Control Language): the user's authorization management
. 6 . Scott subscriber data table
View the data sheet with select * from tab; View table structure desc name of each table; Four tables: Department table (dept), the employee table (emp), wage scales (salgrade), payroll (bonus) Oracle's date there is time, MySQL only date Data table structure -emp (the employee table) EMPNO NUMBER (4) Number of employees ENAME VARCHAR2 (10) Name of the employee JOB VARCHAR2 (9) the employee's position MGR NUMBER (4) Number of employees leadership HIREDATE DATE hire date SAL NUMBER (7,2) basic wage COMM NUMBER (7,2) commission, commission only sales only DEPTNO NUMBER (2) where the department number
7. coding conventions: a fixed syntax in uppercase letters, lowercase letters replaceable part.
SELECT [DISTINCT] * | column name [alias] DISTINCT: eliminate duplicate rows of data display View annual salary of employees, but such a display --sal * 12 does not look good, you can set an alias SELECT empno,ename,job,sal*15+(200+100)*12 FROM emp; SELECT empno,ename,job,sal*12 income FROM emp; DISTINCT: deduplicate, all data columns only allow the elimination of duplicate SELECT DISTINCT job FROM emp; Constant query: SELECT 'Employee information', 10, ename FROM emp; If a string is sure to use single quotes statement; If it is digital, you can write directly String left aligned, right aligned figures String concatenation: || plus sign corresponds to, once connected, there is only one data return SELECT 'Employee Name:' || ename || ', position:' || job FROM emp; SELECT 'Employee Name:' || ename || ', position:' || job info FROM emp; Simple query: Source FROM clause takes precedence over SELECT clause is executed to determine data
8. simple query is a control line, the control bar is defined query
WHERE clause common character is determined:>,> =, <, <=, =, <>, =, in! Queries salary in the range of 1000 to 1500, non-sales staff empno, ename, job, sal SELECT empno,ename,job,sal FROM emp WHERE sal>=1000 AND sal<=1500 AND job!='SALESMAN';
9. The scope of the query: BETWEEN ... AND
a. range query with a limit value b. can be used on various types of data Example: Query all employee information in 1981 hired 1981 Employment: 1981-01-01 ('01 - January -1981 ') ~ 1981-12-31 ('31 - December -1981') SELECT * FROM emp WHERE hiredate BETWEEN '01-JAN-1981' AND '31-DEC-1981';
10. Empty judgment: IS NULL, IS NOTNULL
In the database is called an indeterminate contents, if you use null, any results are null Example: query for all employees to receive employment information is not gold SELECT * FROM emp WHERE comm IS NULL;
11. Fuzzy query: LIKE
LIKE can be achieved using the search key, then the operator provides two matcher: "_": Means match any one character; "%": That match any of 0, 1, a number of characters. Example: employee name query information to all employees starting with A SELECT * FROM emp WHERE ename LIKE 'A%'; Example: query employee information employee names in the second letter is A SELECT * FROM emp WHERE ename LIKE '_A%'; Replace the previous BETWEEN ... AND SELECT * FROM emp WHERE hiredate LIKE '%-81';
12. Range queries: IN, NOT IN
Example: Query the employee number of employee information 7369,7566,7788,9999 SELECT * FROM emp WHERE empno IN (7369,7566,7839,9999); If NOT IN appears in a null program is certainly a problem, if there are null, the query is not, nor return any data SELECT * FROM emp WHERE empno NOT IN (7369,7566,7839,NULL);
13. Query sorts
③SELECT [DISTINCT] * | column name [alias], the column name [alias], ... | data calculation ①FROM Data Sheet [alias] ② [WHERE defined conditions (S)] ④ [ORDER BY sort field [ASC | DESC], sort fields [ASC | DESC], .....]; SELECT clause is executed after the WHERE clause, so the WHERE clause can not use an alias in the SELECT clause defined. ASC: ascending order, default to this mode; DESC: Descending SELECT * FROM emp ORDER BY sal DESC; Example: query information for all employees, in accordance with the requirements of the sort from high to low wages, if wages in accordance with the same hire date from morning till night sorting SELECT * FROM emp ORDER BY sal DESC , hiredate ASC; Query information is sector employees 10 and 20, ... SELECT * FROM emp WHERE deptno IN (10,20) ORDER BY sal DESC,hiredate ASC; ORDER BY with SELECT alias SELECT empno,ename,sal*12 income FROM emp ORDER BY income DESC ;
14. A one-way function
String functions: turn uppercase UPPER, LOWER small letter SELECT * FROM emp WHERE ename=UPPER('&inputname'); SELECT LOWER(ename) FROM emp; Capitalized: String INITCAP (data | column) SELECT INITCAP(ename) FROM emp; String length is calculated: digital lenth (data | column) SELECT * FROM emp WHERE LENGTH(ename)=5; String interception: string SUBSTR (data | column) Provided the specified index and length taken SELECT SUBSTR('helloworld',6,2) FROM dual; Index is set to 0, the default index starting with 1, are the same; can also be set to negative Example: An employee is required to intercept the names of the first three and last three letters SELECT ename,SUBSTR(ename,1,3),SUBSTR(ename,-3) FROM emp; String substitution: String REPLACE (data | columns of data to be replaced, the replacement data) SELECT REPLACE('helloworld','l','_') FROM dual; Does not make sense to use a direct entity table queries, you can use the virtual table --dual Numeric Functions ROUND (Data | column [, retain decimal places]): rounding TRUNC (data | column [, retain decimal places]): Data taken, no rounding, decimal directly taken out SELECT ename,job,TRUNC(sal/30) FROM emp; MOD (data | Column): Find the remainder Date function (to avoid the leap year problem), conversion functions, generic functions SELECT SYSDATE FROM dual; SELECT ADD_MONTHS(SYSDATE,4) FROM dual; There used to calculate the months between date1 and date2, if date1 date2 than later, it returns a positive number. MONTHS_BETWEEN (date1, date2) Date Format Conversion SELECT TO_CHAR(SYSDATE,'yyyy-mm-dd') FROM dual; NVL (): The first parameter is empty then display the value of the second parameter if the first parameter is not empty, then the first parameter value of the original. SELECT ename,sal,NVL(comm,0),(sal+NVL(comm,0))*12 income FROM emp; DECODE (): The results translated into other value
15. The multi-table queries with caution, was the elimination of the Cartesian product
Nature: After the written condition, go find another table with their relevant data only. SELECT * FROM emp,dept WHERE emp.deptno=dept.deptno; SELECT * FROM emp e, dept d WHERE e.deptno=d.deptno; Use two tables sales, costs for multi-table queries, due to the large amount of data, resulting in a very long time Example: query each employee number, name, salary, department name SELECT e.empno,e.ename,e.job,e.sal,d.dname FROM emp e,dept d WHERE e.deptno=d.deptno; Example: the query number, name, salary, wage levels per employee SELECT e.empno, e.ename, e.sal, s.grade FROM emp e,salgrade s WHERE e.sal BETWEEN s.losal AND s.hisal; Example: query each employee number, name, salary, salary grade, department name SELECT e.empno,e.ename,e.job,e.sal,s.grade,d.dname,d.loc FROM emp e , salgrade s,dept d WHERE e.sal BETWEEN s.losal AND s.hisal AND e.deptno=d.deptno;
16. The two kinds of table join
En: equijoins Example: Create a no department employee in the emp INSERT INTO emp(empno,ename) VALUES (9999,'HELLO'); At this point the connection query SELECT e.empno,e.ename,d.deptno,d.dname FROM emp e,dept d WHERE e.deptno=d.deptno; e.deptno = d.deptno (en) who does not satisfy this condition, it will not appear External connection: the data table records all displayed, left outer, right outer join, full outer join Left outer connector (field = fields (+)): Data requirements left table show all Right outer connector (field (+) = field): Data requirements right table show all Their connections: data associated with your own table Example: query each employee number, name, job title, the name of leadership SELECT e.ename,e.job,m.ename FROM emp e, emp m WHERE e.mgr=m.empno; All contents of the left table SELECT e.ename,e.job,m.ename FROM emp e, emp m WHERE e.mgr=m.empno(+);
17. The SQL1999 syntax
Cross-connect: CROSS JOIN, simple data table associated with the generated Cartesian product. SELECT * FROM emp CROSS JOIN dept ; NATURAL connection: NATURAL JOIN, the connection, automatically find use within the field of the same name connected to eliminate the Cartesian product. SELECT * FROM emp NATURAL JOIN dept ; USING clause: Set the fields you want to associate SELECT * FROM emp JOIN dept USING(deptno); ON clause: setting conditions associated SELECT * FROM emp e JOIN dept d ON(e.deptno=d.deptno); Left outer join, right outer join, full outer connection (with less) SELECT * FROM emp e LEFT OUTER JOIN dept d ON(e.deptno=d.deptno); SELECT * FROM emp e RIGHT OUTER JOIN dept d ON(e.deptno=d.deptno); SELECT * FROM emp e FULL OUTER JOIN dept d ON(e.deptno=d.deptno);
18. A set of treatments
[UNION | UNION ALL | MINUS | INTERSECT] UNION: The results of the collection together, but do not show the same parts SELECT empno,ename,job FROM emp WHERE deptno=10 UNION SELECT empno,ename,job FROM emp ; UNION ALL: repeat the display portion also MINUS: a difference set operation, a large collection of collection is reduced INTERSECT: intersecting operation, returns the same part
19. Statistics
() COUNT: Number of rows of tables, 0 if no data is returned, instead of blank COUNT(*)、COUNT(字段)、COUNT(DISTINCT) If the data on one column is not null, the COUNT (*) and COUNT (fields) as the result returned; If there are null, the COUNT (field) is not empty statistics data. SELECT COUNT(*),COUNT(mgr) FROM emp; If there are duplicate data on a column, when the statistics do not want to repeat, use COUNT (DISTINCT) SELECT COUNT(*),COUNT(DISTINCT job) FROM emp; SUM (), AVG (), MIN (), MAX ()
20. grouping queries
After the completion of a field divided according to the group, SELECT clause can only use some statistical functions SELECT deptno,COUNT(*),AVG(sal) FROM emp GROUP BY deptno; # Example: Query the name of each department, the number of average wage SELECT d.dname,COUNT(empno),AVG(sal) FROM dept d,emp e WHERE d.deptno=e.deptno(+) GROUP BY d.dname ; # Example: salary level of the employee queries, number, wages SELECT s.grade, e.empno, e.sal FROM salgrade s,emp e WHERE e.sal BETWEEN s.losal AND s.hisal; # Example: When there is repetition, can be grouped, query on a column for each pay grade, how many people, the highest wages SELECT s.grade,COUNT(e.empno),MAX(e.sal) FROM salgrade s,emp e WHERE e.sal BETWEEN s.losal AND s.hisal GROUP BY s.grade; # Example: Query department number, name, location, number of employees, wages SELECT d.deptno,d.dname,d.loc,e.empno,e.sal FROM dept d,emp e WHERE d.deptno=e.deptno(+) ; Is now repeated three together, uniform grouping operation can be performed in three columns, Only GROUP BY fields that appear to appear in the SELECT # Example: multi-table queries and packet statistics, query department number, name, location, number of people, the average wage SELECT d.deptno,d.dname,d.loc,COUNT(e.empno),AVG(e.sal) FROM dept d,emp e WHERE d.deptno=e.deptno(+) GROUP BY d.deptno,d.dname,d.loc;
21. The the HAVING clause
After filtering statistics packets required to achieve the HAVING clause SELECT job,COUNT(*),AVG(sal) FROM emp GROUP BY job HAVING AVG(sal)>1200; HAVING and WHERE difference WHERE: Before using the GROUP BY grouping of data packets to be screened are not allowed to use statistical functions HAVING: GROUP BY grouping after use, allow the use of statistical functions, screening for the data packet ⑤SELECT [DISTINCT] grouping field | Statistical Functions ①FROM Data Table 1 [alias], the data in Table 2 [alias], ... ② [WHERE defined conditions (S)] ③ [GROUP BY packet field, packet fields, ...] ④ [HAVING the packet filter] ⑥ [ORDER BY sort field [ASC | DESC], sort fields [ASC | DESC], .....];
22. The packet statistics case