我必須在表中插入數據。它有一個柱子,其值應該是負數,如-1,-2,-3 ......等到-50。incerement Oracle插入語句中的值(neagative數字)
我想過使用序列,但它不會接受負值。
我怎麼可以genarate我的意思是插入值?
我必須在表中插入數據。它有一個柱子,其值應該是負數,如-1,-2,-3 ......等到-50。incerement Oracle插入語句中的值(neagative數字)
我想過使用序列,但它不會接受負值。
我怎麼可以genarate我的意思是插入值?
搜索與鉛丹任何表recourd算你喜歡的,然後寫:
使用select生成數據:
select (rownum * -1) as negRowNum from whatevertableyoufound where rownum <= 50
使用0 - rownum
。
SELECT 0 - rownum
FROM DUAL
CONNECT BY LEVEL <= 50;
0-ROWNUM
-1
-2
-3
-4
-5
...
「我想用序列,但它不會接受負值。」
確定嗎?
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,但我認爲這不是最近的功能。