MySQL/POINT:修订间差异

来自康健生活
Kangkk​(留言 | 贡献)
Kangkk​(留言 | 贡献)
第59行: 第59行:
2 rows in set (0.01 sec)
2 rows in set (0.01 sec)
</pre>}}}}
</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>}}}}
== 更新数据 ==

2022年8月9日 (二) 09:55的版本

测试数据

mysql 之后的版本,空间数据类型的操作函数在命名上统一在前面加上ST,如 GeomFromText 改为 ST_GeomFromText。

创建测试表和字段。

模板:Leftrightflex

模板:Leftrightflex

添加数据还可以使用其他语句。

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'
);

函数

ST_GeomFromText

ST_PointFromText

查询数据

模板:Leftrightflex

ST_AsText 模板:Leftrightflex

更新数据