1

我需要在我的 SQL 语句中输出 3 个空列,我使用的是 SQL 开发人员 Oracle 11g 例如:

SELECT
  c.CID, 
  c.CName,
  null, 
  null, 
  null, 
  r.RegionID, 
  r.RegionName
FROM
  Regions r 
  INNER JOIN Branch b ON b.RegionID = r.RegionID
  INNER JOIN Countries c ON c.CID = b.CID;

所以在 SQL Developer 上的脚本输出/查询结果窗口中显示

  CID| CName | Null |   Null  | Null | RegionID  | RegionName
  ------------------------------
  C1 | ENG   | Null  | Null   | Null | R1        | UK   
  C2 | ...   | Null  | Null   | Null | R2        | ...
  C3 | ...   | Null  | Null   | Null | R3        | ...

理想的情况是,如果我可以做类似的事情:

Select
Country,
Region, 
Null as Continent,
Null as hemisphere

etc

我知道这可能听起来很疯狂,但这只是为了格式化,直到数据库更新。

编辑:谢谢你,没有意识到它是如此简单,唯一的问题是我的空列在脚本输出屏幕上很大,即使它是空的,有没有办法让它更合理的大小?

4

3 回答 3

1

好吧,您可以按照您介绍的方式进行操作...:

SELECT
  c.CID, 
  c.CName,
  CAST(null AS VARCHAR2(1)) AS Continent, 
  null AS hemisphere, 
  null AS something, 
  r.RegionID, 
  r.RegionName
FROM
  Regions r 
  INNER JOIN Branch b ON b.RegionID = r.RegionID
  INNER JOIN Countries c ON c.CID = b.CID;
于 2013-11-07T10:22:05.267 回答
0

我认为通过显示空你意味着基本上它应该是空的并显示为空所以你可以使用下面的查询:

Select
Country,
Region, 
''  Continent,
''  hemisphere,
from 
regions r;
于 2013-11-07T10:25:41.057 回答
0

实际上,这应该有效。

SELECT
  c.CID, 
  c.CName,
  null AS country, 
  null AS Region, 
  null AS hemisphere, 
  r.RegionID, 
  r.RegionName
FROM
  Regions r 
  INNER JOIN Branch b ON b.RegionID = r.RegionID
  INNER JOIN Countries c ON c.CID = b.CID;
-- Or, if you don't have any tables yet:
SELECT
  NULL AS CID, 
  NULL AS CName,
  NULL AS country, 
  NULL AS Region, 
  NULL AS hemisphere, 
  NULL AS RegionID, 
  NULL AS RegionName
FROM dual;
于 2013-11-07T10:24:24.467 回答