2016-07-28 54 views
1

我想隨機生成數據插入到表中,這裏的代碼」甲骨文,執行直接插入

​​

emp有3列 - idnameidmgr;

上面的查詢在執行立即聲明看起來像:

insert into emp values (13,'name25',193); 

該塊沒有運行當我試圖運行單個執行immediat e聲明(f.e.

begin 
    Execute immediate 'insert into emp values ('||prac_seq.nextval||','''||'name23'','||trunc(dbms_random.value(1,300))||');' 
end; 
    /

ORA給我一個錯誤:

Execute immediate 'insert into emp values ('||prac_seq.nextval||','''||'name23'','||trunc(dbms_random.value(1,300))||');'; end; Error report: ORA-00911: invalid character ORA-06512: at line 3 00911. 00000 - "invalid character" *Cause: identifiers may not start with any ASCII character other than letters and numbers. $#_ are also allowed after the first character. Identifiers enclosed by doublequotes may contain any character other than a doublequote. Alternative quotes (q'#...#') cannot use spaces, tabs, or carriage returns as delimiters. For all other contexts, consult the SQL Language Reference Manual. *Action:

爲什麼呢?逗號,引號..一切都檢查和罰款。

+1

在這種情況下,不需要使用本地動態SQL('立即執行') - 使用靜態SQL。 –

+0

在立即使用JUSt 2000插入語句之前。這需要很多時間。動態SQL - 7.54秒!所以是的 - 有需要。 –

回答

1

嘗試從您的動態查詢中刪除;

+0

愚蠢......我非常專注於這個逗號,我錯過了它。謝謝!! –

3

爲什麼你使用立即執行此操作。嘗試按級別連接。

select prac_seq.nextval, 'name'||level, trunc(dbms_random.value(1,300)) as rnd 
from dual 
connect by level <= 300; 
+1

不錯的。謝謝!但仍然 - 爲什麼有一個錯誤? –