![]() | |
#1
| |||
| |||
|
#2
| |||
| |||
|
|
Can someone PLEASE tell me why the response is that 'the function "[database].gps_distance" doesn't exist'? Can someone tell me what I'm missing in this? |
|
gps_distance(1,1,1,1,6371) | +----------------------------+ 0.000000 | +----------------------------+ |
#3
| |||
| |||
|
|
On 2010-10-26 21:15, Charles wrote: [...] Can someone PLEASE tell me why the response is that 'the function "[database].gps_distance" doesn't exist'? Can someone tell me what I'm missing in this? Did the function compile successfully? Not sure it is the problem, but I had to change your function a bit before I could get it to compile. After that I have no trouble accessing the function: mysql> delimiter $$ mysql mysql> CREATE FUNCTION gps_distance(lat1 DECIMAL(9,6), long1 DECIMAL(9,6), * * -> * * lat2 DECIMAL(9,6), long2 DECIMAL(9,6), avgradius FLOAT) * * -> * * RETURNS DECIMAL(9,6) * * -> RETURN ACOS(COS(RADIANS(90-lat1)) *COS(RADIANS(90-lat2)) * * -> +SIN(RADIANS(90-lat1)) *SIN(RADIANS(90-lat2)) * * -> *COS(RADIANS(long1-long2))) * avgradius $$ Query OK, 0 rows affected (0.00 sec) mysql> DELIMITER ; mysql> SELECT gps_distance(1,1,1,1,6371); +----------------------------+ | gps_distance(1,1,1,1,6371) | +----------------------------+ | * * * * * * * * * 0.000000 | +----------------------------+ 1 row in set (0.07 sec) |
#4
| |||
| |||
|
|
From the first DELIMITER ; to the last DELIMITER ; in the original code it runs without error. The second part runs without error. The CREATE TABLE ... portion returns the error that the function doesn't exist. |
#5
| |||
| |||
|
|
On 2010-10-26 23:38, Charles wrote: From the first DELIMITER ; to the last DELIMITER ; in the original code it runs without error. *The second part runs without error. *The CREATE TABLE ... portion returns the error that the function doesn't exist. I suggest you start with something simpler than your codesnippet (my example for example). Your code *should* not create the function since you don't have a $$ at the end somewhere, perhaps your admintool is playing you a joke by not showing you the real error (that the function where not created successfully)? /Lennart |
#6
| |||
| |||
|
|
delimiter $$ |
|
CREATE FUNCTION gps_distance(lat1 DECIMAL(9,6), long1 DECIMAL(9,6), lat2 DECIMAL(9,6), long2 DECIMAL(9,6), avgradius FLOAT) RETURNS DECIMAL(9,6) RETURN (ACOS(COS(RADIANS(90-lat1)) *COS(RADIANS(90-lat2)) +SIN(RADIANS(90-lat1)) *SIN(RADIANS(90-lat2)) *COS(RADIANS(long1-long2))) * avgradius; |
#7
| |||
| |||
|
|
Am 26.10.2010 21:15, schrieb Charles: delimiter $$ Here you set the delimiter to '$$'. CREATE FUNCTION gps_distance(lat1 DECIMAL(9,6), long1 DECIMAL(9,6), * * *lat2 DECIMAL(9,6), long2 DECIMAL(9,6), avgradius FLOAT) * * *RETURNS DECIMAL(9,6) RETURN (ACOS(COS(RADIANS(90-lat1)) *COS(RADIANS(90-lat2)) +SIN(RADIANS(90-lat1)) *SIN(RADIANS(90-lat2)) *COS(RADIANS(long1-long2))) * avgradius; But here you end your CREATE FUNCTION statement (delimit it from the next statement) with ';'. HTH, Helmut |
![]() |
| Thread Tools | |
| Display Modes | |
| |