10.07.2015 Views

Programming Guide - Actian

Programming Guide - Actian

Programming Guide - Actian

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

How You Can Access a Database with Standard SQL StatementsThe syntax of the execute immediate statement is:execute immediate statement_string [into variable {, variable}]statement_stringSpecifies a string constant, a varchar expression, or a StringObjectreference variable value. It must adhere to the following restrictions:• It must evaluate to a single SQL statement.• It cannot contain an open or fetch statement or any of the exceptionsfor the execute immediate statement.Assume, for example, that you want to create a temporary table with a uniquename at runtime. Do the following to create the table:1. Declare two variables, one to contain the table name (tname) and one tocontain the I parameter (vstring):tname = varchar(32);vstring = varchar(500);2. Build the temporary table name from the user's login, followed bynumbers:select :user_name = dbmsinfo('username');tname = user_name + '123';3. Load the create table statement into vstring and run it using the executeimmediate statement:vstring = 'create table ' + tname +'(name varchar(50), addr varchar(100))';execute immediate :vstring;When the program runs the execute immediate statement in Step 3, itexecutes the statement contained in vstring, creating the specified table.For more examples of using the execute immediate statement, see theLanguage Reference <strong>Guide</strong> online help.How You Can Use the Into Clause with a Select StatementYou must use the into clause if the statement_string is a select statement.When the statement is executed, the values retrieved by the select statementare placed in the specified variables. The data types of the variables mustmatch those in the target list of the select statement. The number of columnsselected must also match the number of targets specified.For example, assume that your application contains the following code:statement = 'Select title, vidno from video';156 <strong>Programming</strong> <strong>Guide</strong>

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!