nic*_*chl 39
您必须在 DBeaver -> 窗口 -> 首选项 -> 数据库 -> 编辑器 -> SQL 编辑器 -> SQL 处理的“SQL 处理”设置中启用变量处理。有一个Parameters可以更改设置的块。请参阅维基上的动态参数绑定部分。
然后你应该能够做到:
@set date = '2019-10-09'
SELECT ${date}::DATE, ${date}::TIMESTAMP WITHOUT TIME ZONE
Run Code Online (Sandbox Code Playgroud)
它产生:
| date | timestamp |
|------------|---------------------|
| 2019-10-09 | 2019-10-09 00:00:00 |
Run Code Online (Sandbox Code Playgroud)
是的,您可以,使用:.
一个例子:
SELECT * FROM "SYSIBM".SYSDUMMY1
WHERE IBMREQD = :YOUR_VARIABLE
Run Code Online (Sandbox Code Playgroud)
在 DBeaver SQL 编辑器中,您可以键入以下内容:
-- define variable
@set my_var='hello SQL world'
-- call variable
select :my_var
Run Code Online (Sandbox Code Playgroud)
您还可以使用${my_var}引用变量;$my_var但对我不起作用。我正在使用 DBeaver v.21.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}
;
Run Code Online (Sandbox Code Playgroud)
这将返回值“2120-01-01”,字段名为“date_start”。