SQL ORA-01756: 当我尝试执行我的代码时引用的字符串没有正确终止
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/26089465/
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
ORA-01756: quoted string not properly terminated when I try to execute my code
提问by Randy Gilman
I keep getting the following message every time I try to run this code in oracle. The code is as follows:
每次尝试在 oracle 中运行此代码时,我都会收到以下消息。代码如下:
DROP TABLE movie;
CREATE TABLE movie (movie_id NUMBER(5) PRIMARY KEY,
title VARCHAR2(45) NOT NULL,
description VARCHAR2(250) NOT NULL,
released_by NUMBER(3) NOT NULL,
released_on DATE NOT NULL);
INSERT INTO movie (movie_id, title, description, released_by, released_on)VALUES ('1', 'Edge of Tomorrow', 'Lieutenant Colonel Bill Cage is a skilled tactician who has honed his abilities through his experiences as a soldier. However, there is still much he can learn, and soon he is going to get his chance.', '1', '07-OCT-2014');
INSERT INTO movie (movie_id, title, description, released_by, released_on)VALUES('2', 'Captain America: Winter Soldier', 'Steve Rogers is finding it difficult to adjust to living life in the contemporary world. He is working for S.H.I.E.L.D. and begins to suspect a mystery is brewing there.', '2', '09-SEP-2014');
INSERT INTO movie (movie_id, title, description, released_by, released_on)VALUES('3', 'Fed Up', 'America's problem with obesity is caused by our inactivity. Or is it? Katie Couric and Stephanie Soechtig tempt us to restructure our beliefs about the American diet, through this thought-provoking expose.', '3', '09-SEP-2014');
INSERT INTO movie (movie_id, title, description, released_by, released_on)VALUES('4', 'Godzilla', 'The legendary tale of Godzilla comes roaring back to life. This time, it's the modern era, and Godzilla is a giant lizard who has been made fearsome through the interference of radiation.', '1', '16-SEP-2014');
INSERT INTO movie (movie_id, title, description, released_by, released_on)VALUES('5', 'Neighbors', 'New parents Mac and Kelly settle into domesticity in a quiet neighborhood. The tranquility they have been afforded ceases to exist when a fraternity moves into the house next door.', '2', '14-SEP-2014');
COMMIT;
Below is what I get when I try to execute it in Oracle:
以下是我尝试在 Oracle 中执行它时得到的结果:
Table dropped.
Table created.
1 row created.
1 row created.
1 row created.
ERROR:
ORA-01756: quoted string not properly terminated
1 row created.
Commit complete.
SQL>
Any help would be greatly appreciated. Thank you.
任何帮助将不胜感激。谢谢你。
回答by beautifulcoder
Escape single quotes:
转义单引号:
INSERT INTO movie (movie_id, title, description, released_by, released_on)VALUES('4', 'Godzilla', 'The legendary tale of Godzilla comes roaring back to life. This time, it''s the modern era, and Godzilla is a giant lizard who has been made fearsome through the interference of radiation.', '1', '16-SEP-2014');
Notice the it''s
instead of it's
.
请注意it''s
代替it's
。
回答by Nagendra Nigade
Try Oracle's quoting mechanisms :
试试 Oracle 的引用机制:
The mechanism is invoked with a simple "q" in PL/SQL only.
该机制仅在 PL/SQL 中使用简单的“q”调用。
The syntax is q'[...]', where the "[" and "]" characters can be any of the following as long as they do not already appear in the string.
语法为 q'[...]',其中“[”和“]”字符可以是以下任何字符,只要它们尚未出现在字符串中即可。
?!
?[ ]
?{ }
?( )
?< >
?!
?[ ]
?{}
?( )
?< >
Here For Example ,
这里例如,
INSERT INTO movie (movie_id, title, description, released_by, released_on)
VALUES('4', 'Godzilla', q'[The legendary tale of Godzilla comes roaring back to
life. This time, it's the modern era, and Godzilla is a giant lizard who has
been made fearsome through the interference of radiation.]', '1', '16-SEP-
2014');
It's always headache to find all single quotes and replace it with escape character.
找到所有单引号并将其替换为转义字符总是很头疼。
For more Reference Follow : THIS
更多参考请关注:这个
回答by fuzz
My solution try:
我的解决方案尝试:
<br>
pelicula = array("titulo"=>"it's the modern era");
<br>
and insert this array.
并插入这个数组。
INSERT(%%%,pelicula["titulo"],%%%).
插入(%%%,pelicula[“标题”],%%%)。
Explicacion: Para evitar el problema de la comilla, copia la cadena a un array, inserta el nombre a traves de este array y el problema se acaba.
解释:Para evitar el problema de la comilla, copia la cadena a un array, inserta el nombre a traves de este array y el problema se acaba。