SQL 如何在sqlite3中输入类型转换
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/32953639/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to type cast in sqlite3
提问by Abundance
I ran sqlite3 on my command prompt and ran some basic SQL commands.
我在命令提示符下运行了 sqlite3 并运行了一些基本的 SQL 命令。
user@comp:~$ sqlite3
SQLite version 3.8.2 2013-12-06 14:53:30
Enter ".help" for instructions
Enter SQL statements terminated with a ";"
sqlite> CREATE TABLE A (a int, b text, c float);
sqlite> INSERT INTO A(a,b,c) VALUES (1, '2', 3);
sqlite> SELECT b::int+2 FROM A;
All of the lines work except for the last one, which gives the error: `
除了最后一行之外,所有行都有效,这给出了错误:`
Error: unrecognized token: ":"`
错误:无法识别的令牌:“:”`
I was reading from this question (Double colon (::) notation in SQL) that the double colon notation is a type-cast for SQL. Am I doing the operation wrong?
回答by Lukasz Szozda
The ::
syntax is PostgreSQL specific. You could use ANSI standard instead:
该::
语法是PostgreSQL的具体。您可以改用 ANSI 标准:
SELECT CAST(b AS INT) + 2 AS alias
FROM A