将CONNECTEL从ORACLE迁移到POSTGRES

时间:2018-02-23 06:55:43

标签: sql postgresql

我需要将从CONNECT BY LEVEL从Oracle迁移到Postgres的输入。

Oracle的源代码:

SELECT LEVEL,AST_TXRBATCHID_SEQ.NEXTVAL  AS BATCH
from DUAL
CONNECT BY LEVEL <= '2';

2 个答案:

答案 0 :(得分:1)

使用generate_seriesNEXTVAL()功能。

SQL Fiddle

PostgreSQL 9.6架构设置

create sequence AST_TXRBATCHID_SEQ start with 1 increment by 1;

查询1

SELECT id,NEXTVAL('AST_TXRBATCHID_SEQ') AS BATCH
from generate_series(1,2) as id

<强> Results

| id | batch |
|----|-------|
|  1 |     2 |
|  2 |     3 |

答案 1 :(得分:0)

一个简单的解决方案是:

SELECT 1 AS level, nextval('ast_txrbatchid_seq') AS batch
UNION
SELECT 2, nextval('ast_txrbatchid_seq');