随笔分类 -  SQL

该文被密码保护。
posted @ 2014-03-13 23:30 王超_cc 编辑
该文被密码保护。
posted @ 2014-03-13 21:25 王超_cc 编辑
摘要:create table as A_05_14 asselect * from A; 阅读全文
posted @ 2013-05-14 15:57 王超_cc 编辑
摘要:如何更新两个表之前的不同数据呢?那么必然存在多条数据中多个字段的数据不同情况。下面我举例说明:1、创建表createtabletb1 (idvarchar2(10), xmvarchar2(10), xbvarchar2(10)); createtabletb2 (idvarchar2(10), xmvarchar2(10), xbvarchar2(10));2、插入测试数据insertintotb1values('1','xx','xx'); insertintotb1values('2','yy','y 阅读全文
posted @ 2013-05-01 13:35 王超_cc 编辑
摘要:table & sql 环境准备1 要修改的数据select empid,religion_code from PERSONAL_INFO_TEMP_WANG;2 修改数据的来源 SELECT SP.CODE_NO, S1.CONTENT CODE_NAME FROM SY_CODE T, SY_CODE_PARAM SP, SY_GLOBAL_NAME S1 WHERE T.PARENT_CODE_NO = '124566' AND T.CODE_NO = SP.C... 阅读全文
posted @ 2013-04-21 16:10 王超_cc 编辑
摘要:例子 1 alter table hr_file add file_name varchar2(10); 向表hr_file添加字段 file_name 字段类型 varchar2(10)例子 2字段名称 hr_employee.activity原有字段类型 NUMBER(1)新的字段类型 VA... 阅读全文
posted @ 2013-04-01 18:24 王超_cc 编辑
摘要:alter table SY_ROLE_GROUP drop constraint PK_SY_ROLE_GROUP cascade;alter table SY_ROLE_GROUP add constraint PK_SY_ROLE_GROUP primary key (ROLE_GROUP_NO) 阅读全文
posted @ 2013-03-26 18:49 王超_cc 编辑
摘要:错误语句:存储过程名称:ADD_MENU_PLine 74 - 79V_SQL := 'insert into sy_menu(menu_code,depth,menu_url,create_date,created_by,activity,menu_no,menu_parent_no)values(V_MENU_code,v_depth,v_menu_url,sysdate,'wangchao',1,v_menu_no,V_PARENT_MENU_NO)'; --执行删除语句 EXECUTE IMMEDIATE V_SQL;错误编号:Compilation e 阅读全文
posted @ 2013-03-03 22:49 王超_cc 编辑
摘要:1 to_char(create_date, 'YYYY_MM_DD') = '2013_02_04'2 to_date('2013/5/30 20:00:00','yyyy/mm/dd hh24:mi:ss') 阅读全文
posted @ 2013-02-04 17:57 王超_cc 编辑
摘要:1 length()作用 统计某一字段的字符串长度对char类型而言 统计数据类型的长度对varchar2 而言统计 字段内数据的长度2 substr()作用截取字符串例如 select substr('aaaaa',1,3)||'****' from dual;3 RPAD和LPAD(粘贴字符) RPAD 在列的右边粘贴字符 LPAD 在列的左边粘贴字符 SQL> select lpad(rpad(’gao’,10,’*’),17,’*’)from dual; LPAD(RPAD(’GAO’,1 ----------------- *******gao* 阅读全文
posted @ 2013-02-02 00:47 王超_cc 编辑
摘要:表A表 B (AID是外键 指向A表的ID主键)查子表外键与主表主键不重合部分 (包含子表外键为NULL值的情况)select * from B where not exists ( select ID from A where a.id = b.aid );查看子表主键主表主键不重合的部分 (不包含子表外键为NULL值的情况)select * from B where b.aid not in ( select ID from A );普通查询不包含NULLselect * from B where aid !=1;包含NULL的查询 (需要特殊指定)select * from B wher 阅读全文
posted @ 2013-01-23 12:17 王超_cc 编辑
摘要:重点关注9:用EXISTS替代IN.重点关注案例 :查找DEPT_1部门的人员姓名9.1 SQL语句--子查询select pname from t_person where deptid in ( select deptid from t_department where deptname like 'DEPT_1');--exsistselect pname from t_person where exists ( select * from t_department where t_department.deptid = t_person.deptid ... 阅读全文
posted @ 2013-01-04 01:15 王超_cc 编辑
摘要:影响ORACLE效率的关键点 原文 http://hi.baidu.com/odbcconnection/item/f4a56cbf1c8bea422bebe32f 1:选择最有效率的表名顺序(只在基于规则的优化器中有效) ORACLE的解析器按照从右到左的顺序处理FROM子句中的表名,因此FROM子句中写在最后的表(基础表drivingtable)将被最先处理.在FROM子句中包含多个表的情况下,必须选择记录条数最少的表作为基础表.当ORACLE处理多个表时,会运用排序及合并的方式连接它们.首先,扫描第一个表(FROM子句中最后的那个表)并对记录进行派序,然后扫描第二个表(FROM子句中最. 阅读全文
posted @ 2013-01-04 01:15 王超_cc 编辑
摘要:exists (sql 返回结果集为真) notexists (sql 不返回结果集为真) 如下: 表A 表B 表A和表B是1对多的关系 A.ID => B.AID select a.id from A where exists (select a.id from b where a.id = b.aid);select a.id from Awhere not exists ( select a.id from b where a.id = b.aid );条件查询 select * from A where exists (select a.id ... 阅读全文
posted @ 2013-01-03 19:13 王超_cc 编辑
摘要:完全新建一张表1 create table emp(id integer)tablespace CICI;在原有表的基础上新建一张表2 CREATE TABLE EMP_TEMP TABLESPACE CICI AS( SELECT * FROM EMP) ; 阅读全文
posted @ 2013-01-01 06:09 王超_cc 编辑
摘要:准备工作 1 1秒 = 1000毫秒 2 测试时间差的工具 oracle自带函数dbms_utility.get_time 参考:http://blog.csdn.net/linminqin/article/details/6601897 3 计算时间差create or replace function F_TEST_TIME_efficiency(IN_TESTSQL1 varchar)RETURN number IS t1 INTEGER;--时间点1 t2 INTEGER; --时间点2v_diff number;--时间差 /*************************... 阅读全文
posted @ 2012-12-31 19:31 王超_cc 编辑
摘要:select count (*) from a where name in ( --统计A表中 name不重复的个数 select name from a group by name having count(*)=1 -- 查询出不重复的table A的 name字段值);-- 查询表 a 的 name字段重复的记录select * from awhere a.rowid > (select min(x.rowid) from a x where x.name = a.name);create table t_person( cardid integer primary key,... 阅读全文
posted @ 2012-12-30 12:20 王超_cc 编辑
摘要:查询 一段 rownum记录 select * from (select row_.*, rownum rownum_ from ( ) row_ where rownum <= 10) where rownum_ > 0 and --其他查询条件查询 指定rownum记录select * from (select row_.*, rownum rownum_ from (select empid from A a ) row_ where rownum <= 1... 阅读全文
posted @ 2012-12-28 18:00 王超_cc 编辑
摘要:Select b.table_name 主键表名, b.column_name 主键列名, a.table_name 外键表名, a.column_name 外键列名From (Select a.constraint_name, b.table_name, b.column_name, a.r_constraint_name From user_constraints a, user_c... 阅读全文
posted @ 2012-12-27 10:30 王超_cc 编辑
摘要:1 存储过程create or replace procedure CHECK_DDL_P(table_name in varchar2 ) is /*************************************************************** *NAME : ... 阅读全文
posted @ 2012-12-24 15:43 王超_cc 编辑

点击右上角即可分享
微信分享提示