我正在使用 Oracle 的 ADO.Net 提供程序来执行 2 个用分号分隔的选择语句。我正在使用 system.Data.OracleClient 数据提供程序。但是,Oracle 似乎不喜欢分号,因为在 ADO.Net 代码运行时出现无效字符错误。关于如何解决这个问题的任何想法,因为我必须在同一个数据库行程中运行两个 SELECT 语句?
string sql = @"
WITH
x AS
(
SELECT
RowNum AS RowIndex,
CAST(Contract_Id AS VARCHAR2(1000)) Contract_Id,
Contract_Number,
Name AS Contract_Name,
Contract_Number
|| ' '
|| Name AS Contract_Description,
Eff_Date,
Expiry_Date
FROM
contracts
WHERE
contract_number LIKE :ContractSearchText
OR name LIKE :ContractSearchText
)
SELECT
*
FROM
x
WHERE
RowIndex >= :StartingRowIndex
AND RowIndex < (:StartingRowIndex + :MaxRows) ;
SELECT
COUNT(*)
FROM
contracts
WHERE
contract_number LIKE :ContractSearchText
OR name LIKE :ContractSearchText;
";
更新
亚历克斯的回复是我能找到的最佳答案。但是,我想出了另一个替代答案,我不确定桌子是被击中两次还是只被击中一次。备用查询依赖于使用计数派生表创建 CROSS JOIN。可能有人可以告诉我在这个替代答案中桌子是否只被击中一次?
WITH
x AS
(
SELECT
RowNum AS RowIndex,
CAST(Contract_Id AS VARCHAR2(1000)) Contract_Id,
Contract_Number,
Name AS Contract_Name,
Contract_Number
|| ' '
|| Name AS Contract_Description,
Eff_Date,
Expiry_Date
FROM
vha_int_contract
WHERE
contract_number LIKE :ContractSearchText
OR name LIKE :ContractSearchText
),
y as ( select count(distinct contract_id) TotalCount from x)
SELECT
*
FROM
x cross join y
WHERE
RowIndex >= :StartingRowIndex
AND RowIndex < (:StartingRowIndex + :MaxRows)