oracle ORA-01756: 带引号的字符串未正确终止

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/8506324/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-19 00:30:40  来源:igfitidea点击:

ORA-01756: quoted string not properly terminated

sqlvisual-studiooracle

提问by user1081326

I have this error, and i roughly know where it is, but do not know how to correct it.

我有这个错误,我大致知道它在哪里,但不知道如何纠正它。

Error Message:

错误信息:

ORA-01756: quoted string not properly terminated

ORA-01756: 带引号的字符串未正确终止

"INSERT INTO Patients1 VALUES ('System.Windows.Forms.TextBox, Text: 0001' ,'M', '25-AUG-1991' , 'Aaron' , 'R' , 'O'Neill' , '6ft' , '11st' , '0664534334' , '0876543213' , '0001' , 'PAT', 'has a heart condition')"

“插入患者 1 值('System.Windows.Forms.TextBox,文本:0001','M','25-AUG-1991','Aaron','R','O'Neill','6ft', '11st'、'0664534334'、'0876543213'、'0001'、'PAT'、'有心脏病')”

and here is my code:

这是我的代码:

string sql = "INSERT INTO Patients1 VALUES (" + TxtPatientId +"' ,'" + TxtGender.Text + "', '" + TxtDob.Text + "' , '" + TxtFName.Text + "' , '" +
                TxtMName.Text + "' , '" + TxtLName.Text + "' , '" + TxtHeight.Text + "' , '" + TxtWeight.Text + "' , '" + TxtHomePh.Text + 
                "' , '" + TxtMobPhone.Text + "' , '"  + TxtDocId.Text + "' , '" + TxtViewType.Text + "', '" +
                TxtPDetails.Text + "')";

I think my error is coming from the very 1st input (PatientId).

我认为我的错误来自第一个输入(PatientId)。

my database table looks like this:

我的数据库表如下所示:

CREATE TABLE Patient1
   (Patient_id NUMBER(6)    NOT NULL,
    GENDER VARCHAR2(1) NOT NULL, 
    DATE_OF_BIRTH DATE,
    PATIENT_FIRST_NAME VARCHAR2(9)  NOT NULL,
    PATIENT_MIDDLE_INITIAL VARCHAR2(1),
    PATIENT_SURNAME VARCHAR2(9) NOT NULL,
    HEIGHT NUMBER(3,2),
    WEIGHT NUMBER(5,2),
    HOME_PHONE NUMBER(10)   NOT NULL,
    MOBILE_PHONE NUMBER(10) NOT NULL,
    DOCTOR_ID NUMBER(6) NOT NULL,
    VIEWTYPE VARCHAR2(3) DEFAULT 'PAT',
    OTHER_PATIENT_DETAILS VARCHAR2(50),
    CONSTRAINT patients_pk PRIMARY KEY(Patient_id));

Any help here would be appreciated

任何帮助在这里将不胜感激

回答by Michael Berkowski

Looks like you are not accessing the .textproperty of the input. Additionally, you have not opened a single quote for the first item in the VALUESlist:

看起来您没有访问.text输入的属性。此外,您还没有为VALUES列表中的第一项打开单引号:

VALUES (" + TxtPatientId +"'

Should be:

应该:

VALUES ('" + TxtPatientId.text +"'

You have not escaped single quotes in your other parameters. O'Neillhas a quote which breaks the rest of the statement.

您没有在其他参数中转义单引号。 O'Neill有一个引用打破了声明的其余部分。

See @vc 74's answer for information on using bound parameters instead of concatenated strings to build your query.

有关使用绑定参数而不是连接字符串来构建查询的信息,请参阅 @vc 74 的答案。

回答by vc 74

You need to escape the single quote in O'Neill by doubling it or use bind parametersinstead of hardcoded values in your query

您需要通过将单引号加倍或在查询中使用绑定参数而不是硬编码值来转义 O'Neill 中的单引号