5
votes

I have SQL script:

CREATE TABLE TESTTABLE1(
   ID_TESTTABLE1          NUMBER (18) NOT NULL,
   TESTTABLE_VALUE1       NUMBER (18),
   TESTTABLE_KEY1       NUMBER (18))

and use Fluentmigrator:

[Migration(201302021800)]
public class Migration_201302021800 : AutoReversingMigration
{
    public override void Up()
    {
        var url = @"Update_1.0.0.5.sql";
        Execute.Script(url);
    }
}

It executes successfully, and if I add some SQL:

CREATE TABLE TESTTABLE1
(
  ID_TESTTABLE1          NUMBER (18) NOT NULL,
  TESTTABLE_VALUE1       NUMBER (18),
  TESTTABLE_KEY1       NUMBER (18)
);
CREATE TABLE TESTTABLE
(
  ID_TESTTABLE          NUMBER (18) NOT NULL,
  TESTTABLE_VALUE      NUMBER (18),
  TESTTABLE_KEY      NUMBER (18)
);

execute in Fluentmigrator fails, with Oracle exeption {"ORA-00911: invalid character"}.

My database is Oracle db.

What's the problem?

2
Have you tried to run the extended SQL outside the fluent-migrator? It will help you to distinguish if the problem is in fluent-migratior or in pure SQL. - mipe34
yes of course. it executes successfully in oracle. But I think the problem is that need to perform a single sql command (if it executes from c#),not all at once. but I think that is what some solution that run all at once. - AndreyMaybe
Since I suppose you have checked the potential source of the error (techonthenet.com/oracle/errors/ora00911.php). I would suggest to split the SQL into two files. It often help me to pass through fluent migrator. - mipe34
yes it ok, but in really sql script i have more than 10 commands, so if i split it from files, i will have 10 files, maybe it not good way - AndreyMaybe
maybe ideia in that parse him, and run in foreach. but it not stable case. do you think that impossible run the entire sql script ? - AndreyMaybe

2 Answers

5
votes

To batch statements together for Oracle you need to have it enclosed in a BEGIN...END block. In your last example that you linked to in the comments you are missing a semicolon right after the second statement and before the END keyword.

BEGIN 
CREATE TABLE TESTTABLE1 
    ( 
      ID_TESTTABLE1          NUMBER (18) NOT NULL, 
      TESTTABLE_VALUE1       NUMBER (18), 
      TESTTABLE_KEY1       NUMBER (18) 
    ); 
CREATE TABLE TESTTABLE 
    ( 
      ID_TESTTABLE          NUMBER (18) NOT NULL, 
      TESTTABLE_VALUE      NUMBER (18), 
      TESTTABLE_KEY      NUMBER (18) 
    );
END;

Although FluentMigrator could provide better support in this case. For example, when FluentMigrator processes multi-statement scripts from Sql Server then it splits up the script and executes each statement (https://github.com/schambers/fluentmigrator/blob/master/src/FluentMigrator.Runner/Processors/SqlServer/SqlServerProcessor.cs#L197-236). So I would recommend logging an issue at https://github.com/schambers/fluentmigrator/issues

1
votes

Now i use not only BEGIN and END statement, so also EXECUTE IMMEDIATE for CREATE ALTER and DROP. For INSERT i use only BEGIN and END.

BEGIN 
EXECUTE IMMEDIATE'CREATE TABLE TESTTABLE1 
( 
  ID_TESTTABLE1          NUMBER (18) NOT NULL, 
  TESTTABLE_VALUE1       NUMBER (18), 
  TESTTABLE_KEY1       NUMBER (18) 
)'; 
EXECUTE IMMEDIATE 'CREATE TABLE TESTTABLE 
( 
  ID_TESTTABLE          NUMBER (18) NOT NULL, 
  TESTTABLE_VALUE      NUMBER (18), 
  TESTTABLE_KEY      NUMBER (18) 
)';
END;