當前位置:首頁 » 編程語言 » sql數據分號分割
擴展閱讀
webinf下怎麼引入js 2023-08-31 21:54:13
堡壘機怎麼打開web 2023-08-31 21:54:11

sql數據分號分割

發布時間: 2022-06-22 06:36:45

sql中用逗號來分隔數據

用,分隔數據的讀取:
<%
a="a,b,c,d,e,f,g,h,j,k,l"
b=split(a,",")
for i=0 to ubound(b)
response.write(b(i))
response.Write ","
next
%>

用,分隔數據的存入:可以使用多選下拉菜單.
<select name="source" size="7" multiple id="source">
<option value="1">fff</option>
<option value="2">tttt</option>
<option value="3">www</option>
<option value="4">aaa</option>
</select>
你可以試一下,當你選擇了多個項目時,request.form("source")的值就是1,2,3 這種格式

② SQL語言如何將表內字元串按分割符號分割存儲

用replace函數,將分號或者 @ 符號, 替換為你的其他分隔符。

REPLACE
用第三個表達式替換第一個字元串表達式中出現的所有第二個給定字元串表達式。
語法
REPLACE ( ''string_replace1'' , ''string_replace2'' , ''string_replace3'' )
參數
''string_replace1''
待搜索的字元串表達式。string_replace1 可以是字元數據或二進制數據。
''string_replace2''
待查找的字元串表達式。string_replace2 可以是字元數據或二進制數據。
''string_replace3''
替換用的字元串表達式。string_replace3 可以是字元數據或二進制數據。
返回類型
如果 string_replace(1、2 或 3)是支持的字元數據類型之一,則返回字元數據。如果 string_replace(1、2 或 3)是支持的 binary 數據類型之一,則返回二進制數據。
示例
下例用 xxx 替換 abcdefghi 中的字元串 cde。
SELECT REPLACE(''abcdefghicde'',''cde'',''xxx'')GO
下面是結果集:
------------abxxxfghixxx(1 row(s) affected)

③ sql 如何以逗號為分隔符分割一個欄位的值

可用substring函數。

創建測試表及數據:

createtabletest
(idvarchar(10));

insertintotestvalues('123abc');
insertintotestvalues('456def');
insertintotestvalues('789ghi');

執行:

selectsubstring(id,1,3)+','+substring(id,4,3)asidfromtest

結果截圖:

也就顯示成了用逗號分隔的樣子。

④ SQL 怎麼將一列中的數據按一個分隔符分成多列顯示

withHrmResource(id,lastname)as(
select167,'段秋月'unionall
select170,'楊子軍'
)
,formtable_main_78(Requestid,WTCW,XMCY)as(
select722,'xxxxx公司','167,170'
)

selecta.*,stuff(c.[col],1,1,'')[項目名稱]
fromformtable_main_78a
crossapply
(select','+lastnamefromHrmResourceb
wherecharindex(','+convert(varchar,b.id)+',',','+a.XMCY+',')>0
forxmlpath(''))c([col])

結果:

⑤ sql查詢問題,如何一個個取出按分號隔開的數據

-- SELECT * FROM dbo.FunSplitStringToAraay( '28,353,2,35,88 ', ',')
CREATE FUNCTION dbo.FunSplitStringToAraay(@vchString varchar(1000),@vchSplit varchar(10))
RETURNS @tabArray table
(
string varchar(100)
)
AS
BEGIN
DECLARE @intStart int
DECLARE @intLocation int
DECLARE @vchSubstring varchar(100)
SELECT @intStart =1
SELECT @intLocation = CHARINDEX(@vchSplit,@vchString,@intStart)
WHILE (@intLocation <> 0 )
BEGIN
SELECT @vchSubstring=SUBSTRING(@vchString,@intStart,@intLocation-@intStart)

INSERT INTO @tabArray(string) SELECT @vchSubstring
SELECT @intStart = @intLocation +1
SELECT @intLocation = CHARINDEX(@vchSplit,@vchString,@intStart)
END
RETURN
END

⑥ SQL拆分逗號分隔的字元串

1、首先點擊新建查詢按鈕,新建一個查詢。

⑦ sql如何根據隔符分割字元串

  1. 資料庫自帶的substring()、charindex()函數,可以根據需要截取字元串,但並不能實現分割

  2. 自己寫分割函數,以下可以參考:

createfunctionGetStr
(
@strvarchar(1024),--要分割的字元串
@splitvarchar(10),--分隔符號
@indexint--取第幾個元素
)
returnsvarchar(1024)
as
begin
declare@locationint
declare@startint
declare@nextint
declare@seedint
set@str=ltrim(rtrim(@str))
set@start=1
set@next=1
set@seed=len(@split)

set@location=charindex(@split,@str)
while@location<>0and@index>@next
begin
set@start=@location+@seed
set@location=charindex(@split,@str,@start)
set@next=@next+1
end
if@location=0select@location=len(@str)+1
returnsubstring(@str,@start,@location-@start)
end

⑧ mysql 執行多條sql用分號隔開自帶事物嗎

需要,具體做法是把多條SQL命令寫在同一個字元串里作為參數傳遞給multi_query()方法,多條SQL之間使用分號 (;)分隔(包括在自帶事物)。如果第一條SQL命令在執行時沒有出錯,這個方法就會返回TRUE,否則將返回FALSE。

⑨ sql一個欄位內有分隔符如何拆分成多行

select num,id, substr(test1,0,instr(test1, ',')-1) test1, substr(test2,0,instr(test2, ',')-1) test2, substr(test3,0,instr(test3, ',')-1) test3 from table_name --前
union
select num,id, substr(test1,instr(test1, ',')+1) test1, substr(test2,instr(test2, ',')+1) test2, substr(test3,instr(test3, ',')+1) test3 from table_name --後

instr(test1, ',') 是計算逗號的位置。