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

sql字元增加

發布時間: 2023-01-09 23:32:11

A. sql語句來增加字元串位數

用不用游標都可以,不用更簡潔。
主要是用到一些字元串函數,如len--求字元串的長度,ltrim--去除字元串的前導空格
rtrim---去除字元串的尾部空格
方法一:直接用update語句
update
employee
set
empno='000'+ltrim(rtrim(empno))
where
len(ltrim(rtrim(empno)))=3
update
employee
set
empno='00'+ltrim(rtrim(empno))
where
len(ltrim(rtrim(empno)))=4
方法二:採用游標
declare
cur
scroll
cursor
for
select
empno
from
employee
for
update
open
cur
declare
@ex
char(10)
fetch
first
from
cur
into
@ex
while
@@fetch_status=0
begin
if
len(ltrim(rtrim(@ex)))=3
update
employee
set
empno='000'+ltrim(rtrim(empno))
where
current
of
cur
else
if
len(ltrim(rtrim(@ex)))=4
update
employee
set
empno='00'+ltrim(rtrim(empno))
where
current
of
cur
fetch
next
from
cur
into
@ex
end
close
cur
deallocate
cur

B. 如何用Sql語句添加欄位

USE
bankDB
GO
CREATE
TABLE
cardInfo
(
cardID
varchar(19)
not
null,
--卡號
curType
varchar(10)
not
null,
--貨幣種類
默認為人民幣
savingType
varchar(8)
not
null,
--存款類型
活期、定期
openDate
datetime
not
null,
--開戶日期
openMoney
money
not
null,
--開戶金額
balance
money
not
null,
--余額
pass
int
not
null,
--密碼
6位數字,默認為6個『8』
IsReportLose
char(2)
not
null,
--是否掛失
默認為「否」
customerID
int
not
null
--顧客編號,外鍵(一位顧客允許辦理多張卡)
)
go
ALTER
TABLE
cardInfo
ADD
CONSTRAINT
PK_cardID
PRIMARY
KEY(cardID),
CONSTRAINT
CK_cardID
CHECK(cardID
LIKE
'1010
3576
[0-9][0-9][0-9][0-9]
[0-9][0-9][0-9][0-9]'),
CONSTRAINT
DF_curType
DEFAULT('人民幣')
FOR
curType,
CONSTRAINT
DF_openDate
DEFAULT(getdate())
FOR
openDate,
CONSTRAINT
CK_openMoney
CHECK(openMoney>=1),
CONSTRAINT
CK_balance
CHECK(balance>=1),
CONSTRAINT
DF_pass
DEFAULT('888888')
FOR
pass,
CONSTRAINT
DF_IsReportLoss
DEFAULT('0')
FOR
IsReportLose,
CONSTRAINT
FK_customerID
FOREIGN
KEY(customerID)
REFERENCES
userInfo(customerID)
GO

C. sql語句在欄位中增加字元

用replace函數
——————————
要看你要怎麼改法了
是一個空格用一個下劃線
還是全部相連的空格都只用一個下劃線?不同的要求就有不同的函數
——————————————

那容易多了loveyurui
說的就是,repalce(name,'
','_')
使用的話,比如更新
update
table
set
name
=repalce(name,'
','_')
不過建議哦
字元過濾建議在應用環境實現,對於效率安全都更好

D. SQL資料庫指定某張表特定欄位全部統一增加指定字元

update
表名1
set
欄位1=
欄位1
+
'你想加的字元串'
//要是想加在前邊,就是:set
欄位1=
'你想加的字元串'
+
欄位1
//想只加一部分,就加個where
條件。

E. 如何用sql語句在字元串中添加字元

正常情況下把要添加的字元串和原字元串用「+」連接即可。

如:將原有的abc後邊加上123.

select'abc'+'123'

結果:

update表名set欄位名=欄位名+'要添加字元串'

F. sql查詢內容加字元

select id, sex+『abc' from user
在你需要增加字元的欄位後面以 +'.....' 的形式將需要增加的內容列出來即可。

G. SQL增加字元的問題


declare 是聲明一個變數 @name
rtrim是刪除FLD_CHARATER 右邊的空

DECLARE @name varchar(25)
set @name='~'
UPDATE [game1].[dbo].[TBL_BOBUJIFEN]
SET FLD_CHARACTER=rtrim(FLD_CHARACTER)+@name
最後的是更新game1庫中的,TBL_BOBUJIFEN表中的FLD_CHARACTER欄位

H. 如何使用SQL在某欄位原有字元前,後添加新字元

--貌似沒有難度

--某欄位原有字元前添加新字元
update表1set欄位1='ABC'+欄位1
--某欄位原有字元後添加新字元
update表1set欄位1=欄位1+'ABC'