DBeaver,如何声明变量并使用它们?

新手上路,请多包涵

我只想知道是否可以在 DBeaver 的 sql 编辑器上声明变量并在查询中使用它们

原文由 Elliott Urrutia 发布,翻译遵循 CC BY-SA 4.0 许可协议

阅读 2.2k
1 个回答

基于来自@nicoschl 的非常有用的帖子,这里有一些小的改进:

 -- using declarations
@set datex_start = cast('2120-01-01' as date) as date_start;
-- datex_start is the var name
-- casting the value in the declaration saves us the work later
-- the var can be given a default fieldname (e.g. "date_start")

-- run as a standalone command since the subsequent SELECT statement doesn't return values when it's all run together

select
    ${datex_start}
;

这将返回一个字段名为“date_start”的值“2120-01-01”。

原文由 Tom Renish 发布,翻译遵循 CC BY-SA 4.0 许可协议

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进