| 1 |
drop table if exists t1; |
| 2 |
CREATE FUNCTION myfunc_double RETURNS REAL SONAME "UDF_EXAMPLE_LIB"; |
| 3 |
CREATE FUNCTION myfunc_int RETURNS INTEGER SONAME "UDF_EXAMPLE_LIB"; |
| 4 |
CREATE AGGREGATE FUNCTION avgcost RETURNS REAL SONAME "UDF_EXAMPLE_LIB"; |
| 5 |
SELECT myfunc_double(); |
| 6 |
ERROR HY000: Can't initialize function 'myfunc_double'; myfunc_double must have at least one argument |
| 7 |
SELECT myfunc_double(1); |
| 8 |
myfunc_double(1) |
| 9 |
49.00 |
| 10 |
SELECT myfunc_double(78654); |
| 11 |
myfunc_double(78654) |
| 12 |
54.00 |
| 13 |
SELECT myfunc_int(); |
| 14 |
myfunc_int() |
| 15 |
0 |
| 16 |
SELECT myfunc_int(5); |
| 17 |
myfunc_int(5) |
| 18 |
5 |
| 19 |
SELECT myfunc_int('MySQL V8.0'); |
| 20 |
myfunc_int('MySQL V8.0') |
| 21 |
10 |
| 22 |
CREATE TABLE t1(a INT, b INT); |
| 23 |
INSERT INTO t1 values (1,1),(2,2); |
| 24 |
SELECT myfunc_int(a AS attr_name) FROM t1; |
| 25 |
myfunc_int(a AS attr_name) |
| 26 |
1 |
| 27 |
2 |
| 28 |
DROP TABLE t1; |
| 29 |
CREATE TABLE t1(sum int, price float(24)); |
| 30 |
INSERT INTO t1 VALUES(100, 50.00), (100, 100.00); |
| 31 |
SELECT avgcost(sum, price) from t1; |
| 32 |
avgcost(sum, price) |
| 33 |
75.0000 |
| 34 |
DELETE from t1; |
| 35 |
INSERT INTO t1 VALUES(100, 54.33), (200, 199.99); |
| 36 |
SELECT avgcost(sum, price) from t1; |
| 37 |
avgcost(sum, price) |
| 38 |
151.4367 |
| 39 |
DROP TABLE t1; |
| 40 |
DROP FUNCTION myfunc_double; |
| 41 |
DROP FUNCTION myfunc_int; |
| 42 |
DROP FUNCTION avgcost; |
| 43 |
SELECT myfunc_double(1); |
| 44 |
ERROR 42000: FUNCTION test.myfunc_double does not exist |
| 45 |
SELECT myfunc_int(1); |
| 46 |
ERROR 42000: FUNCTION test.myfunc_int does not exist |
| 47 |
CREATE FUNCTION myfunc_double RETURNS REAL SONAME "UDF_EXAMPLE_LIB"; |
| 48 |
CREATE FUNCTION myfunc_int RETURNS INTEGER SONAME "UDF_EXAMPLE_LIB"; |
| 49 |
CREATE AGGREGATE FUNCTION avgcost RETURNS REAL SONAME "UDF_EXAMPLE_LIB"; |
| 50 |
SELECT myfunc_double(78654); |
| 51 |
myfunc_double(78654) |
| 52 |
54.00 |
| 53 |
SELECT myfunc_int(5); |
| 54 |
myfunc_int(5) |
| 55 |
5 |
| 56 |
DROP FUNCTION myfunc_int; |
| 57 |
SELECT myfunc_double(78654); |
| 58 |
myfunc_double(78654) |
| 59 |
54.00 |
| 60 |
SELECT myfunc_int(5); |
| 61 |
ERROR 42000: FUNCTION test.myfunc_int does not exist |
| 62 |
DROP FUNCTION myfunc_double; |
| 63 |
DROP FUNCTION avgcost; |