0% found this document useful (0 votes)
49 views2 pages

Oracle Vs SQL Server Issues

Oracle and SQL Server handle NULL and empty strings differently. Oracle treats both empty strings and NULL as NULL, while SQL Server treats empty strings as empty strings and NULL as NULL. SQL Server uses @@ROWCOUNT to handle exceptions like NO_DATA_FOUND and TOO_MANY_ROWS instead of Oracle's predefined exceptions. Developers need to be aware of these differences when migrating code from Oracle to SQL Server.

Uploaded by

FrancesHsieh
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
Download as pdf or txt
0% found this document useful (0 votes)
49 views2 pages

Oracle Vs SQL Server Issues

Oracle and SQL Server handle NULL and empty strings differently. Oracle treats both empty strings and NULL as NULL, while SQL Server treats empty strings as empty strings and NULL as NULL. SQL Server uses @@ROWCOUNT to handle exceptions like NO_DATA_FOUND and TOO_MANY_ROWS instead of Oracle's predefined exceptions. Developers need to be aware of these differences when migrating code from Oracle to SQL Server.

Uploaded by

FrancesHsieh
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
Download as pdf or txt
Download as pdf or txt
You are on page 1/ 2

Oracle vs.

SQL Server

Oracle uses predefined names to trap predefined Oracle Server errors when exceptions are raised in PL/SQL. For example, PL/SQL raises the predefined
exception NO_DATA_FOUND if a SELECT INTO statement returns no rows, and TOO_MANY_ROWS if a SELECT INTO statement returns more than one rows.
For these two situations, SQL Server needs to use @@ROWCOUNT that returns the number of rows affected by the last statement in Transact-SQL to handle these
exceptions.
Please make sure these Oracle exceptions are handled correctly in SQL Server. 
Common Errors Oracle SQL Server
When Querying Data from Tables
NO_DATA_FOUND WHEN NO_DATA_FOUND THEN IF @@ROWCOUNT = 0
statement1; BEGIN
statement1;
END;
TOO_MANY_ROWS WHEN TOO_MANY_ROWS THEN IF @@ROWCOUNT > 1
Statement2; BEGIN
Statement2;
END;

Oracle treats both ‘’ (empty string) and Null as null while SQL Server treats ‘’ as an empty string and Null as null when SET ANSI_NULLS ON.
Please make sure these two values are handled correctly in SQL Server.
Common issues Oracle SQL Server
‘’ DECLARE DECLARE
v_Test VARCHAR2(10); @v_Test VARCHAR(10);
BEGIN BEGIN
v_Test := ''; SET @v_Test = '';
IF v_Test IS NULL THEN IF @v_Test IS NULL
dbms_output.put_line('NULL'); BEGIN
ELSE PRINT 'NULL'
dbms_output.put_line('Empty String'); END
END IF; ELSE
END; BEGIN
PRINT 'Empty String'
Result: NULL END;
END;

Result: Empty String


NULL DECLARE DECLARE
v_Test VARCHAR2(10); @v_Test VARCHAR(10);
BEGIN BEGIN
v_Test := NULL; SET @v_Test = NULL;
IF v_Test IS NULL THEN IF @v_Test IS NULL
dbms_output.put_line('NULL'); BEGIN
ELSE PRINT 'NULL'
dbms_output.put_line('Empty String'); END
END IF; ELSE
END; BEGIN
PRINT 'Empty String'
Result: NULL END;
END;

Result: NULL
 
NULL Empty String ‘’
No datatype Could belong to char/varchar/nvarchar/nchar etc ...datatype
Occupy 1 bit per column for each row to state it's NULL Occupy 0 bytes
 
Experiment
CREATE TABLE [dbo].[ABC](

[AAA] [nchar](10) NULL,

[BBB] [nchar](10) NULL

) ON [PRIMARY]

GO

INSERT INTO dbo.ABC (AAA,BBB) VALUES ('','123');

INSERT INTO dbo.ABC (AAA,BBB) VALUES (NULL,'789');

GO

SELECT [AAA],[BBB]

,COALESCE(AAA, BBB) AS 'COALESCE',ISNULL(AAA, BBB) AS 'ISNULL'

,COALESCE(NULLIF(AAA,''),BBB) AS 'COALESCE & NULLIF',COALESCE(NULLIF(LEN(AAA),0),BBB) AS 'COALESCE & NULLIF & LEN'

FROM [MyDB].[dbo].[ABC];

GO

You might also like