什么是 Teradata 相当于 Oracle 的 DUAL [英] What is Teradata's equivalent for Oracle's DUAL

查看:58
本文介绍了什么是 Teradata 相当于 Oracle 的 DUAL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在 Oracle 中,我们可以使用 SELECT 语句编写此代码以生成单行.

In Oracle, we can write this to generate a single row using a SELECT statement.

SELECT 1 AS x FROM dual

Teradata 的等价物是什么?

What is Teradata's equivalent?

推荐答案

一般不需要这样的表

在大多数情况下,Teradata 数据库中并不真正需要表.以下是有效的 SQL(就像在 H2、PostgreSQL、Redshift、SQL Server、SQLite、Sybase ASE、Sybase SQL Anywhere、Vertica 中一样)

Generally, no such table is needed

In most cases, no table is really needed in the Teradata database. The following is valid SQL (just like in H2, PostgreSQL, Redshift, SQL Server, SQLite, Sybase ASE, Sybase SQL Anywhere, Vertica)

SELECT 1
SELECT 1 WHERE 1 = 1

例外

但是,有一个例外,当需要设置操作时.例如.这在 Teradata 中无效:

Exceptions

However, there is an exception, when a set operation is desireable. E.g. this is invalid in Teradata:

SELECT 1 UNION ALL SELECT 2

产生这个错误:

对 UNION、INTERSECT 或 MINUS 的 SELECT 必须引用一个表.

A SELECT for a UNION,INTERSECT or MINUS must reference a table.

但是由于 FROM 子句通常是可选的,所以很容易模拟一个 DUAL 表,如下所示:

But since the FROM clause is generally optional, it's very easy to emulate a DUAL table as follows:

SELECT 1 FROM (SELECT 1 AS "DUMMY") AS "DUAL"
UNION ALL 
SELECT 2 FROM (SELECT 1 AS "DUMMY") AS "DUAL"

兼容性

如果需要与 Oracle 等实现兼容性,可以轻松创建行为类似于 Oracle 的双视图:

Compatibility

In case compatibility needs to be achieved with Oracle etc, it is easy to create a view that behaves like Oracle's dual:

CREATE VIEW "DUAL" AS (SELECT 1 AS "DUMMY");

注意DUAL是Teradata中的关键字,因此视图需要引用.

Notice that DUAL is a keyword in Teradata, thus the view needs to be quoted.

这篇关于什么是 Teradata 相当于 Oracle 的 DUAL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆