0

I have this script written in SQL Server 2008 and need to convert it to Oracle SQL this way I can run it in Oracle SQL Developer. Would anyone know the correct syntax? The main things here I would like to know are the following: 1) Declaring local variables 2) Setting local variables 3) Use the local variables 4) Using dates. Thanks very much for your help in advanced.

DECLARE @Name VARCHAR(55)
DECLARE @Age INT
DECLARE @StartDate DATETIME
DECLARE @EndDate DATETIME

SET @NAME = 'Tim'
SET @Age = 55
SET @StartDate = '5/10/1999'
SET @EndDate = '9/22/2008'

SELECT *
FROM TblIdentifier ident
WHERE Name = @Name AND 
      Age = @Age AND 
      Birthday BETWEEN @StartDate AND @EndDate 
ORDER BY ident.ID

1 Answers1

0

Yes. You should consider looking at SQL Plus instead for the scripting. Follow the link in the comment above. There is a way to kind of fake what you want, so you can use it in SQL Developer. Here is a simple example

WITH
konstants AS
(
    SELECT 'Tim' NAME,
           55    AGE
    FROM DUAL
)
SELECT *
FROM TblIdentifier 
WHERE NAME = (SELECT NAME FROM konstants) 
  AND AGE  = (SELECT AGE  FROM konstants)

This puts the constants at the top of the query, so they are in only one place, and it is easy to find and change when you need to.

EvilTeach
  • 28,120
  • 21
  • 85
  • 141