Skip to main content
 首页 » 编程设计

c#之pl/sql 查询和 .net 的奇怪行为

2024年02月24日16freeliver54

我运行此查询以使用 OracleCommand 的输出参数读取记录的计数:

var query = "declare MyCount number; begin SELECT COUNT(*) INTO :MyCount FROM T_ISSUE; end;"; 

这个很好用。

但是如果我像这样将查询分成两行:

var query = @"declare MyCount number;  
              begin SELECT COUNT(*) INTO :MyCount FROM T_ISSUE; end;"; 

我得到以下异常:

System.Data.OracleClient.OracleException: ORA-06550: line 1, column 25: 
PLS-00103: Encountered the symbol "" when expecting one of the following: 
 
   begin function package pragma procedure subtype type use 
   <an identifier> <a double-quoted delimited-identifier> form 
   current cursor 
The symbol "" was ignored. 

有人知道为什么吗?

感谢您的帮助。

请您参考如下方法:

这是由于 VS 使用 windows 风格的换行符 (CR+LF) 但 Oracle 只接受 Unix 风格(仅 LF)。

至少在 VB6 中是这样。