如何在Sybase上投射或转换为VARCHAR数据类型?

发布于 2025-01-26 07:44:38 字数 572 浏览 3 评论 0原文

DECLARE
    @k numeric,
    @acc numeric
SET
    @k = 651393561522 ,
    @acc = 1231234560
WHILE (@k < 651393563552)
    BEGIN
        SET @k = @k + 1 ,
            @acc = @acc + 1
        insert into recipients (id, client_id, inn, name, bic, bill, version)
        VALUES(@k, 1, @acc, 'clientid'+ cast(@k as varchar), 300335, 'bill'+cast(@acc as varchar), 1)
    END

有这样的错误:

[42000] [257]不允许从数据类型'数字'到“ varchar”&gt;的隐式转换。使用转换函数运行此查询。

[42000] [257]不允许从datatype'int'到'varchar'的隐式转换。使用转换函数运行此查询。

DECLARE
    @k numeric,
    @acc numeric
SET
    @k = 651393561522 ,
    @acc = 1231234560
WHILE (@k < 651393563552)
    BEGIN
        SET @k = @k + 1 ,
            @acc = @acc + 1
        insert into recipients (id, client_id, inn, name, bic, bill, version)
        VALUES(@k, 1, @acc, 'clientid'+ cast(@k as varchar), 300335, 'bill'+cast(@acc as varchar), 1)
    END

Have such errors:

[42000][257] Implicit conversion from datatype 'NUMERIC' to 'VARCHAR' >is not allowed. Use the CONVERT function to run this query.

[42000][257] Implicit conversion from datatype 'INT' to 'VARCHAR' is >not allowed. Use the CONVERT function to run this query.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

寒冷纷飞旳雪 2025-02-02 07:44:38

错误消息提及 隐式 转换错误,因此这往往排除 显式 。代码> cast()调用。

这给我们留下了其他列/值的数据类型不匹配问题。 OP将需要对收件人列的数据表进行二次检查:

  • 第一个错误消息提及数字到varchar,并且由于唯一的数字值是@k < /code>和@acc,我猜想IDinn列定义为varchar /p>

  • 第二个错误消息提及varchar的整数,以及sybase(ASE) )对待1300335作为整数,我猜是client_idbill列定义为varchar

The error messages mention implicit conversion errors so this would tend to rule out the explicit conversions being performed by the cast() calls.

This leaves us with datatype mismatch issues for the other columns/values; OP will want to doublecheck the datatypes of the recipients columns:

  • the 1st error message mentions numeric to varchar and since the only numeric values are @k and @acc, I'm guessing either the id or inn column is defined as varchar

  • the 2nd error message mentions integer to varchar and since Sybase (ASE) treats 1 and 300335 as integers, I'm guessing either the client_id, bill or version column is defined as varchar

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文