# sql: 第 1 列扫描错误：将 driver.Value 类型 string ("hello") 转换为 int：无效语法

- **ID:** `go/database-sql-rows-scan-type`
- **领域:** go
- **类别:** data_error
- **验证级别:** ai_generated
- **修复率:** 80%

## 根因

数据库返回的值无法在 Scan 期间转换为目标 Go 类型，通常是由于架构不匹配。

## 版本兼容性

| 版本 | 状态 | 引入 | 弃用 |
|------|------|------|------|
| 1.16 | active | — | — |
| 1.20 | active | — | — |

## 解决方案

1. **** (85% 成功率)
   ```
   Scan into an intermediate type and convert: var tmp string; rows.Scan(&tmp); val, _ := strconv.Atoi(tmp)
   ```
2. **** (90% 成功率)
   ```
   Use sql.NullInt64 to handle nullable/invalid values: var n sql.NullInt64; rows.Scan(&n); if n.Valid { val := n.Int64 }
   ```

## 无效尝试

- **** — May not be feasible in production or requires migration. (60% 失败率)
- **** — Leads to incorrect data handling and potential bugs. (80% 失败率)
