oracle常用sql语句

--oracle的字典

select * from dictionary

--创建表空间oracle创建表空间

create tablesapce  testSpace

datafile 'E:oracleSpace\test.dbf'

size 100M

autoextend on;

--创建用户

create user test

identified by t123456

--用户赋权

grant connect,resource,dba to test

--创建表 

create table test(

did number(8) not null,

dName varchar2(2000),

dsex varchar2(2000),

dtime date

)

--插入测试数据

insert into test value(SEQ_test.nextval,'张三','男',to_date('2012-1-1','yyyy-MM-dd'))

--修改数据

update test set d.Name='李四',dsex='女'

--创建序列

create sequence SEQ_test

start with 1

increment by 1

--多个表的字段王一个空表中插入

insert into test(id,name,sex,age,adds,phone)

as

select ta.id,tb.name,tc.sex,td.adds,te.pbone

或者

create table test as select ta.id,tb.name,tc.sex from表

--创建索引 试图过程 都可以使用plsql创建

/********************oracle查询*************/

----oracle3中查询 1.简单2,集合.3 子查询

--简单查询

select t.字段 from test t where 条件1='xx' and 条件2=''

--多表查询 如果不加条件限制会造成笛卡尔积 t1表3条数据 t2表4条数据 就会查出12条数据

select t1.id,t1.name,t2.id,t2.name from t1,t2

where t1.id=t2.id

--连接查询 条件连接 左边4条右边不够用null数据对齐

select t1.id,t1.name,t2.id,t2.name from 

t1 left jion t2

on t1.id=t2.id

//或者 用oracle自己左链接方法

select t1.id,t1.name,t2.id,t2.name from t1,t2

where t1.id=t2.id(+) 

--虚拟表连接

select ta.id,ta.name,tb.id,tb.name from

(select table1.id,table1.name from table1 where xxx ) ta,

(select table2.id,table2.name from table2 where xxx) tb,

where ta.id=tb.id(+)

--查询字段判断

select jmc, case when nds   is  null   then '0'  else  nds  end  as jg  from gg_jing  

--分组查询 要想对结果集分组 查询的字段必须含有 分组函数(统计函数)

--使用分组必须满足(1.select子句后只能包含两类字段,统计函数和要分组的列)

--使用分组必须满足(1.select子句后只能包含对其分组的列,否则是错误的)

select cssj,count(),max(),min() from table 

group by cssj

猜你喜欢

转载自qq1827245563.iteye.com/blog/2330518