SQLCMD:提示变量? [英] SQLCMD: Prompt for Variable?
问题描述
来自 Oracle 背景,Oracle 的 SQLPlus 可以让您指示一个变量.如果未设置该变量,系统会提示您提供一个值.
Coming from an Oracle background, Oracle's SQLPlus would let you indicate a variable. If the variable wasn't set, you'd be prompted to provide a value.
我正在使用 SQLCMD,使用 $([var_name]) 语法.在 SSMS SQLCMD 模式下,我得到:
I'm using SQLCMD, using the $([var_name]) syntax. In SSMS SQLCMD mode, I get:
发生了致命的脚本错误.
变量 tbl_name 未定义.
A fatal scripting error occurred.
Variable tbl_name is not defined.
...尝试运行:
SELECT COUNT(*) FROM $(tbl_name)
SQLCMD 是否提供与 SQLPlus 相同的功能?如果是这样,我做错了什么?
Does SQLCMD provide the same functionality as SQLPlus? If so, what am I doing wrong?
推荐答案
SQLCMD 不支持提示缺少变量名.但是,您可以在 SQLCMD 模式下使用 SSMS.不知道你的错误是如何引起的,但这对我有用:
SQLCMD does not support prompting for missing variable names. However, you can use SSMS in SQLCMD mode. Dunno how you're error was caused, but this works for me:
:setvar table "sys.tables"
SELECT * FROM $(table);
这篇关于SQLCMD:提示变量?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!