As used herein, it is Oracle 10g database, using the PL / SQL Developer integrated development environment (installation can be self Baidu)
the Oracle Database ---> database instance ---> tablespaces (logical units) (user) ---> Data File (physical units)
can be interpreted as below
the Earth ---> a country ---> provinces (logical unit) (citizen) ---> mountains and rivers (physical units)
typically, Oracle database will be only one instance ORCL,
create a new project:
MYSQL: create a database, create a corresponding table
Oracle: create a table space, create users, to create table
Oracle and MYSQL difference between
Oracle is a multi-user, multi-MYSQL database
1. follow the SQL standard
2 different manufacturers, different database products, but have their own dialect
3. use their own dialect, can perform the same function
4. Oracle security level is higher, MYSQL open source free
* from Tab SELECT; / * Database ---> database instance ---> tablespaces (logical units) (user) ---> data file (physical units) of a country earth ---> ---> Department ( logical units) (citizen) ---> mountains and rivers (physical unit) normally, ORacle database will be only one instance ORCL, a new project: MYSQL: create a database, create a corresponding table Oracle: create a table space, create a user, the user to create tables Oracle and MYSQL difference between Oracle is a multi-user, multi-MYSQL database 1. follow the SQL standard 2 different manufacturers, different database products, but have their own dialect 3. use their own dialect, can do the same thing 4. Oracle security level is higher, MYSQL open source free * / / * basic query: SQL: structured query language Please listen to the question: Tell me about the classification and each type of SQL operators What are common four categories: DDL: data Definition language drop the ALTER TRUNCATE the Create DML: data manipulation language Update the Delete INSERT DCL: data control language grant revoke authorization safety DQL: select from data query language clause where clause of the query structure: SELECT [Column Name] [*] from table [where Condition] [group by grouping condition] [HAVING filter] [order by sorting] * / SELECT from EMP *; SELECT +. 1. 1; - the Oracle being given equal, the output is in MYSQL 2 / * Dual: Oracle the virtual table, a pseudo-table, a syntax structure is mainly used padded * / SELECT. 1. 1 + Dual from; the SELECT * from Dual; the SELECT 1 from emp; - often a direct write * to write efficient than the SELECT COUNT from emp (1); the SELECT COUNT (*) from emp; / * alias query: use as keywords, can be omitted alias can not have special characters or keywords, if you double quotes * / the SELECT ename name, sal emp wages from; the SELECT ename "name", sal emp wages from; / * remove duplicate data distinct multi-column to remove duplicate: each column is repeated as to be able to count * / - single row remove duplicates SELECT DISTINCT Job from EMP; - a plurality of rows of deduplication SELECT DISTINCT Job, DEPTNO from EMP; - four arithmetic query SELECT. 1. 1 + from Dual; - - Polling staff salary = monthly 12 * the SELECT SAL * 12 from emp; - inquiry staff salary + bonus the SELECT SAL + COMM 12 * from emp; --nvl function: 1 if the argument is null is returned parameter 2 the SELECT SAL * 12 + NVL (COMM, 0) from EMP; / * NOTE: null value, representative of an ambiguous unpredictable, four arithmetic operations can not be done * / / * string concatenation: Java: number + stitching Oracle-specific connector: | | stitching in Oracle, mainly double-quotes when using an alias, single quote is the value used is the character concat (str1, str2) function, in both the mysql and Oracle * / - query the employee name: name: SCOTT ename from EMP SELECT; - spliced character select 'Name:' || ename from EMP; - the name of the query in a range of employee information ( 'JONES', 'SCOTT' , 'FORD') in - splicing using the function select concat ( 'Name:', ename) from EMP; / * Condition Query: [where the latter wording] relational operators:>> = = <<= = <!> Logical operators: and or not other operators: like fuzzy query in (set) in a set between .. and .. in a certain interval is null is empty is determined is not null determined not empty * / - can query a monthly bonus employee information the SELECT * from emp the WHERE COMM iS not null; - query wage employee information between 1500--3000 the SELECT * from emp the WHERE SAL the bETWEEN 1500 and 3000; the SELECT * from emp the WHERE SAL> = 1500 and SAL < 3000 =; SELECT * from EMP WHERE ename in ( 'JONES', 'SCOTT', 'FORD'); _ matches a single character 'JONES', 'SCOTT', 'FORD'); if there are special characters, use the escape escaping * / / * Fuzzy query: like % with a character - queries employee name first three characters are O employee information the SELECT * from emp the WHERE ename like '__O%'; - employee name query, the information contained percent of employees select * from emp where ename like ' % \ %%' escape '\'; * from EMP WHERE ename SELECT like '% # %%' Escape '#'; / * Sort: order by ascending: asc ascend descending: desc descend Sort problem null Note: nulls first | last simultaneously arranged in a plurality of rows, separated by commas * / - query employee information, in accordance with the bonus descending sorting select * from emp order by comm desc nulls last; - Query department number and wages in accordance sorted by department ascending, descending sort wages DEPTNO SELECT, SAL by DEPTNO from EMP Order ASC, SAL desc; / * Function: The return value must be one-way function: on a value in a row is processed numerical function character function date function conversion function general functions multi-line functions: process all rows of a column max () min COUNT sUM AVG 1. simply ignore null values * / - the sum of wages and salaries statistics the SELECT sUM (SAL) from emp; - the sum of the statistical employee bonus 2200 the SELECT sUM (COMM) from emp; - statistics number of employees 14 the SELECT COUNT (1) from emp; - an average of 550 employees bonuses statistical error = 2200/14 the SELECT AVG (COMM) from emp; - the statistical average bonuses of employees 157. the the SELECT SUM (COMM ) / COUNT (from EMP. 1); SELECT ceil (SUM (COMM) / COUNT (. 1)) from EMP; Update EMP SET ename = '% TUR the NER' WHERE ename = 'TURNER'; select * from emp; --数值函数 select ceil(45.926) from dual; --46 select floor(45.926) from dual; --45 --四舍五入 select round(45.926,2) from dual; --45.93 select round(45.926,1) from dual; -- 45.9 select round(45.926,0) from dual; --46 select round(45.926,-1) from dual; --50 select round(45.926,-2) from dual; --0 select round(65.926,-2) from dual; --100 --截断 select trunc(45.926,2) from dual; --45.92 select trunc(45.926,1) from dual; -- 45.9 select trunc(45.926,0) from dual; --45 select trunc(45.926,-1) from dual; --40 select trunc(45.926,-2) from dual; --0 the trunc SELECT (65.926, -2) from Dual; --0 --求余 select mod(9,3) from dual; --0 SELECT MOD (9,4) from Dual; --1 - Character Function - substr (str1, start index, length) - Note: The starting index Whether writing is 0 or 1, taken from the first character SELECT substr ( 'ABCDEFG', 0,3) from Dual; - ABC SELECT substr ( 'ABCDEFG', l, 3) from Dual; - ABC SELECT substr ( 'ABCDEFG', 2,3) from Dual; --bcd - Get string length 28 24 SELECT length ( 'ABCDEFG') from Dual; - removing space characters on both sides of the left and right select trim ( 'hello') from dual ; - replacement string the Select replace ( 'Hello', 'L', 'a') from Dual; - date function - to today's date query SELECT SYSDATE from Dual; - query today's date, three months after select add_months (sysdate, 3) from dual; - Query 3 days after the date of select sysdate + 3 from dual; - Polling staff recruited days the SELECT sysdate - the HireDate from emp; the SELECT ceil (sysdate - the HireDate) from emp; - Query hires a number of weeks the SELECT (sysdate - the HireDate) / 7 from emp; - Query hires month the number of the SELECT MONTHS_BETWEEN (sysdate, the HireDate) from emp; - query hires year the SELECT MONTHS_BETWEEN (sysdate, the HireDate) / 12 from emp; - conversion function numerical value date transfer switch characters characters - characters turn value to_number (str) tasteless select 100 + '10 'from dual; --110 default has helped us convert the SELECT 100 + to_number ('10') from Dual; - 110 - numeric characters turn select to_char (sal, '$ 9,999.99 ') from emp; TO_CHAR SELECT (SAL, 'L9,999.99') from EMP; / * TO_CHAR (1210.73, '9999.9') return '1210.7' TO_CHAR (1210.73, '9,999.99') returns' 1,210.73' to_char (1210.73, '$ 9,999.00' ) return '$ 1,210.73' TO_CHAR (21 is, '000099') return '000021' TO_CHAR (852, 'XXXX') return '354' * / - Date revolution character TO_CHAR () SELECT TO_CHAR (SYSDATE , 'mm-dd-YYYY HH: mi The: SS') from Dual; select to_char (sysdate, 'YYYY-mm-dd HH24: mi The: SS') from Dual; - you want in select to_char (sysdate, ' yyyy ') from Dual; --2 017 - just want the date select to_char (sysdate,' d ' ) from dual; --2 represents a day of the week select to_char (sysdate,' dd ' ) from dual; - -10 represents the first few days of the month select to_char (sysdate, 'ddd' ) from dual; --100 represents the first day of the year the SELECT the TO_CHAR (sysdate, 'Day') from Dual; --monday the SELECT the TO_CHAR (sysdate, 'dy') from dual;--mon week shorthand - character transfer date to_date the SELECT ( '2017-04-10', 'yyyy-mm-dd') from Dual; - Query 1981 --1985 annual income recruits information select * from emp where hiredate between to_date ( '1981', 'yyyy ') and TO_DATE (' 1985 ',' YYYY '); / * generic function: NVL (parameter 1, parameter 2) If parameter 1 = null return parameter 2 NVL2 (parameter 1, parameter 2, parameter 3) If parameter 1 = null, 3 returns to the parameter, the parameter 2 otherwise NULLIF (parameter 1, parameter 2) If parameter 1 = 2 then return null parameter, otherwise parameter 1 COALESCE: returns a non-null value * / SELECT NVL2 (null, 5,6) from Dual; --6; SELECT NVL2 (1,5,6) from Dual; --5; SELECT NULLIF (5,6) from Dual; --5 SELECT NULLIF (6,6) Dual from; --null SELECT COALESCE (null, null, 3,5,6) from Dual; --3 SELECT ceil (-12.5) from Dual; --12 SELECT Floor (12 is.5) from dual; --12 select ' hello ' from dual; select * from emp;