发表机构
Torrens University Australia(澳大利亚托伦斯大学)
机构由 AI 辅助整理,请以论文原文为准。AI 中文总结
研究大型语言模型在Oracle数据库执行SQL失败的问题,提出模式感知本地化(SAL)轻量级中间件,通过构建实时模式映射、注入上下文及幻觉索引验证等方法,提升执行基础真值,减少执行失败率。
AI 中文摘要
大型语言模型能从自然语言生成流畅的SQL,但在实际企业Oracle数据库上执行时经常失败,原因是列和别名幻觉以及特定方言语法缺失,主要是缺少模式基础。本文介绍了模式感知本地化(SAL),这是一个用于Oracle NL2SQL的轻量级中间件层,无需模型重新训练。SAL查询Oracle的USER_TAB_COLUMNS目录构建实时模式映射,为每个问题选择相关表子集,将真实上下文注入大语言模型提示。生成的SQL由幻觉索引(Hidx)检查,验证每个引用并自动重写可预测的前缀错误,否则触发结构化重试并进行详细更正。我们使用GPT-4o-mini在实时Oracle Autonomous Database 23c实例上对500个TPC-H自然语言问题评估SAL。无模式基础时,执行基础真值(EGT)为2.2%;手写静态模式提示使EGT达到62.0%;SAL在无手动模式策划时达到62.6%的EGT,同时将执行失败率从97.6%降至2.6%。
英文摘要
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%.
Comments18 pages , 3 figures , 14 tables ,1 algorithm