查看“︁MySQL/POINT”︁的源代码
来自康健生活
←
MySQL/POINT
因为以下原因,您没有权限编辑该页面:
您请求的操作仅限属于该用户组的用户执行:
用户
您可以查看和复制此页面的源代码。
== 测试数据 == <div class="pageBoxGreen">mysql{{Version|8.0+}} 之后的版本,空间数据类型的操作函数在命名上统一在前面加上<code>ST</code>,如 <code>GeomFromText</code> 改为 <code>ST_GeomFromText</code>。</div> 创建测试表和字段。 {{leftrightflex|<syntaxhighlight lang="mysql"> CREATE TABLE `test-location` ( `id` int(11) NOT NULL AUTO_INCREMENT COMMENT '序号', `location` point NOT NULL COMMENT '经纬度', `text` varchar(50) DEFAULT NULL COMMENT '描述', PRIMARY KEY (`id`) ) ENGINE=MyISAM AUTO_INCREMENT=0 DEFAULT CHARSET=utf8mb4;</syntaxhighlight>|{{consoleout|<pre> Query OK, 0 rows affected (0.08 sec) </pre>}}}} {{leftrightflex|<syntaxhighlight lang="mysql"> INSERT INTO `test-location` (location, text) VALUES (ST_GeomFromText('POINT(100 200)'), '测试点1'), (ST_GeomFromText('POINT(300 500)'), '测试点2');</syntaxhighlight>|{{consoleout|<pre> Query OK, 2 rows affected (0.02 sec) Records: 2 Duplicates: 0 Warnings: 0 </pre>}}}} 添加数据还可以使用其他语句。 <syntaxhighlight lang="mysql"> SET @tempdata = 'POINT(100 100)'; INSERT INTO `test-location`(location, text) VALUES ( ST_GeomFromText(@tempdata), '测试点3' ); /** or **/ SET @tempdata = ST_GeomFromText('POINT(100 100)'); INSERT INTO `test-location`(location, text) VALUES ( @tempdata, '测试点4' ); </syntaxhighlight> == 函数 == === Point(X,Y) === Point(X,Y) 是具有精确度的数字的构造函数,不需要先转换为文本,所以速度更快。 === ST_GeomFromText === ST_GeomFromText(wkt, srid)可以返回 MySQL 支持的任何空间类型,可以用 WKT 表示。 === ST_PointFromText === ST_PointFromText(wkt, srid)POINT 来自 Well-known text的强类型构造函数。 == 查询数据 == {{leftrightflex|<syntaxhighlight lang="mysql"> SELECT id, ST_x(location) x, ST_y(location) y, location, text FROM `test-location`; </syntaxhighlight>|{{consoleout|<pre> +----+-----+-----+----------------+------------+ | id | x | y | location | text | +----+-----+-----+----------------+------------+ | 1 | 100 | 200 | POINT(100 200) | 测试点1 | | 2 | 300 | 500 | POINT(300 500) | 测试点2 | +----+-----+-----+----------------+------------+ 2 rows in set (0.01 sec) </pre>}}}} ST_AsText {{leftrightflex|<syntaxhighlight lang="mysql"> SELECT id, ST_AsText(location), text FROM `test-location`;</syntaxhighlight>|{{consoleout|<pre> +----+---------------------+------------+ | id | ST_AsText(location) | text | +----+---------------------+------------+ | 1 | POINT(100 200) | 测试点1 | | 2 | POINT(300 500) | 测试点2 | +----+---------------------+------------+ 2 rows in set (0.00 sec) </pre>}}}} == 更新数据 == {{leftrightflex|<syntaxhighlight lang="mysql"> update `test-location` set location=st_GeomFromText('POINT(123 100)') where id =1;</syntaxhighlight>|{{consoleout|<pre> Query OK, 1 row affected (0.01 sec) Rows matched: 1 Changed: 1 Warnings: 0 </pre>}}}}
此页面嵌入的页面:
模板:Consoleout
(
查看源代码
)
模板:Double-columns
(
查看源代码
)
模板:Double-columns/style.css
(
查看源代码
)
模板:Version
(
查看源代码
)
模板:Version/style.css
(
查看源代码
)
返回
MySQL/POINT
。
导航菜单
康健生活
搜索
user-page
通知
user-interface-preferences
个人工具
登录
五一
多读书,多运动,多到远处走走,再看看不一样的世界。