-3

如何将其从 MS SQL SERVER 转换为 MySQL?

/****** Object: StoredProcedure [dbo].[geolocation_refresh_geography] Script Date: 05/08/2012 22:02:26 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
create procedure [dbo].[geolocation_refresh_geography]
as
update locations
SET geolocation = geography::STPointFromText('POINT(' + CAST([Longitude] AS VARCHAR(20)) + ' ' + CAST([Latitude] AS VARCHAR(20)) + ')', 4326)
where geolocation is null
GO

我的代码在第 4 行导致错误,不知道为什么?

create procedure geolocation_refresh_geography()
BEGIN
update locations
SET geolocation = geography::STPointFromText('POINT(' + CAST(Longitude AS VARCHAR(20)) + ' ' + CAST(Latitude AS VARCHAR(20)) + ')', 4326)
where geolocation is null
END
4

2 回答 2

0

您是否尝试过 MySQL 迁移工具包?

http://dev.mysql.com/doc/migration-toolkit/en/mysql-migration-toolkit-indepth-sourcedb-mssql.html

这些天很难找到,但我相信您也可以使用 MySQL Workbench 来完成此任务。 http://www.mysql.com/products/workbench/

我建议只迁移您应该为您移植过程的整个架构。

于 2012-05-22T15:53:09.610 回答
0

对于初学者,MySQL 仅在启用了 Spatial Extensions 的情况下才支持空间数据 (http://dev.mysql.com/doc/refman/5.0/en/spatial-extensions.html)。假设您已经进行了该设置,您只需将 SQL Server 语法调整为适当的 MySQL 方法。

MySQL 有一个 PointFromText() 方法 (http://dev.mysql.com/doc/refman/5.0/en/creating-spatial-values.html#function_pointfromtext),它反映了 SQL Server 的 STPointFromText() (http:// /msdn.microsoft.com/en-us/library/bb933979.aspx),因此您可以简单地将对geography::STPointFromText的引用替换为PointFromText

但是,要从单个纬度/经度坐标对插入点,最简单的方法是 Point() (http://dev.mysql.com/doc/refman/5.0/en/creating-spatial- values.html#function_point),在这种情况下,您的代码将变为:

create procedure geolocation_refresh_geography()
BEGIN
update locations
SET geolocation = Point(Longitude, Latitude)
where geolocation is null
END
于 2012-05-22T20:41:38.847 回答