oracle查询优化,存储过程select表循环插入另一个表,以及索引重建
查询语句pl/sql中用F5优化语句
ORACLE的explain plan工具的作用只有一个,获取语句的执行计划
1.语句本身并不执行,ORACLE根据优化器产生理论上的执行计划
2.语句的分析结果存放在表PLAN TABLE中
select * from TABLE
where NOWTIME >=to_date('20160101','yyyy-mm-dd') and NOWTIME < to_date('20160102','yyyy-mm-dd')
通过截图显示select语句是走索引的“INDEXRANGE SCAN”后边是索引名称,cost显示成本,走索引成本是很低的。
如果没有“INDEXRANGE SCAN”,表之前是建有索引,说明索引失效,我们无需删掉再建立索引,只需要用以下语句重建索引,速度很快,即使表里有上千万数据。
alter index index_name rebuild tablespace tablespace_name 加入表空间名,会将指定的索引移动到指定的表空间当中。
存储过程:
//////////////////////////////////////////
create or replace procedure loop_while
(
start_date in date,
end_date in date
)
is
current_date_str date := start_date;
current_date_str_end date;
begin
while current_date_str <=end_date
loop
current_date_str_end:=current_date_str+1;
insert into TABLE1
select * from TABLE
where NOWTIME >=current_date_str and NOWTIME < current_date_str+1 ;
commit;
current_date_str:=current_date_str+1;
end loop;
end loop_while;
/////////////////////////////////////////////////////////////////
current_date是关键字,只会获取当前日期
sysdate取的是服务器(主机)的当前日期和时间
current_date取得是会话的当前日期和时间
注意:一般情况下,二者相同。但如果修改了当前会话的时区,则会不同。
按天循环插入表中。
oracle查询优化,存储过程select表循环插入另一个表,以及索引重建的更多相关文章
- 把一个select查询结果插入到一个表(可选指定字段和值实例)
把一个select查询结果插入到一个表(可选指定字段和值实例) insert into bak (cc,yf) select cc,9 from ket insert into bak (cc,yf ...
- ORACLE 查询一个数据表后通过遍历再插入另一个表中的两种写法
ORACLE 查询一个数据表后通过遍历再插入另一个表中的两种写法 语法 第一种: 通过使用Oracle语句块 --指定文档所有部门都能查看 declare cursor TABLE_DEPT and ...
- Oracle 中用一个表的数据更新另一个表的数据
Oracle 中用一个表的数据更新另一个表的数据 分类: SQL/PLSQL2012-05-04 15:49 4153人阅读 评论(1) 收藏 举报 oraclemergesubqueryinsert ...
- Oracle中 如何用一个表的数据更新另一个表中的数据
准备阶段 1.建表语句: create table table1( idd varchar2(10) , val varchar2(20) ); create table table2( idd va ...
- SQL技巧两则:选择一个表的字段插入另一个表,根据其它表的字段更新本表内容
最近,在作django数据表迁移时用到的. 因为在django中,我把本来一个字符型字段,更改成了外键, 于是,哦喝~~~字符型字段相当于被删除了, 为了能导入这些字段的外键信息,于是出此下策. 其实 ...
- mysql 从一个表中查询插入另一个表
insert into dnt_userfields (uid,realname ) select uid,nickname from discuz.dnt_users where uid>72 ...
- SQL存在一个表而不在另一个表中的数据, 更新字段为随机时间
--更新字段为随机时间 86400秒=1天 UPDATE dl_robot ), ,GETDATE()) ) SQL存在一个表而不在另一个表中的数据 方法一 使用 not in ,容易理解,效 ...
- sql语法:从一个表update到另外一个表
sql语法:从一个表update到另外一个表 一. update a set a.name=b.name1 from a,b where a.id=b.id 二. update table1 set ...
- 【452】pandas筛选出表中满足另一个表所有条件的数据
参考:pandas筛选出表中满足另一个表所有条件的数据 参考:pandas:匹配两个dataframe 使用 pd.merge 来实现 on 表示查询的 columns,如果都有 id,那么这是很好的 ...
随机推荐
- vs2015编译纯ASM文件
x86: 1. 创建一个 C++ 的空项目. 2.解决方案管理器 - 目标项目名 - 右键 - 生成依赖项 - 生成自定义 (VS2015, 如果使用VS2010 你右键就直接能看到生成自定义) 3. ...
- elasticsearch 概念
elasticsearch 来源:https://baike.baidu.com/item/elasticsearch/3411206?fr=aladdin ElasticSearch是一个基于Luc ...
- OC property(声明)
@interface Student : NSObject { int _age; int _no; float _height; } // 当编译器遇到@property时,会自动展开成getter ...
- Android学习笔记_46_Android的intent之间Object、List、List<Object>和全局变量数据的传递(Parcelable Serializable)
转http://blog.csdn.net/pku_android/article/details/7456305 一.传递List<String>和List<Integer> ...
- Android学习笔记_43_网络通信之文件断点上传
1.建立服务端,用于接收上传的文件.这里使用Socket,文件可能会比较大.采用多线程编程,防止并发. package com.socket.service; import java.io.File; ...
- 【题解】洛谷P3627 [APIO2009]抢掠计划(缩点+SPFA)
洛谷P3627:https://www.luogu.org/problemnew/show/P3627 思路 由于有强连通分量 所以我们可以想到先把整个图缩点 缩点完之后再建一次图 把点权改为边权 并 ...
- SQL模糊查询,sum,AVG,MAX,min函数
cmd mysql -hlocalhost -uroot -p select * from emp where ename like '___' -- 三个横线, - 代表字符,可以查询 三个enam ...
- iOS 清除xcode缓存和生成文件
方法1 按快捷键 shift+command+G 或者 Finder图标点击右键选 前往文件夹... 调出前往文件夹框 在里面输入如下 /Users/(自己电脑名字)/Library/Develope ...
- 移动端判断微信浏览器安卓浏览器和ios浏览器
$(function(){ var u = navigator.userAgent; var isAndroid = u.indexOf('Android') > -1 || u.indexOf ...
- HTML页面常用的编辑框
public class FormInputUtil { /** * 获取表单中的InputText * * @param name * @param rs * @return */ public s ...