当前位置: 代码迷 >> Oracle管理 >> 两列数据合并,该如何解决
  详细解决方案

两列数据合并,该如何解决

热度:97   发布时间:2016-04-24 05:19:45.0
两列数据合并
A B 
aa 11
bb 22

合并后的数据为 aa11,bb22 A表是varchar B表是int

------解决方案--------------------
转个类型
SQL code
select wm_concat(to_char(A)||to_char(B)) c1from t1
------解决方案--------------------
参考:
SQL code
if object_id('[tb]') is not null drop table [tb]gocreate table [tb] (code int,bill_code nvarchar(6))insert into [tb]select 4010305,'001' union allselect 4010305,'005' union allselect 4010306,'007' union allselect 4010307,'009' union allselect 4010305,'003'if object_id('dbo.f_str')is not null drop function dbo.f_strgoCREATE FUNCTION dbo.f_str(@code int)RETURNS varchar(8000)ASBEGIN    DECLARE @r varchar(8000)    SET @r = ''    SELECT @r = @r + ',' + bill_code    FROM tb    WHERE code=@code    RETURN STUFF(@r, 1, 1, '')ENDGOselect dbo.f_str(4010305)/*001,005,003(1 個資料列受到影響)*/
  相关解决方案