1 Reply Latest reply: Jul 8, 2013 3:04 AM by Mihael RSS

    Field constraint for days of week using single letter representation.

    mbuchanan

      I know I can add a check constraint for m,t,w,r,f,s,u

       

      How can I add a constraint that will allow any combination of the above.

       

      For example it would allow m or mf, or mwf

       

      Someone said it could be done with trim but I can not figure it out.

       

       

      Thanks in advance.

        • 1. Re: Field constraint for days of week using single letter representation.
          Mihael

          You can use regex functions, for example :

           

          create table t1 (v varchar2 (15) constraint c1 check (regexp_replace(

                                                                regexp_replace(

                                                                regexp_replace(

                                                                regexp_replace(

                                                                regexp_replace(

                                                                regexp_replace(

                                                                regexp_replace(v, 'm','',1,1),

                                                                                  't','',1,1),

                                                                                  'w','',1,1),

                                                                                  'r','',1,1),

                                                                                  'f','',1,1),

                                                                                  's','',1,1),

                                                                                  'u','',1,1) is null) );

           

          You can try to do this code more simple, using only one regexp function.