|

楼主 |
发表于 22-11-2006 04:28 PM
|
显示全部楼层
sql functions有没有办法, trim 掉某character之后的characters..
比如:
abcdefg-h 变 abcdefg
abcd-efgh 变 abcd |
|
|
|
|
|
|
|
发表于 22-11-2006 05:08 PM
|
显示全部楼层
原帖由 天魔神 于 27-10-2006 01:43 AM 发表
请问各位高手,最近小弟我在做一个足球的作业.运用于SQL-PLUS
DBMS_output.put_line('Team Played Won Drew Lost GF GA GD Points');
DBMS_output.put_line('---- ------ --- ---- ---- -- -- ...
我想update就可以了。
原帖由 tensaix2j 于 22-11-2006 04:28 PM 发表
sql functions有没有办法, trim 掉某character之后的characters..
比如:
abcdefg-h 变 abcdefg
abcd-efgh 变 abcd
substring(field, location, lenght)
[ 本帖最后由 hui_wooi 于 22-11-2006 05:10 PM 编辑 ] |
|
|
|
|
|
|
|

楼主 |
发表于 22-11-2006 07:45 PM
|
显示全部楼层
原帖由 hui_wooi 于 22-11-2006 05:08 PM 发表
我想update就可以了。
substring(field, location, lenght)
我知道这个function...
问题是
length,location, field
都是variable..
而且我用
select something from tblBlah1 a
full outer join
tblBLah2 b
on
substring(a.field,0,charindex("-",a.field))=substring(b.field,0,charindex("_",b.field))
不行。。因为
有时 "-" 没出现
结果拿了0length的substring
[ 本帖最后由 tensaix2j 于 22-11-2006 07:53 PM 编辑 ] |
|
|
|
|
|
|
|
发表于 22-11-2006 07:56 PM
|
显示全部楼层
原帖由 tensaix2j 于 22-11-2006 07:45 PM 发表
我知道这个function...
问题是
length,location, field
都是variable..
而且我用
select something from tblBlah1 a
full outer join
tblBLah2 b
on
substring(a.field,0,charindex(&qu ...
你的意思是不一定有“-”? |
|
|
|
|
|
|
|

楼主 |
发表于 22-11-2006 07:57 PM
|
显示全部楼层
原帖由 hui_wooi 于 22-11-2006 07:56 PM 发表
你的意思是不一定有“-”?
没错。。而且,位置不定 |
|
|
|
|
|
|
|

楼主 |
发表于 22-11-2006 08:00 PM
|
显示全部楼层
|
|
|
|
|
|
|
发表于 22-11-2006 08:08 PM
|
显示全部楼层
原帖由 tensaix2j 于 22-11-2006 08:00 PM 发表
等等。。好象可以用case when...
如何?
能找出string的pattern会比较方便。 |
|
|
|
|
|
|
|
发表于 22-11-2006 11:48 PM
|
显示全部楼层
原帖由 tensaix2j 于 22-11-2006 04:28 PM 发表
sql functions有没有办法, trim 掉某character之后的characters..
比如:
abcdefg-h 变 abcdefg
abcd-efgh 变 abcd
得自己写 sql function 了. |
|
|
|
|
|
|
|

楼主 |
发表于 23-11-2006 07:41 AM
|
显示全部楼层
可以了。。谢谢。。
- select distinct(family),b.productname from tblproductlookup a
- full outer join [pgsisddev01].j_autouph.dbo.tblProd b
- on
- case when charindex('-',a.family)>0 then substring(a.family,0,charindex('-',a.family)) else a.family end =
- case when charindex('_',b.productname)>0 then substring(b.productname,0,charindex('_',b.productname)) else b.productname end
复制代码 |
|
|
|
|
|
|
|

楼主 |
发表于 23-11-2006 08:00 AM
|
显示全部楼层
原帖由 神仙祖宗 于 5-9-2006 06:50 PM 发表
如果不要用store procedure该如何作?用纯SQL.
stored proc 和纯sql 有何不同?stored proc 不就只是把sql 给存起来吗?
通常,我都是先写纯 sql,用一些暂时的variable test 过了,再转去 parameterized stored proc..
比如 sql如下。。
declare @i int
。。
set @i= testvalue here..
。。
。。(some procedure...)
变
create procedure aaa
( @i int
)
as
...
(some procedure)
[ 本帖最后由 tensaix2j 于 23-11-2006 10:45 AM 编辑 ] |
|
|
|
|
|
|
|

楼主 |
发表于 23-11-2006 10:51 AM
|
显示全部楼层
|
|
|
|
|
|
|
发表于 23-11-2006 01:50 PM
|
显示全部楼层
原帖由 tensaix2j 于 23-11-2006 07:41 AM 发表
可以了。。谢谢。。
select distinct(family),b.productname from tblproductlookup a
full outer join .j_autouph.dbo.tblProd b
on
case when charindex('-',a.family)>0 then substring(a.family,0, ...
这样写很长, 应该尝试自行写 function 缩短你的 code. |
|
|
|
|
|
|
|
发表于 23-11-2006 01:53 PM
|
显示全部楼层
|
|
|
|
|
|
|

楼主 |
发表于 25-11-2006 05:29 PM
|
显示全部楼层
原帖由 goatstudio 于 23-11-2006 01:50 PM 发表
这样写很长, 应该尝试自行写 function 缩短你的 code.
说的没错。谢谢  |
|
|
|
|
|
|
|

楼主 |
发表于 25-11-2006 05:29 PM
|
显示全部楼层
问问各位
return table 的 fucntion 好用点还是 view 好用点? |
|
|
|
|
|
|
|

楼主 |
发表于 29-11-2006 08:47 AM
|
显示全部楼层
|
|
|
|
|
|
|
发表于 29-11-2006 09:11 AM
|
显示全部楼层
原帖由 tensaix2j 于 25-11-2006 05:29 PM 发表
问问各位
return table 的 fucntion 好用点还是 view 好用点?
这两个是不同的东西呢... 用途也不一样... |
|
|
|
|
|
|
|

楼主 |
发表于 29-11-2006 09:36 AM
|
显示全部楼层
有一个东西我还弄不清楚。
若我有5 个file group, 1 个 mdf。。
vs
我有1 个file group,1 个mdf,4个 ndf,
哪个比较efficient? |
|
|
|
|
|
|
|

楼主 |
发表于 29-11-2006 09:45 AM
|
显示全部楼层
原帖由 goatstudio 于 29-11-2006 09:11 AM 发表
这两个是不同的东西呢... 用途也不一样...
为何不可以用return table 的function来代替view 呢?
比如:
create view vwA as
select colA,colB from tblA
用以下来代替
create function funcA
(
--no parameter
)
returns table as
return
(
select colA,colB from tblA
)
所以
select * from vwA
变可以用以下来代替
select * from funcA() |
|
|
|
|
|
|
|
发表于 29-11-2006 11:00 AM
|
显示全部楼层
原帖由 tensaix2j 于 29-11-2006 09:45 AM 发表
为何不可以用return table 的function来代替view 呢?
比如:
create view vwA as
select colA,colB from tblA
用以下来代替
create function funcA
(
--no parameter
)
returns table as ...
问题在于, 你可以在 sql 里直接呼叫 function.
例如:
SELECT functionA(columA) FROM tablename
这是 view 做不到的. |
|
|
|
|
|
|
| |
本周最热论坛帖子
|