Differences between variables in other RDBMSes

The differences between variables in each of the RDMSes are outlined as follows: 

  • Oracle: In Oracle, there is a different syntax for using variables, as shown in the following query: 
DECLARE
var_parkname varchar2(100);
var_parkkey varchar2(5) := 'ALB01';
BEGIN
SELECT parkname INTO var_parkname FROM parks_copy
WHERE parkkey = var_parkkey;
DBMS_OUTPUT.PUT_LINE(var_parkname);
END;

The query has you declare a variable for parkkey (var_parkkey), as well as for the output of the query with the variable in it, which is named var_parkname. Then, you output var_parkname to get the results. 

  • PostgreSQL: You can't use variables outside of functions. 
  • SQL Server: In SQL Server, you can't use := to set a variable, only =. Also, you need to declare the variable before setting it, as shown in the following code snippet: 
DECLARE @varname varchar(5); 

You can also declare and set the variable in one line, as shown in the following code snippet: 

DECLARE @varname varchar(5) = 'ALB01';

The first DECLARE statement will require you to use a SET statement to set the value, but the second DECLARE statement won't. 

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.188.77.32