随笔分类 -  oracle

摘要:在查看sql执行计划时,我们会发现表的连接方式有多种,本文对表的连接方式进行介绍以便更好看懂执行计划和理解sql执行原理。一、连接方式: 嵌套循环(NestedLoops (NL)) (散列)哈希连接(Hash Join (HJ)) (归并)排序合并连接(Sort Merge Join (SM... 阅读全文

posted @ 2015-03-30 15:07 kenwong 阅读(1267) 评论(0) 推荐(0)

摘要:1.select*fromEMP twheret.deptno=10;EMPNO ENAME JOB MGR HIREDATE SAL COMM DEPTNO7782 CLARK MANAGER 7839 1981/6/9 2450.00 107839 KING PRESIDENT 198... 阅读全文

posted @ 2014-12-25 16:30 kenwong 阅读(2733) 评论(0) 推荐(0)

摘要:Oracle中TIMESTAMP时间的显示格式Oracle数据库的时间字段我们通常是使用timestamp 格式,在未做设置前,查询出来的数据类似于“27-1月 -08 12.04.35.877000 上午”,经过to_char函数转换后得到如下结果:“2008-01-27 00:04:35:877... 阅读全文

posted @ 2014-12-01 14:46 kenwong 阅读(3182) 评论(0) 推荐(0)

摘要:instr(title,'手册')>0相当于title like '%手册%'instr(title,'手册')=1相当于title like '手册%'instr(title,'手册')=0相当于title not like '%手册%'特殊用法:select id, name from user... 阅读全文

posted @ 2014-11-04 17:06 kenwong 阅读(693) 评论(0) 推荐(0)

摘要:insert allwhen sum_orders = 1000 and sum_orders <1000 theninto mediums_customerselseinto large_customersselect customer_id,sum(order_total) sum_orders... 阅读全文

posted @ 2014-10-30 10:58 kenwong 阅读(304) 评论(0) 推荐(0)

摘要:--登录:sys/ken@orcl as sysdba1、建立表空间、授予权限/*分为四步 *//*第1步:创建临时表空间 */create temporary tablespace user_temp tempfile 'D:\oracle\oradata\Oracle9i\user_temp... 阅读全文

posted @ 2014-10-20 17:19 kenwong 阅读(145) 评论(0) 推荐(0)

摘要:--测试数据create table rowtocol_test asselect 2009 year,1 month,'部门1' dept,50000 expenditure from dualunion all select 2009,2,'部门1',20000 from dualunion a... 阅读全文

posted @ 2014-09-17 10:59 kenwong 阅读(201) 评论(0) 推荐(0)

摘要:CREATE TABLE CC (Student NVARCHAR2(2),Course NVARCHAR2(2),Score INT ); INSERT into CC select N'张三',N'语文',78 from dual union all select N'张三... 阅读全文

posted @ 2014-09-17 10:05 kenwong 阅读(493) 评论(0) 推荐(0)

摘要:存储过程中执行如下DDL语句create or replace procedure etl_test(v_com varchar2) is v_spname varchar2(40); com varchar2(40);begin com := v_com; v_spna... 阅读全文

posted @ 2014-04-28 14:56 kenwong 阅读(696) 评论(0) 推荐(0)

摘要:在oracle 的scott用户表下查询全表 使用rownum 代码如下: select * from emp where rownum >2为什么一条都数据都没有。rownum只能用于要么用rownumber()OVER,要么就实例化rownumber()over:select* from (select t.*,row_number()over(order by empno desc) rn from emp t) a where a.rn=2;实例化:select * from (select t.*,rownum rk from (select * from emp order 阅读全文

posted @ 2014-04-04 10:07 kenwong 阅读(234) 评论(0) 推荐(0)

摘要:select sql_text --sql文本的前1000个字符 ,first_load_time --初次载入时间 ,last_load_time --最后载入时间 ,s.sql_fulltext --全部sql ,executions --语句的执行次数 ,parse_calls --解析调用次数 ,disk_reads --读磁盘次数 ,sorts --完成的排序数 ,cpu_time --语句被... 阅读全文

posted @ 2014-03-14 16:27 kenwong 阅读(167) 评论(0) 推荐(0)

摘要:PL/SQL-FOR UPDATE 与 FOR UPDATE OF的区别数据库 oracle for update of 和 for update区别select * from TTable1 for update 锁定表的所有行,只能读不能写2 select * from TTable1 where pkid = 1 for update 只锁定pkid=1的行3 select * from Table1 a join Table2 b on a.pkid=b.pkid for update 锁定两个表的所有记录4 select * from Table1 a join Table2 b o 阅读全文

posted @ 2014-03-14 15:52 kenwong 阅读(721) 评论(0) 推荐(0)

摘要:我们在Oracle存储过程中需要遍历一张表,应该怎样做。我想大多少的人第一个念头就是Cursor。 比如: create or replace procedure StudyCursor( resulst out integer ) is v_tablename varchar(30); v_tabletype varchar(11); cursor mycursor is select * from cat; begin open mycursor; loop fetch mycursor into v_tablename,v_tabletype; null; --... 阅读全文

posted @ 2014-03-07 17:18 kenwong 阅读(441) 评论(1) 推荐(1)

摘要:今天在测试库上使用:alter system set sga_target=300m scope=spfile结果那个m 没写上,导致ORACLE重启的时候无法启动了。报错:ORA-00371: not enough shared pool memory, should be atleast 62198988 bytes原因是ORACLE启动时用SPFILE参数文件。那就不用这个文件,用那个默认的SQL> startup pfile='/home/oracle/oracle/product/10.2.0/db_1/dbs/init.ora';ORACLE instance 阅读全文

posted @ 2012-11-18 17:58 kenwong 阅读(721) 评论(0) 推荐(0)

摘要:--单行 with temp as (select '6001600301,6001600302,6001600303,6001600304' text from dual) select substr(text,instr(text,',',1,rn)+1,instr(text,',',1,rn+1)-instr(text,',',1,rn)-1) text from ( select ','||t1.text||',' text,t2.rn from temp t1, (select rownu 阅读全文

posted @ 2012-10-30 09:14 kenwong 阅读(154) 评论(0) 推荐(0)

导航