BEGIN/ENDE und erstellt eine Tabelle in der einzelne .sql-Datei

Habe ich ein kleines SQL-Skript, dass ich die Ausführung mit der Oracle SQL*Plus zu emulieren, erstellen oder ersetzen in Tabellen:

BEGIN
    EXECUTE IMMEDIATE 'DROP TABLE symbols';
EXCEPTION
    WHEN OTHERS THEN
        IF SQLCODE != -942 THEN
    END IF;
END;
/
CREATE TABLE symbols ( 
            blah blah,
            blah blah,
        );
EXIT;

SQL*Plus commandline ist:

sqlplus aegsys15_owner/pass#234@MARVINUAT03 @createSymbolsTable.sql << EOF
> EOF

Wenn ich das weglassen der Schrägstrich (/) nach dem ENDE, es scheint nur die ersten BEGIN/END-block und ignoriert die CREATE TABLE-Abschnitt darunter. Auch, es muss nicht alles drucken helfen in allen - nur verbinden/trennen:

SQL*Plus: Release 11.2.0.1.0 Production on Tue Sep 13 15:49:34 2011

Copyright (c) 1982, 2009, Oracle.  All rights reserved.

Connected to:
Oracle Database 11g Enterprise Edition Release 11.1.0.7.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options

 78  Disconnected from Oracle Database 11g Enterprise Edition Release 11.1.0.7.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options

Jedoch, wenn ich die Schrägstrich-es gibt mir eine Fehlermeldung:

    END IF;
    *
ERROR at line 6:
ORA-06550: line 6, column 5:
PLS-00103: Encountered the symbol "END" when expecting one of the following:
( begin case declare exit for goto if loop mod null pragma
raise return select update while with <an identifier>
<a double-quoted delimited-identifier> <a bind variable> <<
continue close current delete fetch lock insert open rollback
savepoint set sql execute commit forall merge pipe purge

CREATE TABLE symbols (
             *
ERROR at line 1:
ORA-00955: name is already used by an existing object

Erstens, was ist der beste Weg, dass sowohl der BEGIN/END exception-block an der Spitze, und der CREATE TABLE-block in der gleichen .sql-Datei?

Und zweitens, was einige Weg, um einige hilfreiche Ausgabe von SQL*Plus? Jeder .sql-Datei, die wir ausführen, kann mehrere CREATE-Anweisungen (Tabellen, Indizes, Synonyme etc..). Unsere ideale Ausgabe wäre etwas wie:

TABLE foo: Pass
SYNONYM bar: Fail
INDEX foo_1: Pass

Nicht sicher, ob sowas machbar ist mit SQL oder PL/SQL-aber - gerne schreiben Sie ein Bash-oder Python-wrapper-Skript, um dieses, wenn Sie Jungs denken, dass ist eine bessere Lösung.

Cheers,
Victor

Sie können beide ausgeführt werden BEGIN/ENDE und erstellt eine Tabelle in einer sql-Datei, aber Sie haben zu tun minor-edition in Ihren cade

InformationsquelleAutor victorhooi | 2011-09-13

Schreibe einen Kommentar