如何使用获取要复制的 table 的名称和新的 table 的名称以在 Pl/SQL oracle 中创建它的过程来复制 table?
How to copy table using the procedure that gets the table's name to copy and name of the new table to create it in Pl/SQL oracle?
运行以下代码
create or replace procedure copy_table(
from_table in out varchar2,
new_table_name in out varchar2
) is v varchar(4000);
begin
v :='create table new_table_name as select * from from_table';
execute immediate v;
end copy_table;
begin
copy_table(lalala, new_table);
end;
我收到错误消息
begin
copy_table(lalala, new_table);
end;
Error report -
ORA-06550: line 2, column 12:
PLS-00357: Table,View Or Sequence reference 'LALALA' not allowed in this context
ORA-06550: line 2, column 1:
PL/SQL: Statement ignored
我已经有了“啦啦啦”table,如何正确调用程序?
我的程序是否可以处理现有的 table 并创建一个新程序?还是代码有误?
您已将过程参数作为字符串传递,而它们必须作为变量传递。此外,您的过程参数必须是 IN only 而不是 IN OUT。所以你更新的代码将是 -
create or replace procedure copy_table(
from_table in varchar2,
new_table_name in varchar2
) is v varchar(4000);
begin
v :='create table '|| new_table_name ||' as select * from '|| from_table;
execute immediate v;
end copy_table;
运行以下代码
create or replace procedure copy_table(
from_table in out varchar2,
new_table_name in out varchar2
) is v varchar(4000);
begin
v :='create table new_table_name as select * from from_table';
execute immediate v;
end copy_table;
begin
copy_table(lalala, new_table);
end;
我收到错误消息
begin
copy_table(lalala, new_table);
end;
Error report -
ORA-06550: line 2, column 12:
PLS-00357: Table,View Or Sequence reference 'LALALA' not allowed in this context
ORA-06550: line 2, column 1:
PL/SQL: Statement ignored
我已经有了“啦啦啦”table,如何正确调用程序? 我的程序是否可以处理现有的 table 并创建一个新程序?还是代码有误?
您已将过程参数作为字符串传递,而它们必须作为变量传递。此外,您的过程参数必须是 IN only 而不是 IN OUT。所以你更新的代码将是 -
create or replace procedure copy_table(
from_table in varchar2,
new_table_name in varchar2
) is v varchar(4000);
begin
v :='create table '|| new_table_name ||' as select * from '|| from_table;
execute immediate v;
end copy_table;