ORA-01756:当我尝试执行代码时,引用的字符串未正确终止

时间:2014-09-28 20:43:18

标签: sql oracle insert

每次尝试在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;

下面是我尝试在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>

非常感谢任何帮助。谢谢。

3 个答案:

答案 0 :(得分:6)

逃避单引号:

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

请注意it''s而不是it's

答案 1 :(得分:5)

尝试Oracle的引用机制:

仅在PL / SQL中使用简单的“q”调用该机制。

语法为q'[...]',其中“[”和“]”字符可以是以下任意一个,只要它们不会出现在字符串中。

  

•!

     

•[]

     

•{}

     

•()

     

•< >

这里例如,

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

找到所有单引号并用转义字符替换它总是很头疼。

更多参考资料:THIS

答案 2 :(得分:-1)

我的解决方案尝试:

<br>
pelicula = array("titulo"=>"it's the modern era");
<br>

并插入此数组。

INSERT(%%%,PELICULA [&#34; TITULO&#34],%%%)。

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。