2016-07-28 72 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

不错的。谢谢!但仍然 - 为什么有一个错误? –