Assigning values to variables in PL/SQL and Transact-SQL is similar.
| Oracle | SQL Server | 
|---|---|
| variable_name := value | SET @variable_name = value | 
| SELECT expression[, ...n] INTO variable_name[, ...n] FROM... | SELECT {@variable_name = expression}[, ...n] FROM... | 
| FETCH cursor_name INTO variable_name[, ...n] | FETCH [fetch option] FROM cursor_name INTO variable_name[, ...n] | 
As in PL/SQL, the SELECT statement in Transact-SQL can be used to assign literal values, functions, or column values from a single row.
In PL/SQL, the FETCH...INTO statement always returns the next row in the cursor. In Transact-SQL, you can move back and forth through the cursor, or jump to a particular position in the cursor by including a fetch option. The default is FETCH NEXT, which works like the PL/SQL FETCH statement.
Microsoft® SQL Server™ does not offer a constant declaration, and you cannot assign variables in the DECLARE statement.
| FETCH | SELECT @local_variable | 
| SET @local_variable | Transact-SQL Variables |