常用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数据库过程中,常用脚本命令莫不是用户和密码.表空间.多表联合.执行语句等常规操作. ...
随机推荐
- nth_element函数
使用方法:nth_element(start, start+n, end) 使第n大元素处于第n位置(从0开始,其位置是下标为n的元素),并且比这个元素小的元素都排在这个元素之前,比这个元素大的元素都 ...
- 因kernel too old 而 centos6.8 升级内核
因为docker运行centos 的时候,报错了,错误为kernel too old .我看了一下是因为os的内核不行了,需要升级下内核. 查看默认版本: uname -r 忘记截图了,内核大概是2. ...
- python编程语言学习day02
格式化输出 (1)info 格式 (2)%字符串占位 %s 表示字符串占位 %d 表示整数占位 %f 表示浮点数占位 中间的% 之后是所需要输入的值 多个占位, % 之后用()括号括起 ...
- 在IDEA安装SonarLint插件的步骤和使用方法
1.安装SonarLint插件方式 2.使用方式 3.效果
- 后缀自动机求字典序第k小的串——p3975
又领悟到了一点新的东西,后缀自动机其实可以分为两个数据结构,一个是后缀树,还有一个是自动机 后缀树用来划分endpos集合,并且维护后缀之间的关系,此时每个结点代表的是一些后缀相同且长度连续的子串 自 ...
- TYVJ1061 Mobile Service
P1061 Mobile Service 时间: 1000ms / 空间: 131072KiB / Java类名: Main 描述 一个公司有三个移动服务员.如果某个地方有一个请求,某个员工必须赶到那 ...
- 实现组件props双向绑定解决方案
注意: 子组件不能直接修改prop过来的数据,会报错 方案一: 用data对象中创建一个props属性的副本 watch props属性 赋予data副本 来同步组件外对props的修改 watch ...
- 秦曾昌人工智能课程---5、KNN和朴素贝叶斯
秦曾昌人工智能课程---5.KNN和朴素贝叶斯 一.总结 一句话总结: 拟合和概率:构建机器学习模型,一般有拟合和概率两种方式 轻学无用:一定要保证学有所用,要深入学习,比如之前做的安卓,一定要学通, ...
- CSS3:CSS3 圆角
ylbtech-CSS3:CSS3 圆角 1.返回顶部 1. CSS3 圆角 CSS3 圆角 使用 CSS3 border-radius 属性,你可以给任何元素制作 "圆角". C ...
- TCP/IP点滴
1 子网的划分 2 子网的表述 ipv4 IPv4中规定IP地址长度为32,最大地址个数为2^32,点分十进制表示方法:122.70.156.25. ipv6 地址的长度为128,即最大地址个数为2^ ...