Question

All,

I want to execute a DDL(Data Definition Language) from C code.

What are the alternatives to do this?

Was it helpful?

Solution

One option is to use dynamic ESQL with PRO*C:

EXEC SQL EXECUTE IMMEDIATE
     "CREATE TABLE dyn1 (col1 VARCHAR2(4))";

Another option is to use system to run SQL*Plus. On a Linux type system it could look something like this:

<write sql command(s) to sql file>
system("cat mycommands.sql | sqlplus dbuser/password@myDatabase");

or this:

system("echo 'drop table myTable' | sqlplus dbuser/password@myDatabase");

If you are already using PRO*C I would recommend the PRO*C approach, because it gives much better control over error handling.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top