So here is a simple issue, I want a stored procedure to return a data set. I want to pass in parameters and have those parameters be used as criteria to filter the data returned. Not a rocket science request, hell not even a bottle rocket science request. Here's how you do it in SQL Server:
Create Procedure dbo.SomeTableSelect
( @SomeID INT ,
@SomeValue Varchar(50)
)
as
Select SomeID,SomeValue,SomeDate
From dbo.SomeTable
Where SomeID = @SomeID
and SomeValue = @SomeValue
Pretty simple and easy to do right? Well transfer that to Oracle. Guess what, it doesn't work that way! In Oracle, you can pass in parameters but you have to use a cursor to get back the data. What's really fun, is if you want to run the procedure, you have to declare a cursor so that the cursor inside the procedure can write data out. GAHH!
Oracle code:
CREATE OR REPLACE PROCEDURE SOMETABLESELECT
(
P_SOMEID IN NUMBER,
P_SOMEVALUE IN VARCHAR2,
P_OUT_REF OUT SYS_REFCURSOR
)
AS
BEGIN
OPEN P_OUT_REF FOR
SELECT SOMEID, SOMEVALUE, SOMEDATE
FROM SOMETABLE
WHERE SOMEID = P_SOMEID
AND SOMEVALUE = P_SOMEVALUE;
END;
Some things to remember in Oracle
1) Oracle is case sensitive! Always name your objects with ALL CAPS, it will not find the procedure SomeTableSelect, no matter how much you yell at it that the stupid thing is right there.
2) Always use a BEGIN and END, you have to actually or the syntax will be invalid.
3) Remember your ";" this ends commands in Oracle and you need it.
4) Oracle will let you create a procedure that is completely invalid, yipee.
Oracle doesn't actually hate to return data, but it seems to assume that you will only ever ask for a single row. Many examples of how to return data have you putting the result set into a group of out output variables, which means you could only return a single row.
In conclusion, I think SQL Server wins this round. The ability to extract data from your database seems pretty simple and direct. SQL Server makes it easypie and Oracle seems to think it's funny to make me jump through hoops.
--matt
stop the stupid!
Wednesday, August 19, 2009
Subscribe to:
Post Comments (Atom)

Oh, this is too fun. I get to restore databases to test from production for both Oracle and Microsoft SQL Server all of the time. Microsoft SQL Server takes a few minutes, Oracle takes hours! Granted Oracle has it's backups on tape drives and MS SQL has it on disk, but still...
ReplyDeleteI would pay money to see you jump through hoops!!
ReplyDeletezip it Jack :)
ReplyDelete