Dynamic SQL Format 1

Description

Use this format to execute a SQL statement that does not produce a result set and does not require input parameters. You can use this format to execute all forms of Data Definition Language (DDL).

Syntax

EXECUTE IMMEDIATE SQLStatement 
	{USING TransactionObject} ;

Parameter

Description

SQLStatement

A string containing a valid SQL statement. The string can be a string constant or a PowerBuilder variable preceded by a colon (such as :mysql). The string must be contained on one line and cannot contain expressions.

TransactionObject (optional)

The name of the transaction object that identifies the database.

Examples

Example 1

These statements create a database table named Trainees. The statements use the string Mysql to store the CREATE statement.

NoteFor Sybase ASE users If you are connected to an ASE database, set AUTOCOMMIT to true before executing the CREATE.

string MyASE

MyASE = "CREATE TABLE Trainees "&

		+"(emp_id integer not null,"&

		+"emp_fname char(10) not null, "&

		+"emp_lname char(20) not null)"

EXECUTE IMMEDIATE :MyASE ;

Example 2

These statements assume a transaction object named My_trans exists and is connected:

string MyASE

MyASE="INSERT INTO department Values (1234,"& 

       +"'Purchasing',1234)" 

EXECUTE IMMEDIATE :MyASE USING My_trans ;