常用Oracle操作语句
--常用的字段类型有:varchar2,char,nchar,date,long,number,float,BLOB,CLOB --添加表字段
alter table tablename add AREAID Number(18);
--修改表字段
alter table tablename modify SJLY varchar2(200);
--删除表字段
alter table tablename drop (AREAID); --DBA_TABLES、ALL_TABLES和USER_TABLES显示了有关数据库表的一般信息。
--DBA_TAB_COLUMNS、ALL_TAB_COLUMNS和USER_TAB_COLUMNS显示了每个数据库表的列的信息。
select * from all_tables WHERE owner='SUPER';
--或者
SELECT * FROM dba_tables WHERE owner='SUPER'; select * from tab;--查询出所有的表及视图
select * from user_views;--查询出当前用户下的所有视图 --列出数据库里所有的表名
--(仅用于SqlServer)
select name from sysobjects where type='super' --U代表用户
--(Oracle写法)
select * from user_tables --查询出当前用户下的所有表数据 --列出表里的所有的列名
--(仅用于SqlServer)
select name from syscolumns where id=object_id('tablename') ;
--(Oracle写法)
select column_name,data_type,char_col_decl_length,data_precision,data_scale
from user_tab_columns where table_name='tablename'; --这种写法主要是用在:Java代码动态加载where后面的条件。如 :and name='小白'
select * from talbeName where 1=1; --时间比较
select * from tablename where updatetime>=to_date('2013-10-11', 'yyyy-mm-dd') and updatetime<to_date('2013-11-30', 'yyyy-mm-dd'); --时间加减
select a.sblsh, a.sbsj,b.bjsj,a.sxmc,b.bjbmmc from laam_ex_sb a,laam_ex_bj b where trunc(b.bjsj)-trunc(a.sbsj) > 10 and b.sblsh=a.sblsh; --rownum 相当于SqlServer-->>top n *
create table mytable as select * from laam_ex_bj where rownum<3; --复制表结构及数据到新表
create table newTalbe as select * from oldTalbe; select * into newTalbe from oldTalbe; -- (仅用于SQlServer) insert into newTable(a, b, c) select d,e,f from oldTalbe; --前提是newTalbe事先已存在 --用'||'符号拼接表字段信息
select 'ALTER TABLE '||substr(table_name,0,length(table_name)-3)||' MODIFY SJLY varchar2(200);' from user_tables where table_name like 'LBID%OLD'; --创建索引
create index INDEX_Job on LBIDResidentJobInfo(XM, SFZH, scbj);
create index INDEX_Legal on LBIDHouseAndLegalPerson(rkfrlegalpersonbaseid); --外键
create index INDEX_House on LBIDhouseinfo(id); --主键 --子查询
select a,b,c from A where A IN (select d from B );
--或者
select a,b,c from A where A IN (1,2,3); --显示文章、提交人和最后回复时间
select a.title,a.username,b.adddate from table A,(select max(adddate) adddate from table where table.title=A.title) B ; --两张关联表,删除主表中已经在副表中没有的信息
delete from table1 where not exists ( select * from table2 where table1.field1=table2.field1 ); --四表联查问题:
select * from A left inner join B on A.a=B.b right inner join C on A.a=C.c inner join D on A.a=D.d where ..... --一条 sql 语句搞定数据库分页
--(仅用于SqlServer)
select top 10 b.* from (select top 20 主键字段,排序字段 from 表名 order by 排序字段 desc) a,表名 b where b.主键字段 = a.主键字段 order by a.排序字段;
--(Oracle写法)
select b.* from (select id,sbsj from laam_ex_sb where rownum<=20 order by sbsj desc) a,laam_ex_sb b where a.id = b.id and rownum<=10 order by a.sbsj; --删除重复记录
delete from laam_ex_sb
where createtime>to_date('2014-09-21', 'yyyy-mm-dd') and sqrmc in (select sqrmc from laam_ex_sb where createtime>to_date('2014-09-21', 'yyyy-mm-dd')
group by sqrmc having count(sqrmc) > 1)
and id not in (select min(id) from laam_ex_sb where createtime>to_date('2014-09-21', 'yyyy-mm-dd') group by sqrmc having count(sqrmc)>1); --随机取出10条数据
select * from laam_ex_bj where rownum<10 order by sys_guid();
select * from laam_ex_bj where rownum<10 order by dbms_random.value; --选择从10到15的记录
--(仅用于SqlServer)
select top 5 * from (select top 15 * from table order by id asc) table_别名 order by id desc;
--(Oracle写法)
select * from (select * from laam_ex_sb where rownum<=15 order by rownum desc) laam_ex_sb where rownum<=5;
--日程安排提前五分钟提醒
select * from 日程安排 where datediff('minute',开始时间,getdate())>5;
--group by 用法
select sxmc,count(sxmc) 数量 from laam_ex_sb where 1=1 group by sxmc order by 数量; select sxmc,sxbm,count(*) from laam_ex_sb where 1=1 group by sxmc,sxbm having count(*)>100; select sxbm,sum(case when sxbm is not null then 1 else 0 end ) 总量 from laam_ex_sb where 1=1 group by sxbm order by 总量;
常用Oracle操作语句的更多相关文章
- 常用Oracle SQL语句(汇总版)
Oracle数据库常用sql语句 ORACLE 常用的SQL语法和数据对象 一.数据控制语句 (DML) 部分 1.INSERT (往数据表里插入记录的语句) INSERT INTO 表名(字段名1, ...
- Oracle操作语句--增加/删除
1.删除1980年雇员的雇员信息: delete from myemp where hiredate between to_date('1980-1-1','yyyy-mm-dd') and ...
- [sqlite] 判断表、视图是否存在及常用C#操作语句
1,判断表是否存在: SELECT name, sql FROM sqlite_master WHERE type="table" AND name = "Dom&quo ...
- Shell脚本文件中常用的操作语句
1. 清空文件中的内容 cat /dev/null >> /var/log/messages 2. 脚本中判断用户是不是root用户 ROOT_UID = 0 # ...
- oracle操作语句
Oracle中建立索引,会提高查询速度: create index 索引名 on 表名(列名); create index index_userid on tbl_detail(userid);如何找 ...
- Hibernate学习笔记三:常用数据库操作语句
转载请注明原文地址: 一:HQL 1:HQL语句格式:select from POJO类名 where 条件表达式 group by 属性 having 聚集函数 order by 属性 [其中,fr ...
- mysql 常用sql操作语句
获取数据库里所有表 SELECT TABLE_NAME,TABLE_ROWS FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_SCHEMA='数据库名' 获取表里 ...
- 常用oracle语句-------------------------------------------》(笔记)
Orale常用语句 1:查询指定表名的字段 select * from sys.user_tab_columns where table_name=表名 //查询指定表名的字段 2: 查询数据库参 ...
- Oracle手边常用命令及操作语句
Oracle手边常用命令及操作语句 作者:白宁超 时间:2016年3月4日11:24:08 摘要:日常使用oracle数据库过程中,常用脚本命令莫不是用户和密码.表空间.多表联合.执行语句等常规操作. ...
随机推荐
- sql ibatis
<!-- 写入单位下当前参保人员 --> <insert id="insertTempCaz043" parameterClass="map" ...
- 微信小程序开发入门与实践
基础知识---- MINA 框架 为方便微信小程序开发,微信为小程序提供了 MINA 框架,这套框架集成了大量的原生组件以及 API.通过这套框架,我们可以方便快捷的完成相关的小程序开发工作. MIN ...
- 13. this关键字
1.this的概述 this关键字代表是对象的引用.也就是this在指向一个对象,所指向的对象就是调用该函数的对象引用. 2.this实例,初始化成员变 class Employee { privat ...
- Redis探索之路(三):Redis的五种数据类型String和Hash
一:String 存储二进制数据,可以图片,序列化对象 GET,SET SETNX(not exist) setnx age 33 返回 0,1 SETEX设置有效期 SETEX COLOR 2 ...
- ArrayList 详解
基本介绍 ArrayList: 支持null元素.有顺序.元素可以重复. 可以动态增长和缩减的索引序列,基于数组实现的List类(查询效率高,而在插入删除性能下降很多(需要移动数组元素)). 底层的数 ...
- DOM——创建元素的三种方式
document.write() document.write('新设置的内容<p>标签也可以生成</p>'); innerHTML var box = document. ...
- lsof 详解
lsof常用参数 lsof 如果不加任何参数,就会打开所有被打开的文件,建议加上一下参数来具体定位lsof -i 列出所有网络连接lsof -i tcp 列出所有tcp连接信息lsof -i udp ...
- Delphi如何实现无边框窗体的移动
在控件的MouseDown事件中加入if (ssleft in Shift) then begin ReleaseCapture; Perform(WM_syscommand, $F012, 0);e ...
- NX二次开发-UFUN点收集器UF_UI_select_point_collection
#include <uf.h> #include <uf_ui.h> UF_initialize(); //点收集器 char sMessage[] = "点收集器& ...
- 去除springboot内置tomcat
/** * @author zx * @title: ServletInitializer * @projectName activiti * @description: 解决内置tomcat * @ ...