oracle in与exists 的区别
表的分布情况 采用cbo 数据和索引都已分析 tb_role 为8960行 建有parent_id的索引tb_user 为8541行 建有role_id的索引SQL> select id, role_id, login 2 from tb_user e 3 wher...
sql优化案例:改变表的写法使代价和逻辑读降下来
优化前:SQL> set autotrace traceonlySQL> Select a.*,b.* 2 From tb_bet_log a 3 Full Outer Join tb_user b On a.client_id = b.id 4 Where ...
一个很简单的查询,为什么用不到索引
http://www.itpub.net/viewthread.php?tid=964719&extra=&page=1create table test as select rownum id,rownum-1 id2 from dba_objects;create index idx_test1 on test(id2);analyze table test compu...
SELECT COUNT(*) 索引会走 index fast full scan
测试如下:不加的会走全表扫描 要是数据量大的话 有可能结果需要很长时间才出来SQL*Plus: Release 9.2.0.4.0 - Production on Mon Mar 24 10:00:23 2008Copyright (c) 1982, 2002, Oracle Corporation. All r...
sql优化用group by 函数代替分析函数
SQL> Select dfId, 2 Id As Client_Id, 3 Login As Client_Name, 4 ...
优化同事发过来的一个sql
SQL>set autotrace traceonlySQL> Select distinct Id, Role_Id, Login 2 From tb_test a,(Select Client_Id 3 ...
oracle 两个时间相减得秒
oracle 两个时间相减默认的是天数oracle 两个时间相减默认的是天数*24 为相差的小时数oracle 两个时间相减默认的是天数*24*60 为相差的分钟数oracle 两个时间相减默认的是天数*24*60*60 为相差的秒数测试如下:S...
行列转换sql
CREATE OR REPLACE TYPE TYPE_IN IS TABLE OF NUMBER; CREATE OR REPLACE FUNCTION FUN_TO_T_IN (P_IN VARCHAR2) RETURN T_IN ASV_RETURN T_IN DEFAULT T_IN();V_IN VARCHAR2(32767);V_COUNT NUMBER DEFAULT ...
如何查哪些用户拥有execute 某个procedure的权限?
SQL> SQL> grant execute on aw_drop_proc to paul; Grant succeededSQL> select * from dba_tab_privs where table_name='AW_D...
exists 的问题
今天同事发以下两个sql来问我,怎么运行结果一样Select Id From Tb_Admin_Role Where Exists (Select Id From Tb_Admin_Role Connect By Pr...
如何用sql找出中间断号的数字
因为工作需要 需要找出id中间断号的数字create table t as select rownum id from dual connect by rownum<=20;delete from t where id in (3,10,11,12);commit;SQL> with my_q as ( 2 select s_id,...
delete 数据很慢调优解决
delete from tb_test partition (TB_test_P200711) where id<=15744829 and id>=14471371 and created_date between to_date('2007-11-07 00:00:00','yyyy-mm-dd hh24:mi:ss') and...
生成有规则的用户名和随机产生的对应6位用户数字密码
begin for i in 1..5000 loop if i<10 then insert into tb_test (role_id,name,login,password,credit_amount,currency_code_id) values(4,'ddz0000'||i,'ddz0000'||i,TRUNC(DBMS_RANDOM.VALUE(100000, 999999)),50...
oracle sql tunning all hints
The following is a list of all hints available in Oracle9i. Many of the hints are also available in earlier releases of Oracle. The purpose of this list is not to exhaustively describe the syntax of e...
in 和exists的用法
昨天在客户那用 in 的写法删除数据库时, 由于没有对数据进行分析,很慢要十多分钟才出来,用exists可能快点 但分析后速度就很快 in和exists 差不多 由于数据库是CBO模式 所以总结如下: 假设数据库没做分析,最好先分析...
oracle 常用查询视图
1.查找某个用户下所有表,和根据num_rows的值确定表是否分析过select * from user_tables;2.查找某个用户下所有触发器select * from user_triggers;3.查找某个用户下所有序列号select * from user_sequences;4....
求一条sql关于按分组重复值不显示?
如下面表: id shop type money 1 500 电冰箱 2000 2 500 空调 2000 3 500 电视 2000 4 501 电冰箱 4000 5 501 空调 4000 6 501 电视 4000 处理成 id shop type money 1 500 电冰箱 2000 2 500 空调 《--空格也可以 ...
输入表名后自动生成sqlldr控制文件存储过程
自己写的一个存储过程输入表名生成对应表的控制文件CREATE OR REPLACE PROCEDURE P_generate_sqlldr_null(p_table_name IN VARCHAR2) AS l_curr_line LONG; l_table_name user_tables.table_name%TYPE; BEGIN selec...
利用sql语句找出表中有重复记录的三种sql写法
create table test_0210(id number,name varchar2(32),age number); insert into test_0210 values(1,'abc',32); insert into test_0210 values(2,'def',33); insert into test_0210 values(3,'def',45); commit; se...
oracle update语句的几点写法
update两表关联的写法包括字查询 1.update t2 set parentid=(select ownerid from t1 where t1.id=t2.id); 2. update tb_client_win_lost_report a set a.rolling_code_id=2 where game_code_id=70000 and exists (s...