0

以下查询适用于数值数据类型(int、bigint 等)。我想做同样的事情,但将其应用于 varchar。这可能吗?如何?

CREATE SEQUENCE acct_seq
 START WITH 1
 INCREMENT BY 1
 NO MAXVALUE
 NO CYCLE
 CACHE 24
;

SELECT accntnum  AS new_acct, old_acct
FROM FINAL TABLE (
UPDATE accounts INCLUDE(old_acct INT)
SET accntnum = NEXT VALUE FOR acct_seq, old_acct = accntnum
)
ORDER BY old_acct;

就行UPDATE accounts INCLUDE(old_acct INT)而不是 int 我想使用VARCHAR(size). 大小将在 4 到 100 之间。

4

1 回答 1

1

首先将 INT 转换为 CHAR,然后转换为 VARCHAR。

SET accntnum = cast(cast(NEXT VALUE FOR acct_seq as CHAR(255)) as VARCHAR(255)), old_acct = accntnum

于 2013-08-21T15:07:37.077 回答