SQL中的单引号和双引号有什么区别? [英] What is the difference between single and double quotes in SQL?

查看:429
本文介绍了SQL中的单引号和双引号有什么区别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

SQL中的单引号和双引号有什么区别?

What is the difference between single quotes and double quotes in SQL?

推荐答案

单引号用于表示开头和SQL中的字符串结束。双引号通常不在SQL中使用,但数据库与数据库不同。

Single quotes are used to indicate the beginning and end of a string in SQL. Double quotes generally aren't used in SQL, but that can vary from database to database.

坚持使用单引号。

这是主要的用途。对于列别名,您可以使用单引号,您希望在应用程序代码中引用的列名称不是数据库中实际调用该列的值。例如: PRODUCT.id 会比 product_id 更具可读性,因此您可以使用以下方法之一:

That's the primary use anyways. You can use single quotes for a column alias—where you want the column name you reference in your application code to be something other than what the column is actually called in the database. For example: PRODUCT.id would be more readable as product_id, so you use either of the following:


  • SELECT PRODUCT.id AS product_id

  • code> SELECT PRODUCT.id'product_id'

  • SELECT PRODUCT.id AS product_id
  • SELECT PRODUCT.id 'product_id'

MySQL ...但我知道有些人说,使用单引号方法时,TOAD IDE似乎给了一些悲伤。

Either works in Oracle, SQL Server, MySQL … but I know some have said that the TOAD IDE seems to give some grief when using the single quotes approach.

当列别名时,你必须使用单引号包括空格字符,例如 product id ,但不建议对列别名使用多个单词。

You do have to use single quotes when the column alias includes a space character, e.g., product id, but it's not recommended practice for a column alias to be more than one word.

这篇关于SQL中的单引号和双引号有什么区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆