久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

無法連接到末尾帶有 CHAR(0) 的字符串

Can#39;t concatenate to strings with CHAR(0) at the end(無法連接到末尾帶有 CHAR(0) 的字符串)
本文介紹了無法連接到末尾帶有 CHAR(0) 的字符串的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

限時送ChatGPT賬號..

以下代碼片段應該展示了我在 SQL Server 和我的 VBScript Web 應用程序中觀察到的一個問題:

SELECT '"Hello World"'SELECT '"Hello World' + CHAR(0) + '"'

結果:

你好世界"你好,世界

請注意,第二個結果行缺少最后的雙引號.

我知道您不能在 SQL Server 中將字符串連接到 NULL 值.但是,以下代碼段表明,就 SQL Server 而言,CHAR(0) 不被視為 NULL.

SELECT ISNULL(CHAR(0), 'CHAR(0) 被認為是 NULL')

結果:

<預><代碼>

此外,當我從 DB 中將此值讀入 VBScript 中的變量時,我也無法連接到該變量.

我不是 C 開發人員,但我知道 C 風格的字符串以空字符結尾.這是否相關?有人可以幫助我理解為什么在 SQL Server 和 VBScript 中會發生這種情況嗎?

我可以通過簡單地替換違規數據中的所有 CHAR(0) 來解決我的直接問題,但首先我想了解這樣做的原因并制定預防性解決方案.

<小時>

包括一些 VBScript

testSql = "SELECT '""Hello World' + CHAR(0) + '""' AS TestString"設置結果集 = conn.execute(testSql)testString = resultSet.Fields.Item("TestString")testString = testString &}"Response.Write 測試字符串

結果:

"Hello World

解決方案

SQL Server 連接以 nul 字符結尾的字符串就好了.看這個例子:

SELECT len('"Hello World' + CHAR(0) + '"')

輸出:

14

SELECT len('"Hello World' + CHAR(0) + '"' + '"Hello World' + CHAR(0) + '"')

輸出:

28

當您先將字符串存儲到 CTE 或表中時,結果是一樣的.

它在 VB 中的處理和輸出使它看起來好像沒有.嘗試打印您在 VB 中從 SQL 中得到的字符串的長度.

The following snippets should demonstrate an issue I've observed in both SQL Server and in my VBScript web application:

SELECT '"Hello World"'
SELECT '"Hello World' + CHAR(0) + '"'

Results:

"Hello World"
"Hello World

Notice that the second result line is missing the final double quote.

I understand that you can't concatenate strings to a NULL value in SQL Server. However, the following snippet reveals that CHAR(0) is not considered NULL as far as SQL Server is concerned.

SELECT ISNULL(CHAR(0), 'CHAR(0) IS CONSIDERED NULL')

Result:


Also, when I read this value from the DB into a variable in VBScript, I'm unable to concatenate to that variable as well.

I'm not a C developer, but I understand that C-style strings are terminated by the null character. Is this relevant? Can someone please help me understand why this is happening in SQL Server and in VBScript?

I can solve my immediate problem by simply replacing all CHAR(0)'s in the offending data, but first I'd like to understand the reason for this and develop a preventative solution.


EDIT: Including some VBScript

testSql = "SELECT '""Hello World' + CHAR(0) + '""' AS TestString"
set resultSet = conn.execute(testSql)
testString = resultSet.Fields.Item("TestString")

testString = testString & "}"

Response.Write testString

Result:

"Hello World

解決方案

SQL server concatenates strings ending in nul characters just fine. See this example:

SELECT len('"Hello World' + CHAR(0) + '"')

Output:

14

SELECT len('"Hello World' + CHAR(0) + '"' + '"Hello World' + CHAR(0) + '"')

Output:

28

The result is the same when you store the string into a CTE or table first.

Its the handling and output in VB that makes it appear as if it does not. Try to print the length of the string your are getting out of SQL in VB.

這篇關于無法連接到末尾帶有 CHAR(0) 的字符串的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!

相關文檔推薦

What SQL Server Datatype Should I Use To Store A Byte[](我應該使用什么 SQL Server 數據類型來存儲字節 [])
Interpreting type codes in sys.objects in SQL Server(解釋 SQL Server 中 sys.objects 中的類型代碼)
Typeorm Does not return all data(Typeorm 不返回所有數據)
Typeorm .loadRelationCountAndMap returns zeros(Typeorm .loadRelationCountAndMap 返回零)
How to convert #39;2016-07-01 01:12:22 PM#39; to #39;2016-07-01 13:12:22#39; hour format?(如何將“2016-07-01 01:12:22 PM轉換為“2016-07-01 13:12:22小時格式?)
MS SQL: Should ISDATE() Return quot;1quot; when Cannot Cast as Date?(MS SQL:ISDATE() 是否應該返回“1?什么時候不能投射為日期?)
主站蜘蛛池模板: 日本国产欧美 | 久久精品一 | 久久免费精品 | 成人av免费看 | 欧美a在线看 | 国产高清免费视频 | 欧美一区二区三区在线免费观看 | 麻豆视频国产在线观看 | a在线免费观看 | 日韩一区二区在线播放 | 国产一级片网站 | 国产1区 | 欧美日韩中文在线 | 欧美三区在线观看 | 亚洲天堂av在线 | 一区免费看 | 天天操夜夜操 | 日韩成人一区 | 欧美爱爱视频 | 超碰人人爱 | a级大片免费观看 | 免费观看黄色片视频 | 亚洲区中文字幕 | 国内av在线| 精品国偷自产在线 | 亚洲午夜一区二区 | 亚洲国产一区二区三区 | 91资源在线 | 国产成人精品一区二区三区四区 | 国产精品69毛片高清亚洲 | 亚洲国产一区二区三区, | 欧美一级在线视频 | 日韩欧美精品一区 | 性色av网站 | 精品国产乱码久久久久久蜜退臀 | 久草免费视 | 91久久精品一区二区二区 | 一区二区三区免费 | 91精品国产综合久久久久 | 欧美一区二区三区在线看 | caoporn免费在线视频 |