Skip to content

Commit

Permalink
Sample Files Chapter 2
Browse files Browse the repository at this point in the history
  • Loading branch information
TexanInParis committed Jul 13, 2016
1 parent bdf04df commit 75f2932
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 6 deletions.
6 changes: 4 additions & 2 deletions IBM DB2/Chapter 02/Listing 2.029.sql
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ SET SCHEMA SalesOrdersSample;

CREATE FUNCTION CalculateAge(Date_of_Birth DATE)
RETURNS int
RETURN TRUNC((CURRENT_DATE - Date_of_Birth) / 365);
RETURN TRUNC((DAYS(CURRENT_DATE) - DAYS(Date_of_Birth)) / 365, 0);

DROP FUNCTION CalculateAge;
-- Execute the following only if you do not intend
-- to run Listing 2.030.
-- DROP FUNCTION CalculateAge;
3 changes: 2 additions & 1 deletion Microsoft SQL Server/Chapter 02/Listing 2.029.sql
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,6 @@ BEGIN
RETURN DATEDIFF(DAY, @Date_of_Birth, CAST(GETDATE() AS date)) / 365;
END;

-- Run the following if you do not wish to keep the function in the database.
-- Execute the following only if you do not intend
-- to run Listing 2.030.
-- DROP FUNCTION CalculateAge;
3 changes: 2 additions & 1 deletion MySQL/Chapter 02/Listing 2.029.sql
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,6 @@ CREATE FUNCTION CalculateAge(Date_of_Birth date)
RETURNS int
RETURN (DATEDIFF(CURRENT_DATE, Date_of_Birth) / 365);

-- Run the following if you do not wish to keep the function in the database.
-- Execute the following only if you do not intend
-- to run Listing 2.030.
-- DROP FUNCTION CalculateAge;
4 changes: 3 additions & 1 deletion Oracle/Chapter 02/Listing 2.029.sql
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,6 @@ BEGIN
RETURN(TRUNC((SYSDATE - Date_of_Birth) / 365));
END;

DROP FUNCTION CalculateAge;
-- Execute the following only if you do not intend
-- to run Listing 2.030.
-- DROP FUNCTION CalculateAge;
4 changes: 3 additions & 1 deletion PostgreSQL/Chapter 02/Listing 2.029.sql
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,6 @@ BEGIN
END;
$BODY$;

DROP FUNCTION CalculateAge(Date_of_Birth DATE);
-- Execute the following only if you do not intend
-- to run Listing 2.030.
-- DROP FUNCTION CalculateAge(Date_of_Birth DATE);

0 comments on commit 75f2932

Please sign in to comment.