13.07.2015 Views

SAS/ACCESS 9.2 for Relational Databases: Reference, Fourth Edition

SAS/ACCESS 9.2 for Relational Databases: Reference, Fourth Edition

SAS/ACCESS 9.2 for Relational Databases: Reference, Fourth Edition

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

<strong>SAS</strong>/<strong>ACCESS</strong> Interface to DB2 Under UNIX and PC Hosts 4 Terminating a Temporary Table 467Temporary Table Support <strong>for</strong> DB2 Under UNIX and PC HostsEstablishing a Temporary TableFor general in<strong>for</strong>mation about this feature, see “Temporary Table Support <strong>for</strong> <strong>SAS</strong>/<strong>ACCESS</strong>” on page 38.To make full use of temporary tables, the CONNECTION=GLOBAL connectionoption is necessary. You can use this option to establish a single connection across <strong>SAS</strong>DATA step and procedure boundaries that can also be shared between the LIBNAMEstatement and the SQL pass-through facility. Because a temporary table only existswithin a single connection, you must be able to share this single connection among allsteps that reference the temporary table. The temporary table cannot be referencedfrom any other connection.The type of temporary table that is used <strong>for</strong> this processing is created using theDECLARE TEMPORARY TABLE statement with the ON COMMIT PRESERVE clause.This type of temporary table lasts <strong>for</strong> the duration of the connection—unless it isexplicitly dropped—and retains its rows of data beyond commit points.DB2 places all global temporary tables in the SESSION schema. There<strong>for</strong>e, toreference these temporary tables within <strong>SAS</strong>, you must explicitly provide the SESSIONschema in Pass-Through SQL statements or use the SCHEMA= LIBNAME option witha value of SESSION.Currently, the only supported way to create a temporary table is to use a PROC SQLPass-Through statement. To use both the SQL pass-through facility and librefs toreference a temporary table, you need to specify a LIBNAME statement be<strong>for</strong>e thePROC SQL step. This enables the global connection to persist across <strong>SAS</strong> steps, evenmultiple PROC SQL steps, as shown in this example:libname temp db2 database=sample user=myuser password=mypwdschema=SESSION connection=global;proc sql;connect to db2 (db=sample user=myuser pwd=mypwd connection=global);execute (declare global temporary table temptab1 like other.tableon commit PRESERVE rows not logged) by db2;quit;At this point, you can refer to the temporary table by using the libref Temp or byusing the CONNECTION=GLOBAL option with a PROC SQL step.Terminating a Temporary TableYou can drop a temporary table at any time, or allow it to be implicitly dropped whenthe connection is terminated. Temporary tables do not persist beyond the scope of asingle connection.

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

Saved successfully!

Ooh no, something went wrong!