数据库将字符串转换为多行
来源:互联网 发布:烟台seo整站优化方案 编辑:程序博客网 时间:2024/06/04 18:22
sql server数据库:
if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[fn_StrToTable]') and xtype in (N'FN', N'IF', N'TF'))
drop function [dbo].[fn_StrToTable]
GO
Create Function fn_StrToTable(@str varchar(max))
Returns @tableName Table
(
goodsid char(11)
)
As
Begin
set @str = @str+','
Declare @insertStr char(11) --截取后的第一个字符串
Declare @newstr varchar(max) --截取第一个字符串后剩余的字符串
set @insertStr = left(@str,charindex(',',@str)-1)
set @newstr = stuff(@str,1,charindex(',',@str),'')
Insert @tableName Values(@insertStr)
while(len(@newstr)>0)
begin
set @insertStr = left(@newstr,charindex(',',@newstr)-1)
Insert @tableName Values(@insertStr)
set @newstr = stuff(@newstr,1,charindex(',',@newstr),'')
end
Return
End
drop function [dbo].[fn_StrToTable]
GO
Create Function fn_StrToTable(@str varchar(max))
Returns @tableName Table
(
goodsid char(11)
)
As
Begin
set @str = @str+','
Declare @insertStr char(11) --截取后的第一个字符串
Declare @newstr varchar(max) --截取第一个字符串后剩余的字符串
set @insertStr = left(@str,charindex(',',@str)-1)
set @newstr = stuff(@str,1,charindex(',',@str),'')
Insert @tableName Values(@insertStr)
while(len(@newstr)>0)
begin
set @insertStr = left(@newstr,charindex(',',@newstr)-1)
Insert @tableName Values(@insertStr)
set @newstr = stuff(@newstr,1,charindex(',',@newstr),'')
end
Return
End
with a as (select ',G0ZL08F4EIS,G09OHEQ2DLI,G0BK8OCHSBY' id from dual)
select regexp_substr(id,'[^,]+',1,rownum) goodsid from a
connect by rownum<=length(regexp_replace(id,'[^,]+'))
0 0
- 数据库将字符串转换为多行
- 将一列字符串显示为转换为多行显示
- SQLSERVER数据库将数值类型转换为字符串的问题
- 将字符串转换为数值
- 将字符串转换为大写
- 将整数转换为字符串
- 将数字转换为字符串
- 将数字转换为字符串
- 将数字转换为字符串
- 将字符串转换为整数
- 将字符串转换为数字
- 将字符串转换为数字
- 将字符串转换为整数
- 将字符串转换为数字
- 将字符串转换为整数
- 将字符串转换为数字
- 将字符串转换为整数
- 将字符串转换为整数
- Android中ListView如何获取列表中选中的CheckBox
- iOS 应用开发入门指南,中文教程
- 鼠标的位置控制
- android中ListView控件&&onItemClick事件中获取listView传递的数据
- 【个人机房重构】—— 抽象工厂+反射+配置文件详解以及错误分析
- 数据库将字符串转换为多行
- Android多线程及异步任务消息处理机制(一)--Handler的使用
- aop,spring aop,aspectj区别与联系
- 测试结果分析
- 窗口的消息处理
- NYOJ-求转置矩阵问题
- EBS R12客户信息
- JUnit 4 with Hamcrest
- 性能数据