2011-07-12 18 views

回答

0

搜索與鉛丹任何表recourd算你喜歡的,然後寫:

使用select生成數據:

select (rownum * -1) as negRowNum from whatevertableyoufound where rownum <= 50 
0

使用0 - rownum

SELECT 0 - rownum 
FROM DUAL 
CONNECT BY LEVEL <= 50; 

0-ROWNUM 
-1 
-2 
-3 
-4 
-5 
... 
3

「我想用序列,但它不會接受負值。」

確定嗎?

SQL> create table t1 (c1 number) 
    2/

Table created. 

SQL> create sequence myseq increment by -1 
    2/

Sequence created. 

SQL> insert into t1 values (myseq.nextval) 
    2/

1 row created. 

SQL> r 
    1* insert into t1 values (myseq.nextval) 

1 row created. 

SQL> r 
    1* insert into t1 values (myseq.nextval) 

1 row created. 

SQL> select * from t1 
    2/

     C1 
---------- 
     -1 
     -2 
     -3 

SQL> 

您使用的是哪個版本的數據庫?這來自Oracle 11g R1,但我認爲這不是最近的功能。