PreviousSQL Engine Reference (v9 SP2 (9.5) revision 1) Next

SELECT (with into)

Chapter contents

The SELECT (with INTO) statement allows you to select column values from a specified table to insert into variables or to populate a temporary table with data.

Syntax

SELECT [ ALL | DISTINCT ] select-list INTO variable-or-temp-table-name 
[ , variable-or-temp-table-name ]... 
  FROM table-reference [ , table-reference ]... [ WHERE search-condition ] 
  [ GROUP BY expression [ , expression ]...[ HAVING search-condition ] ] 

Remarks

The variables must occur within a stored procedure, a trigger, or a user-defined function.

You can populate a temporary table by using SELECT INTO only if the SELECT INTO statement occurs outside of a stored procedure, user-defined function, or trigger. Populating, or creating, a temporary table with SELECT INTO is not permitted within a stored procedure, user-defined function, or trigger.

Examples

See the examples for CREATE (temporary) TABLE for how to use SELECT INTO to populate temporary tables. A temporary table can be created and populated with a single SELECT INTO statement.

The following example assigns into variables :x, :y the values of first_name and last_name in the Person table where first name is Bill.

SELECT first_name, last_name INTO :x, :y from person 
where first_name = 'Bill' 

See Also

CREATE FUNCTION

CREATE PROCEDURE

CREATE (temporary) TABLE


Chapter contents
Book contents

Prev topic: SAVEPOINT
Next topic: SELECT