0

I need to write a PL/SQL procedure to create tables that match the ones in another account(I have access to that account). They need to have same columns and types. Also, they need to be filled with the same data

Help me!

EDIT:

SQL> CREATE OR REPLACE PROCEDURE MakeTables
  2  AS
  3  BEGIN
  4  EXECUTE IMMEDIATE
  5  'CREATE TABLE Table1 AS (SELECT * FROM ANOTHER_ACCT.Table1);
  6  CREATE TABLE Table2 AS (SELECT * FROM ANOTHER_ACCT.Table2);
  7  CREATE TABLE Table3 AS (SELECT * FROM ANOTHER_ACCT.Table3);
  8  CREATE TABLE Table4 AS (SELECT * FROM ANOTHER_ACCT.Table4)';
  9  END;
 10  /

Procedure created.

But when I run this I get this error:

SQL> BEGIN
  2  MakeTables;
  3  END;
  4  /
BEGIN
*
ERROR at line 1:
ORA-00911: invalid character
ORA-06512: at "BS135.MAKETABLES", line 4
ORA-06512: at line 2
4

1 に答える 1

1

別の「アカウント」とは、別の「ユーザー/スキーマ」のことですか? もしそうなら、これは簡単かもしれません。「oracle create table as select」について読む/グーグルに行きます。これにより、select ステートメントからテーブルを作成できるため、次のようなステートメントを発行できます。

create table new_table as select * from other_schema.old_table

多くのテーブルを作成するプロセスを自動化する場合を除き、PL/SQL は必要ありません。次に、データ ディクショナリをドライバーとしてクエリできます。

(また、ここで適切な質問をする方法をお読みください: https://stackoverflow.com/questions/how-to-ask )

于 2013-04-09T00:06:48.813 に答える