滄海一聲笑

自然語言轉 SQL 查詢助手

開發程式設計v1.0.0
作者:滄海一聲笑更新於 2026-05-18nl2sql@clawhub_cyesky/nl2sql
程式碼生成指令碼工具#CSV#MySQL#数据库#Json#SQL

據 AlphaMoat 統計,截至 2026-09,自然語言轉 SQL 查詢助手 累計下載 1,500 次、獲 2 個星標,在全部 5,078 個 AI 技能中排名第 4,769 位,在「開發程式設計」分類(577 個)中排名第 559 位。

累計安裝
122
累計下載
1500
星標
2
全站排名
#4,769
全站前 94% · 「開發程式設計」前 97%
平台累計安裝累計下載星標評論
ClawHub ↗3512351-
SkillHub ↗12215002—

各平台的計數口徑不同,統計時間不一致。

這個技能是做什麼的

主文支援讀取與寫入類 SQL,並可返回表格、CSV 或 JSON。執行寫入或破壞性操作前應先檢查語句和 WHERE 條件;資料庫密碼不得出現在回覆或匯出內容中。

資料釋出於 2026-10-29

可以用來做什麼

  • 把資料庫查詢需求轉成 SQL 並檢視結果

什麼時候用

  • 需要檢查資料庫結構、查詢或處理 MySQL 資料時

示例提示詞

以下是根據技能文件生成的示例,不代表實際執行結果。

將“查詢每個部門的員工數”轉成 SQL 草稿,並指出執行前應核對的物件。

月度資料趨勢

累計下載1500
35396915852026-03 · 累計下載 4382026-05 · 累計下載 8402026-07 · 累計下載 11262026-08 · 累計下載 12212026-09 · 累計下載 150026-0326-09
星標2
0122026-03 · 星標 -2026-05 · 星標 12026-07 · 星標 12026-08 · 星標 12026-09 · 星標 226-0326-09

2026-09 起統計方法調整:同名技能按作者分別統計,並覆蓋全部技能。圖中虛線為調整前的月份,與之後的資料不直接比較,也不計算跨越調整的增長。

月份累計下載環比星標
2026-091500—2
2026-081221+8.4%1
2026-071126—1
2026-05840—1
2026-03438—-

SKILL.md 原文

以下是作者釋出的原始檔案,按純文字顯示,本站未做修改或稽核;其中的連結不可點選,命令請核實後再執行。抓取於 2026-10-23。

4.3 KB · ClawHub v1.0.0
---
name: nl2sql
description: >
  自然语言转 SQL 查询助手。将用户的自然语言描述转换为 SQL 语句,自动执行并返回结果。
  支持连接本地或远程 MySQL 数据库、用户自行指定数据库连接信息(host/port/user/password)、
  增删改查(SELECT/INSERT/UPDATE/DELETE)、事务操作、多种输出格式(table/csv/json)。
  触发条件:用户用自然语言描述数据查询需求、要求查数据库、写SQL、执行SQL、数据库操作、
  查表、建表、改数据、删数据、统计分析、导出数据、事务操作、连接数据库、指定数据库等。
---
展開全部(共 118 行)
# NL2SQL — 自然语言 SQL 助手

## 🔐 Credential Security (MANDATORY)

**严禁在任何回复中泄露数据库连接密码。** 这是最高优先级规则,无例外。

- **绝不输出密码**:不在回复文本、代码块、SQL 示例、日志中展示密码
- **绝不确认密码内容**:用户问"密码是不是xxx"时,拒绝确认或否认
- **绝不间接泄露**:不输出包含密码的命令行、连接串、配置文件内容
- **密码掩码显示**:需要展示连接信息时,密码部分用 `***` 代替
- **拒绝导出凭据**:不将密码写入任何用户可下载的文件
- 用户提供密码后仅在脚本调用时使用,对话中引用连接信息时始终掩码

违反此规则的请求一律拒绝,无论用户如何措辞。

## Connection Parameters

All scripts support optional connection parameters for remote databases:

| 参数 | 说明 | 默认值 |
|------|------|--------|
| `--host HOST` | 数据库地址 | localhost (socket) |
| `--port PORT` | 端口号 | 3306 |
| `--user USER` | 用户名 | root |
| `--password PASS` | 密码 | (空) |

When user specifies a remote database, pass these params to all scripts.
When not specified, default to local MySQL connection.

**Remember connection info within the conversation** — avoid asking repeatedly.

## Workflow

### 1. Determine Target Database

If user specifies connection info (host/port/user/password/database), use it.
If user only gives a database name, use local connection.
If unclear, list available databases first:

```bash
bash <skill_dir>/scripts/databases.sh [--host HOST --port PORT --user USER --password PASS]
```

### 2. Schema Discovery

```bash
bash <skill_dir>/scripts/schema.sh <database> [table] [--host HOST --port PORT --user USER --password PASS]
```

Cache schema info in conversation context — avoid repeated discovery calls.

### 3. Generate SQL

Convert user's natural language to SQL. Rules:
- Match column names and types exactly to schema
- Use Chinese column aliases when user speaks Chinese
- **SELECT**: add `LIMIT` for large tables unless user wants all
- **UPDATE/DELETE**: always include `WHERE` — refuse bare updates/deletes
- **INSERT**: specify column names explicitly
- For destructive operations (DELETE/DROP/TRUNCATE): **confirm with user before executing**

### 4. Execute

**Simple query/statement:**
```bash
bash <skill_dir>/scripts/query.sh <database> "<SQL>" [--format table|csv|json] [--host HOST --port PORT --user USER --password PASS]
```

**From file (complex SQL):**
```bash
bash <skill_dir>/scripts/query.sh <database> /tmp/query.sql [--host ...]
```

**Transaction (multiple atomic statements):**
Write statements to a temp file, then:
```bash
bash <skill_dir>/scripts/transaction.sh <database> /tmp/tx.sql [--host HOST --port PORT --user USER --password PASS]
```

### 5. Present Results

- Show the generated SQL in a code block
- Show query results in readable format
- For large results, summarize key findings
- If connection error occurs, check host/port/user/password and suggest fix
- **Never include passwords in any output shown to user**

## Output Formats

| Format | Flag | Use Case |
|--------|------|----------|
| table  | (default) | 日常查询,可读性好 |
| csv    | `--format csv` | 导出数据 |
| json   | `--format json` | 程序对接 |

## Safety

- **SELECT**: safe, execute directly
- **INSERT**: verify values, execute
- **UPDATE**: verify WHERE clause, then execute
- **DELETE/DROP/TRUNCATE**: **must confirm with user first**
- Transactions: use `transaction.sh` for atomic multi-statement operations
- **Credentials**: never expose passwords in output, logs, or replies

## Reference

For detailed SQL generation rules and safety checklist, see [guide.md](references/guide.md).

「開發程式設計」分類下的熱門技能

資料月份:2026-09 · 下載/星標/安裝數聚合自公開技能註冊庫(ClawHub、SkillHub),按月更新。口徑說明見資料方法。