V2EX = way to explore
V2EX 是一个关于分享和探索的地方
Sign Up Now
For Existing Member  Sign In
yomate
V2EX  ›  数据库

sql server where 查询时 字段是 nvarchar 类型的保存的数字 但是可以用 int 类型的数字去匹配,这是什么原理?

  •  
  •   yomate · Sep 11, 2025 · 2034 views
    This topic created in 229 days ago, the information mentioned may be changed or developed.
    4 replies    2025-09-12 00:55:58 +08:00
    Satoshl
        1
    Satoshl  
       Sep 11, 2025
    隐式转换,sql 数据有转换优先级
    Configuration
        2
    Configuration  
       Sep 11, 2025
    隐式转换呗,日期字段你还不照样是 where xxx_date = '2025-09-11',但你要是 where xxx_date = '2025-09-51' 它照样报错转换错误
    xchangyouren
        3
    xchangyouren  
       Sep 11, 2025
    DBMS 都有的类型转换,因为不是用户直接指定的,所以称为 隐式类型转换。隐式类型转换可能会导致无法使用索引。避免隐式类型转换是索引优化方法之一
    nobody1234
        4
    nobody1234  
       Sep 12, 2025
    数据类型优先级:
    https://learn.microsoft.com/zh-cn/sql/t-sql/data-types/data-type-precedence-transact-sql?view=sql-server-ver17

    在编程语言中也有类似机制,我记得 C 语言也有
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   989 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 33ms · UTC 19:32 · PVG 03:32 · LAX 12:32 · JFK 15:32
    ♥ Do have faith in what you're doing.