Oracle数据库操作总结之一

/****************by Jiangong SUN***************/

 

RDBMS(Relational Data Base Management System)


ER图(Entity Relationship)

 

Primary key主键
Foreign key外键

 

Data Definition Language (DDL) statements are used to define the database structure or schema.
数据定义语言,用于管理数据库结构
    * CREATE - to create objects in the database
    * ALTER - alters the structure of the database
    * DROP - delete objects from the database
    * TRUNCATE - remove all records from a table, including all spaces allocated for the records are removed
    * COMMENT - add comments to the data dictionary
    * RENAME - rename an object


Data Manipulation Language (DML) statements are used for managing data within schema objects.
数据操作语言,用于管理数据库对象的数据。
    * SELECT - retrieve data from the a database
    * INSERT - insert data into a table
    * UPDATE - updates existing data within a table
    * DELETE - deletes all records from a table, the space for the records remain
    * MERGE - UPSERT operation (insert or update)
    * CALL - call a PL/SQL or Java subprogram
    * EXPLAIN PLAN - explain access path to data
    * LOCK TABLE - control concurrency


Data Control Language (DCL) statements.
数据控制语言
    * GRANT - gives user's access privileges to database
    * REVOKE - withdraw access privileges given with the GRANT command
Transaction Control (TCL) statements are used to manage the changes made by DML statements. It allows statements to be grouped together into logical transactions.


事务控制语言
    * COMMIT - save work done
    * SAVEPOINT - identify a point in a transaction to which you can later roll back
    * ROLLBACK - restore database to original since the last COMMIT
    * SET TRANSACTION - Change transaction options like isolation level and what rollback segment to use

 

SQL vs. iSQL*Plus:
iSQL*Plus是一个browser环境,Oracle特有。
通过http://xxx:5560/isqlplus/访问。
Where:
SELECT last_name, salary
FROM   employees
WHERE  salary <= 3000 ;
SELECT last_name, salary
FROM   employees
WHERE  salary BETWEEN 2500 AND 3500 ;
SELECT employee_id, last_name, salary, manager_id
FROM   employees
WHERE  manager_id IN (100, 101, 201) ;
SELECT first_name
FROM   employees
WHERE  first_name LIKE 'S%' ; //%代表了0到多个字符
SELECT first_name
FROM   employees
WHERE  first_name LIKE '_o%' ; //_代表了1个字符
SELECT employee_id, job_id
FROM employees
WHERE job_id LIKE 'SA/_R%' ESCAPE '/'; // Escape符/
SELECT last_name, manager_id
FROM   employees
WHERE  manager_id IS NULL ;
SELECT   last_name, job_id, department_id, hire_date
FROM     employees
ORDER BY hire_date ; //默认ASC升序,DESC降序
SELECT employee_id, last_name, salary, department_id
FROM   employees
WHERE  employee_id = &employee_num ; //使用&来提示输入值
SELECT   employee_id, last_name, job_id, &column_name
FROM     employees
WHERE    &condition
ORDER BY &order_column ;
SELECT   employee_id, last_name, job_id, &&column_name
FROM     employees
ORDER BY &column_name ;  //使用&&可以重用变量值。
DEFINE employee_num = 200  //定义变量
UNDEFINE employee_num   //删除变量


字符函数:
lower('SQL Course') -> sql course
upper('SQL Course') -> SQL COURSE
initcap('SQL Course') -> Sql Course
concat('hello','world') -> helloworld
substr('helloworld',1,5) -> hello
length('helloworld') -> 10
instr('helloworld') -> 6
lpad(salary, 10, '*') -> *****24000
rpad(salary, 10 , '*') -> 24000*****
replace('java and c', 'j', 'c') -> cava and c
trim('h' from 'hellworld') -> elloworld


数字函数:
round(45.937) -> 45.97
trunc(45.937) -> 45.93
mod(100, 30) -> 10
select round(45.937, 2)
from dual;  //dual是一个虚拟表。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值