本人刚刚接触数据库方面的一些东西,但由于数据库类型较多,接触比较多的是oracle,但在学习过程中经常碰到sql server或mysql的数据库例子,将其他复制到oracle中发现经常会报些奇怪的异常,如以下两个例子:请大侠们指教下,是不是不同类型的数据库及不同版本的数据库有不同的支持,作为一个初学者,而且想更多实习oracle的话,应该如何面对这些问题,谢谢!
create table students
(
  id varchar(10) not null,
  name nvarchar(10),
  sex nchar(2),
  age int default 0 not null,
  check (age >= 0  and age < 150)
)ORA-00907: 缺少右括号CREATE TABLE tblUser(
UserID VARCHAR(50) NOT NULL,
UserName VARCHAR(20) NOT NULL,
UserPassword VARCHAR(50) NOT NULL,
UserMail VARCHAR(50) NOT NULL,
UserType INTEGER DEFAULT(0),
UserCreated DATETIME DEFAULT(getdate()) NOT NULL
)ORA-00904: "GETDATE": 无效的标识符

解决方案 »

  1.   

       create table students 

      id varchar2(10) not null, 
      name  varchar2(10), 
      sex  char(2), 
      age int default 0, 
      constraint CKC_age_students check (BREAK_ID is null or (BREAK_ID between 0 and 149)) 
    ) CREATE TABLE tblUser( 
    UserID VARCHAR2(50) NOT NULL, 
    UserName VARCHAR2(20) NOT NULL, 
    UserPassword VARCHAR2(50) NOT NULL, 
    UserMail VARCHAR2(50) NOT NULL, 
    UserType INTEGER DEFAULT 0, 
    UserCreated date default SYSDATE NOT NULL 
      

  2.   

    第一个修改下   create table students 

      id varchar2(10) not null, 
      name  varchar2(10), 
      sex  char(2), 
      age int default 0, 
      constraint CKC_age_students check (age is null or (age between 0 and 149)) 
      

  3.   

    create table students 

      id varchar(10) not null, 
      name nvarchar2(10), 
      sex nchar(2), 
      age int default 0 not null, 
      constraint VALID_AGE_CHECK check (age >=0 and age <150)
    );
    CREATE TABLE tblUser( 
    UserID VARCHAR(50) NOT NULL, 
    UserName VARCHAR(20) NOT NULL, 
    UserPassword VARCHAR(50) NOT NULL, 
    UserMail VARCHAR(50) NOT NULL, 
    UserType INTEGER DEFAULT(0), 
    UserCreated DATE DEFAULT SYSDATE NOT NULL 
    ) ;
      

  4.   

    不好意思,忘了 not null了
     create table students 

      id varchar2(10) not null, 
      name  varchar2(10), 
      sex  char(2), 
      age int default 0 not null , 
      constraint CKC_age_students check ( age between 0 and 149 ) 
      

  5.   


    楼主就2个大问题
    1.定义的check约束,最好是使用constraint关键词来定义,具体如楼上int和sun所定义
    2.oracle取当前系统时间是直接使用sysdate,sql server中是getdate(),注意下这个区别就行了