随笔分类 -  T-SQL

摘要:oracle创建表空间 SYS用户在CMD下以DBA身份登陆:在CMD中打sqlplus /nolog然后再conn / as sysdba--如果路径不存在则要创建路径--创建临时表空间 create temporary tablespace txwh_temp tempfile 'E:\or... 阅读全文
posted @ 2015-11-02 16:12 Seaurl 阅读(2260) 评论(0) 推荐(0) 编辑
摘要:update dbo.EquipmentAttribute set AttributeName=replace(AttributeName,' ','') where EquipmentID=83 and id =1308 阅读全文
posted @ 2014-06-23 14:31 Seaurl 阅读(184) 评论(0) 推荐(0) 编辑
摘要:情境:保留表A数据,且A表与B表是一对多关系SELECT tuf.Id,tuf.FileName,tuf.type,tuf.url,tum.MachineId,tum.IsDownland,tum.IsFlagFROM t_UpgradeFile tufLEFT join (SELECT t.* from t_Upgrade_Machine t where t.MachineId='3333' ) tum on tuf.Id=tum.UpgradeFileId 阅读全文
posted @ 2013-12-02 15:59 Seaurl 阅读(270) 评论(0) 推荐(0) 编辑
摘要:在Oracle中进行查询排序时,如果排序字段里面有空值的情况下,排序结果可能会达不到自己想要的结果。如 select * from tableTest order by VISITS desc上图可以看到表示服务访问次数的“VISITS”字段上的空值记录排序时放在前面,和实际逻辑不对将原来的sql语句改写为:select * from tableTest order by VISITS desc nulls last,"nulls last"控制将空值记录放在后面,当然,你也可以用"nulls first"将控制记录放在前面。 阅读全文
posted @ 2013-09-24 09:26 Seaurl 阅读(269) 评论(0) 推荐(0) 编辑
摘要:select sum(ceil((gdr.enddt - gdr.startdt) * 24)) h,sum(ceil((gdr.enddt - gdr.startdt) * 24 * 60)) m,sum(ceil((gdr.enddt - gdr.startdt) * 24 * 60 * 60)) sfrom gat_data_record gdrwhere gdr.enddt between to_date('2011-1-1','yyyy-mm-dd') and to_date('2014-2-1','yyyy-mm-dd' 阅读全文
posted @ 2013-09-22 15:35 Seaurl 阅读(3470) 评论(0) 推荐(1) 编辑
摘要:substr(字符串,截取开始位置,截取长度) //返回截取的字substr('Hello World',0,1) //返回结果为 'H' *从字符串第一个字符开始截取长度为1的字符串substr('Hello World',1,1) //返回结果为 'H' *0和1都是表示截取的开始位置为第一个字符substr('Hello World',2,4) //返回结果为 'ello'substr('Hello World',-3,3)//返回结果为 'rld' *负数(- 阅读全文
posted @ 2013-09-22 09:18 Seaurl 阅读(195) 评论(0) 推荐(0) 编辑
摘要:SELECT EXTRACT(DAY FROM (sysdate-to_date('2012-03-29 00:00:00','YYYY-MM-DD HH24:MI:ss')) DAY TO SECOND ) || ' days ' || EXTRACT(HOUR FROM (sysdate-to_date('2012-03-29 00:00:00','YYYY-MM-DD HH24:MI:ss')) DAY TO SECOND ) || ' hours' || EXTRACT(MINUTE FRO 阅读全文
posted @ 2013-09-02 14:57 Seaurl 阅读(532) 评论(0) 推荐(0) 编辑
摘要:1 create sequence MSG_OUTBOX_ID_SEQ2 minvalue 13 maxvalue 9999999994 start with 815 increment by 16 cache 20; 阅读全文
posted @ 2013-08-27 16:11 Seaurl 阅读(186) 评论(0) 推荐(0) 编辑
摘要:怎么合并多行记录的字符串,一直是oracle新手喜欢问的SQL问题之一,关于这个问题的帖子我看过不下30个了,现在就对这个问题,进行一个总结。-什么是合并多行字符串(连接字符串)呢,例如: 1 SQL> desc test; 2 Name Type Nullable Default Comments 3 ------- ------------ -------- ------- -------- 4 COUNTRY VARCHAR2(20) Y 5 CITY VARCHAR2(20) Y 6 7 SQL> select * from test; 8 9 10 COUNTRY ... 阅读全文
posted @ 2013-06-18 15:50 Seaurl 阅读(2051) 评论(0) 推荐(0) 编辑
摘要:1 declare @i int 2 set @i=0 3 begin transaction 4 while @i<80 5 begin 6 set @i=@i+1 7 insert into TabTest values (100+@i, 'Name'+convert(nvarchar(50),@i), @i, dateadd(dd,@i,getdate()) ) 8 end 9 commit10 go11 12 ... 阅读全文
posted @ 2013-03-13 09:20 Seaurl 阅读(131) 评论(0) 推荐(0) 编辑
摘要:1 delete from TAB_JXGD_BPBJ a2 where not EXISTS (select jxdid from tab_jxgd b where a.jxgdid=b.jxdid) 阅读全文
posted @ 2012-11-13 15:31 Seaurl 阅读(766) 评论(0) 推荐(0) 编辑
摘要:方法1:select a.a1,a.a2,a.a3,b.b2,c.c2,d.d2from a,b,c,dwhere a.a1=b.b1 and b.b1=c.c1 and c.c1=d.d1方法2:select a.a1,a.a2,a.a3,b.b2,c.c2,d.d2from a inner join b on a.a1=b.b1 inner join c on b.b1=c.c1 inner join d on c.c1=d.d1 阅读全文
posted @ 2012-09-19 15:25 Seaurl 阅读(195) 评论(0) 推荐(0) 编辑

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