check constraint

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • todashah
    New Member
    • Feb 2008
    • 26

    check constraint

    how can i put check constraint for date while creating a table.
    I want to pass a constant as a date and do not want to pass as a database variable.
  • amitpatel66
    Recognized Expert Top Contributor
    • Mar 2007
    • 2358

    #2
    Try this:

    [code=oracle]

    create table t12(dat date, CONSTRAINT my_cons CHECK (dat BETWEEN '01-JAN-2009' AND '31-JAN-2009'))

    [/code]

    Comment

    • hiral amit patel
      New Member
      • Jul 2009
      • 5

      #3
      check constraint

      i have tried that one but not able to create such table.
      the following error is being generated


      create table t12(dat date,constraint my_cons check(dat between '01-jan-2009' and '31-jan-2009'))
      *
      ERROR at line 1:
      ORA-02436: date or system variable wrongly specified in CHECK constraint

      Comment

      • amitpatel66
        Recognized Expert Top Contributor
        • Mar 2007
        • 2358

        #4
        Which database version you are using?

        Comment

        • amitpatel66
          Recognized Expert Top Contributor
          • Mar 2007
          • 2358

          #5
          I am able to create the table using same code as shown:

          [code=oracle]

          SQL> create table t12(dat date,constraint my_cons check(dat between '01-jan-2009' and '31-jan-2009')
          )
          2 /

          Table created.

          SQL>

          [/code]

          Comment

          • hiral amit patel
            New Member
            • Jul 2009
            • 5

            #6
            check constraint

            Hi amit

            I m using oracle 8i

            Comment

            • amitpatel66
              Recognized Expert Top Contributor
              • Mar 2007
              • 2358

              #7
              Please post the output of the below query:

              [code=oracle]

              SELECT * FROM v$version

              [/code]

              Comment

              Working...