-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathtest.sql
105 lines (89 loc) · 4.44 KB
/
test.sql
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
-- MICROSECOND()
SELECT MICROSECOND('0001-01-01 00:00:00.100000') FROM SYSIBM.SYSDUMMY1;
SELECT MICROSECOND('0001-01-01 12:35:30.100001') FROM SYSIBM.SYSDUMMY1;
-- SECOND()
SELECT SECOND('0001-01-01 12:35:30.100001') FROM SYSIBM.SYSDUMMY1;
-- MINUTE()
SELECT MINUTE('0001-01-01 12:35:30.100001') FROM SYSIBM.SYSDUMMY1;
SELECT MINUTE('0001-01-01 12:35:30.100001+02:00') FROM SYSIBM.SYSDUMMY1;
-- HOUR()
SELECT HOUR('0001-01-01 12:35:30.100001') FROM SYSIBM.SYSDUMMY1;
SELECT HOUR('0001-01-01 12:35:30.100001+02:00') FROM SYSIBM.SYSDUMMY1; -- WRONG
-- DAY()
SELECT DAY('0001-01-01 12:35:30.100001') FROM SYSIBM.SYSDUMMY1;
SELECT DAY('1000-01-01') FROM SYSIBM.SYSDUMMY1;
SELECT DAY('0004-02-29') FROM SYSIBM.SYSDUMMY1;
-- YEAR()
SELECT YEAR('0001-01-01') FROM SYSIBM.SYSDUMMY1;
SELECT YEAR(CURRENT_TIMESTAMP) FROM SYSIBM.SYSDUMMY1;
-- DAYS()
SELECT DAYS('1000-01-01') FROM SYSIBM.SYSDUMMY1;
SELECT DAYS('0000-01-01') FROM SYSIBM.SYSDUMMY1; -- ERROR
SELECT DAYS('0001-01-01') FROM SYSIBM.SYSDUMMY1;
-- MONTHS_BETWEEN()
SELECT MONTHS_BETWEEN('0002-01-01', '0001-01-01') FROM SYSIBM.SYSDUMMY1;
SELECT MONTHS_BETWEEN('0002-01-01', '0001-01-02') FROM SYSIBM.SYSDUMMY1;
SELECT MONTHS_BETWEEN('0002-01-01', '0001-01-03') FROM SYSIBM.SYSDUMMY1;
SELECT MONTHS_BETWEEN('0003-01-01', '0001-01-02') FROM SYSIBM.SYSDUMMY1;
SELECT MONTHS_BETWEEN('2008-01-17', '2008-02-17') FROM SYSIBM.SYSDUMMY1;
SELECT MONTHS_BETWEEN('2008-02-17', '2008-03-17') FROM SYSIBM.SYSDUMMY1;
SELECT MONTHS_BETWEEN('2008-02-20', '2008-01-17') FROM SYSIBM.SYSDUMMY1;
SELECT MONTHS_BETWEEN('2008-01-17', '2008-02-20') FROM SYSIBM.SYSDUMMY1;
SELECT MONTHS_BETWEEN('2008-02-20', '2008-01-20') FROM SYSIBM.SYSDUMMY1;
SELECT MONTHS_BETWEEN('2014-07-09', '2014-06-10') FROM SYSIBM.SYSDUMMY1;
SELECT MONTHS_BETWEEN('2014-07-09 14:00:00.000000', '2014-06-10') FROM SYSIBM.SYSDUMMY1;
SELECT MONTHS_BETWEEN('2014-07-09 14:30:00.000000', '2014-06-10') FROM SYSIBM.SYSDUMMY1;
SELECT MONTHS_BETWEEN('2014-07-09 14:30:30.000000', '2014-06-10') FROM SYSIBM.SYSDUMMY1;
SELECT MONTHS_BETWEEN('2014-07-09 14:30:30.000000+06:00', '2014-06-10') FROM SYSIBM.SYSDUMMY1;
SELECT ROUND(MONTHS_BETWEEN('2008-03-29', '2008-02-29')*31,2) FROM SYSIBM.SYSDUMMY1;
SELECT ROUND(MONTHS_BETWEEN('2008-03-30', '2008-02-29')*31,2) FROM SYSIBM.SYSDUMMY1;
SELECT ROUND(MONTHS_BETWEEN('2008-03-31', '2008-02-29')*31,2) FROM SYSIBM.SYSDUMMY1; -- WRONG ("The result
-- is not 33 because both dates are the last day of their respective month, and so the result is only based
-- on the year and month portions.")
-- LOCATE()
SELECT LOCATE('N', 'DINING') FROM SYSIBM.SYSDUMMY1;
-- TRANSLATE()
SELECT TRANSLATE('12345', 'ax', '143') FROM SYSIBM.SYSDUMMY1;
SELECT TRANSLATE('Hanauma Bay') FROM SYSIBM.SYSDUMMY1;
SELECT TRANSLATE('Hanauma Bay', 'j', 'B' ) FROM SYSIBM.SYSDUMMY1;
SELECT TRANSLATE('Hanauma Bay', 'ei', 'aa') FROM SYSIBM.SYSDUMMY1;
SELECT TRANSLATE('Hanauma Bay', 'r', 'Bu') FROM SYSIBM.SYSDUMMY1;
-- INTEGER()/INT()
SELECT INTEGER(1.00) FROM SYSIBM.SYSDUMMY1;
SELECT INTEGER(1.50) FROM SYSIBM.SYSDUMMY1;
SELECT INTEGER(1.99) FROM SYSIBM.SYSDUMMY1;
SELECT INTEGER(2.00) FROM SYSIBM.SYSDUMMY1;
SELECT INTEGER(1.99e0) FROM SYSIBM.SYSDUMMY1;
SELECT INTEGER(2.00e0) FROM SYSIBM.SYSDUMMY1;
SELECT INTEGER(2.00) FROM SYSIBM.SYSDUMMY1;
SELECT INTEGER(1) FROM SYSIBM.SYSDUMMY1;
SELECT DOUBLE(1.00) FROM SYSIBM.SYSDUMMY1;
SELECT CHAR(1.00) FROM SYSIBM.SYSDUMMY1;
-- HEX()
SELECT HEX('000020') FROM SYSIBM.SYSDUMMY1;
SELECT HEX(000020) FROM SYSIBM.SYSDUMMY1; -- WRONG
-- ROUND()
SELECT ROUND(873.726, 2) FROM SYSIBM.SYSDUMMY1;
SELECT ROUND(873.726, 1) FROM SYSIBM.SYSDUMMY1;
SELECT ROUND(873.726, 0) FROM SYSIBM.SYSDUMMY1;
SELECT ROUND(873.726, -1) FROM SYSIBM.SYSDUMMY1;
SELECT ROUND(873.726, -2) FROM SYSIBM.SYSDUMMY1;
SELECT ROUND(873.726, -3) FROM SYSIBM.SYSDUMMY1;
SELECT ROUND(873.726, -4) FROM SYSIBM.SYSDUMMY1;
-- VALUE()
SELECT VALUE(1) FROM SYSIBM.SYSDUMMY1; -- DB2 ERROR
SELECT VALUE(NULL) FROM SYSIBM.SYSDUMMY1; -- DB2 ERROR
SELECT VALUE(NULL, NULL) FROM SYSIBM.SYSDUMMY1; -- DB2 ERROR
SELECT VALUE(NULL, 1, NULL) FROM SYSIBM.SYSDUMMY1; -- DB2 ERROR
SELECT VALUE(NULL, '1', NULL) FROM SYSIBM.SYSDUMMY1; -- DB2 ERROR
-- ^= operator
SELECT 1 FROM SYSIBM.SYSDUMMY1 WHERE 1 ^= 2;
SELECT 1 FROM SYSIBM.SYSDUMMY1 WHERE 1 ^= 1;
-- !! operator
SELECT 'FOO' !! ' BAR' FROM SYSIBM.SYSDUMMY1;
-- misc tests
SELECT INT(5) - (INT(5) / 1000) * 1000 FROM SYSIBM.SYSDUMMY1;
SELECT 5 / 1000 FROM SYSIBM.SYSDUMMY1;
SELECT 5.0 / 1000 FROM SYSIBM.SYSDUMMY1;
--
SELECT * FROM SYSIBM.SYSDUMMY1 FETCH FIRST 1 ROWS ONLY;