Oracle 基础语句

-- 创建表空间
create tablespace space_name datafile 'D:\Required\Oracle\space_name.dbf' size 2048M autoextend on extent management local uniform size 100M;
-- 创建用户
create user username identified by password default tablespace space_name;
-- 用户授权
grant connect, resource, dba, debug connect session to username;
-- 用户配额
alert user username quota ublimited on space_name;
-- 创建表格
create table table_name(column_0 number, column_1 varchar2(32), column_2 data);
-- 修改表名
rename table_name to tb_table_name;
-- 修改列名
alert table table_name rename column column_name to column_name;
-- 删除数据
truncate table table_name;
-- 分页查询
select ttt.* from (select tt.*, rownum as rowno from(select t.* from table_name t order by ref desc) tt where rownum <= &end) ttt where ttt.rowno > &start;
-- 复制数据
insert into &new_table_name select * from &old_table_name;
-- 复制表格
create table &new_table_name as select * from &old_table_name where column_name in (value_0, value_1, value_3);
-- 查看用户下所有表
select * from user_tables;
-- 查看指定表名
select object_id, object_name, object_type, created from user_objects where instr(object_name, upper('&table_name')) > 0 and object_type = 'TABLE';
-- 查看编码
select * from nls_database_parameters;
-- 条件语法:
-- decode(字段, 值1, 返回值1, 值2, 返回值2, ...值n, 返回值n, 缺省值)
-- case 字段 when 值1 then 返回值1 when 值2 then 返回值2 when 值n then 返回值n else 缺省值 end
-- case when 条件1 then 返回值1 when 条件2 then 返回值2 when 条件n then 返回值n else 缺省值 end

猜你喜欢

转载自53032104.iteye.com/blog/2208640