Oracle 10g - 在插入语句中转义引号
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/5326085/
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
Oracle 10g - Escape quote in insert statement
提问by oracleNewb
I am trying to insert people's height into a database in the form of 5'9
我正在尝试以 5'9 的形式将人的身高插入到数据库中
How do I properly escape the quote so I can do this. My insert statement looks like this so far.
我如何正确地转义引用以便我可以做到这一点。到目前为止,我的插入语句看起来像这样。
INSERT INTO height(id, height)
VALUES(height-seq.nexval, '5\'9');
The backslash does not work obviously and I am pretty new to oracle. Thanks
反斜杠显然不起作用,我对 oracle 还很陌生。谢谢
回答by a_horse_with_no_name
Oracle uses standard SQL:
Oracle 使用标准 SQL:
INSERT INTO height(id, height) VALUES(height-seq.nexval, '5''9');
(Yes there are two single quotes)
(是的,有两个单引号)
回答by Prashant Lakhlani
if you are doing this from a front end using some programming language, consider using a parametrized query, if you are in psql or some other tool to do this, just use '5''9 ' and it will work fine
如果您使用某种编程语言从前端执行此操作,请考虑使用参数化查询,如果您使用 psql 或其他一些工具来执行此操作,只需使用 '5''9' 就可以正常工作
回答by Rob van Laarhoven
I hate double quoting, it's a mess. Luckely these days we have the quote operator:
我讨厌双引号,这是一团糟。幸运的是,这些天我们有了报价运算符:
q'{delimiter}string{delimiter}'
INSERT INTO height(id, height)
VALUES(height-seq.nexval, q'#5'9#');