Oracle 常用语句大全,速速收藏
Oracle数据库是世界上最流行的关系型数据库管理系统之一,以下是一些常用的Oracle SQL语句:
- 创建用户:
CREATE USER username IDENTIFIED BY password;
- 给用户授权:
GRANT CONNECT, RESOURCE TO username;
- 创建表:
CREATE TABLE tablename (
column1 datatype,
column2 datatype,
...
);
- 插入数据:
INSERT INTO tablename (column1, column2, ...) VALUES (value1, value2, ...);
- 查询数据:
SELECT column1, column2 FROM tablename WHERE condition;
- 更新数据:
UPDATE tablename SET column1 = value1, column2 = value2 WHERE condition;
- 删除数据:
DELETE FROM tablename WHERE condition;
- 创建索引:
CREATE INDEX indexname ON tablename (column1);
- 创建视图:
CREATE VIEW viewname AS SELECT column1, column2 FROM tablename WHERE condition;
- 创建存储过程:
CREATE PROCEDURE procedurename
IS
BEGIN
-- PL/SQL statements here
END;
- 创建触发器:
CREATE TRIGGER triggername
BEFORE INSERT ON tablename FOR EACH ROW
BEGIN
-- PL/SQL statements here
END;
- 创建序列:
CREATE SEQUENCE sequencename START WITH 1 INCREMENT BY 1;
- 创建同义词:
CREATE SYNONYM synonymname FOR tablename;
- 导出数据:
EXP username/password@SID FILE=export.dmp LOG=export.log
- 导入数据:
IMP username/password@SID FILE=import.dmp LOG=import.log FULL=YES
- 查看表结构:
DESC tablename;
- 查看所有表:
SELECT table_name FROM user_tables;
- 查看表空间:
SELECT * FROM dba_data_files;
- 查看用户权限:
SELECT * FROM dba_sys_privs WHERE grantee = 'USERNAME';
- 设置表空间配额:
ALTER USER username QUOTA UNLIMITED ON tablespace_name;
这些是Oracle数据库中最常用的SQL语句,每个语句都有其特定的用途和语法要求。在使用时,需要根据实际需求进行调整和使用。
评论已关闭