Home > Database > Mysql Tutorial > Oracle Error Workaround

Oracle Error Workaround

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2016-06-07 16:56:28
Original
950 people have browsed it

在实际项目中使用ORACLE时出现的一些问题,通过变通的方案将问题避免了,特撰此文,以备忘用!1.ORA-01403:NO DATA FOUND-未找到

在实际项目中使用Oracle时出现的一些问题,通过变通的方案将问题避免了,特撰此文,,以备忘用!

1.ORA-01403:NO DATA FOUND-未找到数据

  a.加一个exception异常处理

EXCEPTION WHEN NO_DATA_FOUND THEN ...
  b.先用count计算一下是否大于0,即是否有值,这样就算没有值也会返回0,而不是NULL

SELECT COUNT(*) INTO FIELD FROM TABLE WHERE ...
 2.ORA-01704:STRING LITERAL TOO LONG-文字字符串过长

  直接用类似INSERT INTO TABLE (ID,CONTEXT) VALUES('1','...')语句向ORACLE插入长字节的字段CONTEXT时会出现此错误信息

  a.在程序中可以利用参数来实现

C#代码
1 OracleConnection ocon = new OracleConnection();
2 OracleCommand ocom = new OracleCommand(sql, ocon);
3 ocom.Connection.Open();
4 ocom.Parameters.Add(":Value", OracleType.Blob);
5 ocom.Parameters[":Value"].Value = longvalue;
6 ocom.ExecuteNonQuery();
  b.利用存储过程来实现相对比较简单,只要将参数传入即可

DECLARE
   v_context CLOB :='long context';
BEGIN
    INSERT INTO TABLE (ID,CONTEXT) VALUES ('1',:v_context);
END;

linux

Related labels:
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template