Search code examples
oracleddlcheck-constraints

How to translate check constraint from SQL Server to Oracle


I'd have to translate the followed sql server constraint:

ALTER TABLE [dbo].[tblLocal_FDIMP_SRCDESCFTP]  WITH CHECK ADD  CONSTRAINT [fmtfile_chk] CHECK  (
   (  (1) = case 
            when [file_type]='LBC' AND [fmtfile]='ZIP' then (1) 
            when ([file_type]='AE' OR [file_type]='TS') AND ([fmtfile] IS NULL OR upper([fmtfile])='ZIP') then (1) 
            else (0) end
))GO

What would be the equivalent constraint translate to Oracle syntax ?

Thanks


Solution

  • Why do people use 1 = CASE for conditions?

    ALTER TABLE tblLocal_FDIMP_SRCDESCFTP 
    ADD  CONSTRAINT fmtfile_chk CHECK  ((file_type='LBC' AND fmtfile='ZIP') 
                                    OR ((file_type='AE' OR file_type='TS') AND (fmtfile IS NULL OR UPPER(fmtfile)='ZIP')));