# SQL 扫描错误：列索引 3 上无法将 NULL 转换为字符串

- **ID:** `go/database-scan-null-field`
- **领域:** go
- **类别:** data_error
- **验证级别:** ai_generated
- **修复率:** 90%

## 根因

将数据库中的 NULL 值扫描到非指针的 Go 类型（例如，使用 string 而不是 *string 或 sql.NullString）。

## 版本兼容性

| 版本 | 状态 | 引入 | 弃用 |
|------|------|------|------|
| Go 1.18 | active | — | — |
| Go 1.19 | active | — | — |
| Go 1.20 | active | — | — |
| Go 1.21 | active | — | — |
| Go 1.22 | active | — | — |

## 解决方案

1. ```
   对可空列使用 sql.NullString 或 *string，并在使用前检查 .Valid
   ```
2. ```
   将自定义结构体字段定义为指针以处理 NULL
   ```

## 无效尝试

- **** — This masks the data issue and can lead to incorrect business logic if NULL has semantic meaning. (60% 失败率)
- **** — Pollutes the data and may break other queries or reports. (80% 失败率)
