SQL 如何在oracle的过程中创建一个表?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/21232941/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-01 00:48:47  来源:igfitidea点击:

how to create a table inside of a procedure in oracle?

sqloraclestored-procedurescreate-table

提问by jalal rasooly

i want to create a table inside of a procedure. i tried to put the create query in a string then execute immediate the string. for example:

我想在一个过程中创建一个表。我试图将创建查询放在一个字符串中,然后立即执行该字符串。例如:

create or replace procedure hr.temp is
   var1 varchar2(4000);
begin
   var1:='create table hr.temp(
          id number)';
   execute immediate var1;
end temp;

but when i execute this procedure i get error of:

但是当我执行这个程序时,我得到以下错误:

ORA-00911: invalid character
ORA-06512: at "SYS.TEMP", line 6
.
.
.

is there any way i can do this?

有什么办法可以做到这一点吗?

采纳答案by pahariayogi

Try this. It should work...

尝试这个。它应该工作...

create or replace procedure hr.temp is
   var1 varchar2(4000);
BEGIN
   var1:='create table hr.temp2(
          id number)';
   EXECUTE IMMEDIATE var1;
end temp;

回答by jalal rasooly

the answer of m.r 'a_horse_with_no_name' is right. The first point is I should not create a table in sys schema.

'a_horse_with_no_name' 先生的回答是正确的。第一点是我不应该在 sys 模式中创建表。

The second point is in a dynamic sql I should not use ;character in dynamic sql.

第二点是在动态 sql 中我不应该;在动态 sql 中使用字符。