2

在为简单的 insert..select stmnt 编写以下代码后,我收到了错误。我很困惑,因为语法似乎没有错。


INSERT INTO dimension_tab(FACT_1_ID,FACT_2_ID,FACT_3_ID,FACT_4_ID,SALES_VALUE)
SELECT TRUNC(DBMS_RANDOM.value(low => 1, high => 3)) AS fact_1_id,
       TRUNC(DBMS_RANDOM.value(low => 1, high => 6)) AS fact_2_id,
       TRUNC(DBMS_RANDOM.value(low => 1, high => 11)) AS fact_3_id,
       TRUNC(DBMS_RANDOM.value(low => 1, high => 11)) AS fact_4_id,
       ROUND(DBMS_RANDOM.value(low => 1, high => 100), 2) AS sales_value
FROM   dual
CONNECT BY level <= 1000;
COMMIT;

4

2 回答 2

0

您使用的是有效语法,但由于您使用的是 oracle 10g,它不支持=>,因此您必须替换(low => 1, high => 3)(1, 3).

像这样试试

INSERT INTO dimension_tab
SELECT TRUNC(DBMS_RANDOM.value( 1,  3)) AS fact_1_id,
       TRUNC(DBMS_RANDOM.value( 1,  6)) AS fact_2_id,
       TRUNC(DBMS_RANDOM.value( 1,  11)) AS fact_3_id,
       TRUNC(DBMS_RANDOM.value( 1,  11)) AS fact_4_id,
       ROUND(DBMS_RANDOM.value( 1,  100), 2) AS sales_value
FROM   dual
CONNECT BY LEVEL <= 1000;
于 2013-11-08T06:36:15.517 回答
0

DBMS_RANDOM.VALUE 的语法是

DBMS_RANDOM.VALUE(
  low  IN  NUMBER,
  high IN  NUMBER
)

所以你可以像这样使用......

INSERT INTO dimension_tab (FACT_1_ID,FACT_2_ID,FACT_3_ID,FACT_4_ID,SALES_VALUE)
SELECT TRUNC(DBMS_RANDOM.value( 1,  3)) AS fact_1_id,
       TRUNC(DBMS_RANDOM.value( 1,  6)) AS fact_2_id,
       TRUNC(DBMS_RANDOM.value( 1,  11)) AS fact_3_id,
       TRUNC(DBMS_RANDOM.value( 1,  11)) AS fact_4_id,
       ROUND(DBMS_RANDOM.value( 1,  100), 2) AS sales_value
FROM   dual
CONNECT BY LEVEL <= 1000;
COMMIT;
于 2013-11-08T06:38:20.340 回答