I am using the ADO.Net provider for Oracle to execute 2 select statements separated by a semi-colon. I am using system.Data.OracleClient data provider. However, it seems the semi-colon is not liked by Oracle becuase I get an invalid character error when the ADO.Net code runs. Any ideas on how I could solve this as I have to run both SELECT statements in same database trip?
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;
";
UPDATE
Alex's reply is the best answer I could find. However, I had come up with another alternate answer, about which I am not sure if the table is hit twice or only once. The alternate query relies on creating a CROSS JOIN with a count derived table. May be someone can tell me if the table is hit only once in this alternate answer?
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)