arXiv:2607.22572cs.AI2026-07

让大模型生成的SQL不再乱编字段,实时校验并修正错误。

Schema-Aware Localisation (SAL): Live Schema Grounding and Hallucination Validation for Oracle NL2SQL

  • 用Oracle实时元数据构建查询上下文,注入大模型提示词。
  • 执行成功率从2.2%提升至62.6%,复杂查询也达40.7%。
  • 无需重训练模型,适合企业级Oracle数据库场景。

大语言模型能生成流畅的SQL,但在真实企业Oracle数据库中常因虚构列名或遗漏方言语法而失败,导致ORA-00904错误。根本原因是缺乏模式上下文感知。本文提出轻量级中间件SAL,无需重训练模型,通过查询Oracle USER_TAB_COLUMNS目录实时构建模式映射,为每条问题选择相关表子集(多表查询回退至全模式),并将真实上下文注入LLM提示。生成的SQL经由幻觉指数(Hidx)验证,逐项检查别名.列引用,自动修正可预测前缀错误,否则触发结构化重试并列出修正项。在500个TPC-H自然语言问题上测试,使用GPT-4o-mini与实时Oracle Autonomous Database 23c。无模式感知时执行成功且结果一致率仅2.2%(12/500);手动静态提示提升至62.0%;SAL无须人工模式标注即达62.6%(简单题96%、中等题95%、复杂题40.7%),执行失败率从97.6%降至2.6%。

原文摘要 · Abstract (English)

Large language models can generate fluent SQL from natural language, but on real enterprise Oracle databases they frequently fail at execution time: columns and aliases are hallucinated and dialect-specific syntax is missed, leading to ORA-00904 invalid-identifier errors. In this setting, failures are primarily due to missing schema grounding: the model cannot know which tables and columns actually exist. This paper introduces Schema-Aware Localisation (SAL), a lightweight middleware layer for Oracle NL2SQL that requires no model retraining. SAL queries Oracle's USER_TAB_COLUMNS catalog to build a live schema map, selects a relevant table subset for each question (falling back to the full schema for multi-table queries), and injects this ground-truth context into the LLM prompt. Generated SQL is then checked by the Hallucination Index (Hidx), which validates every alias.column reference against the live catalog, automatically rewrites predictable prefix errors, and otherwise triggers a structured retry with itemised corrections. We evaluate SAL on 500 TPC-H natural language questions executed against a live Oracle Autonomous Database 23c instance using GPT-4o-mini. Without any schema grounding, execution-grounded truth (EGT; executes and matches the reference result set) is 2.2% (12/500). A hand-written static schema hint brings EGT to 62.0%. SAL, with no manual schema curation, achieves 62.6% EGT (96% simple, 95% medium, 40.7% complex) while reducing execution failures from 97.6% to 2.6%.

NL2SQLOracle幻觉检测实时校验

Thank you to arXiv for use of its open access interoperability. PaperDance 不是 arXiv 官方产品;中文卡片由大模型生成,请以原文为准。