Next query doesn't see previous, single SQL file - PL/SQL

Viewed 51

I have a problem.

I have following sql statements in one SQL file:

CREATE OR REPLACE TYPE Banda AS OBJECT (
    nr_bandy NUMBER(2)
    , nazwa VARCHAR2(20)
    , teren VARCHAR2(20)

    , MAP MEMBER FUNCTION MapBanda RETURN NUMBER
);

CREATE OR REPLACE TYPE BODY Banda IS
    MAP MEMBER FUNCTION MapBanda RETURN NUMBER IS
    BEGIN
        RETURN nr_bandy;
    END;
END;

When I run those Create-Statements one by one (I mean select first create, ctrl + enter, then second one and ctrl + enter) I'll create those structures without any problems. But, if I try create them both (I mean Ctrl+A -> Ctrl + Enter) second one query seems to be aware of knowing about type 'Banda'.

I'm getting:

Type BANDA compiled

LINE/COL  ERROR
--------- -------------------------------------------------------------
8/1       PLS-00103: Encountered the symbol "CREATE" 
Errors: check compiler log

Is there any possibility to "commit" every single statement? Actually I have about 10-12 types created this way, so it's really annoying. I'm using Oracle SQL Developer.

2 Answers

try it with /

CREATE OR REPLACE TYPE Banda AS OBJECT (
    nr_bandy NUMBER(2)
    , nazwa VARCHAR2(20)
    , teren VARCHAR2(20)

    , MAP MEMBER FUNCTION MapBanda RETURN NUMBER
);
/

CREATE OR REPLACE TYPE BODY Banda IS
    MAP MEMBER FUNCTION MapBanda RETURN NUMBER IS
    BEGIN
        RETURN nr_bandy;
    END;
END;
/

@Simonare is 100% correct.

Your other option is to highlight the text for the TYPE and hit ctrl+enter and then select the text for the type body and hit ctrl+enter again.

If you're saving your code to file(s) to be stored in a source control system (PLEASE SAY YOU ARE DOING THIS), then you'll want to be mindful of how this code will get executed later. Will it be used in SQL*Plus? SQL Developer? Something else? Then write the code for THAT...which of course means you'll want to test for it as well.

Related