I have a simple SQL Server stored proc
CREATE PROCEDURE [dbo].[some_proc]
AS
BEGIN
DECLARE @CountA INT
DECLARE @CountB INT
DECLARE @CountC INT
DECLARE @CountD INT
SELECT @CountA = COUNT(*) FROM some_table WHERE Status IN (7,8,9)
SELECT @CountB = COUNT(*) FROM some_table WHERE Status IN (5)
SELECT @CountC = COUNT(*) FROM some_table WHERE Status IN (6)
SELECT @CountD = COUNT(*) FROM some_table
SELECT @CountA AS aCount , @CountB AS bCount , @CountC AS cCount , @CountD AS dCount
END
GO
We support both SQL Server and Oracle database for our product, so I need to convert this to PL/SQL function. What would be the equivalent pl/sql function?
Expected outcome should be one row of data with column names aCount,bCount, cCount, dCount (I already have ADO.net code done and working with SQL server stored proc). This is what I have so far. From limited knowledge that I have I know I need to user cursor somehow, but can't figure out how.
CREATE OR REPLACE FUNCTION some_proc(
p_ix_sys_error OUT number
)
IS
DECLARE
CountA NUMBER;
CountB NUMBER;
CountC NUMBER;
CountD NUMBER;
BEGIN
SELECT COUNT(*) INTO CountA FROM some_table WHERE Status IN (7,8,9);
SELECT COUNT(*) INTO CountB FROM some_table WHERE Status IN (5);
SELECT COUNT(*) INTO CountC FROM some_table WHERE Status IN (6);
SELECT COUNT(*) INTO CountD FROM some_table;
SELECT CountA AS aCount , CountB AS bCount , CountC AS cCount , CountD AS dCount
END
GO