ITPub博客

首页 > 数据库 > Oracle > varchar2类型默认值问题

varchar2类型默认值问题

原创 Oracle 作者:老w爱db 时间:2024-02-21 14:06:28 0 删除 编辑

今天有朋友反馈有字段varchar2(5)可以默认为00000,于是自己测试了一下,果然可以

建表语句:

-- Create table

create table BB

(

  o NUMBER not null,

  p VARCHAR2(5) default 000000 not null

)

tablespace HIP_DATA

  pctfree 10

  initrans 1

  maxtrans 255

  storage

  (

    initial 64K

    next 1M

    minextents 1

    maxextents unlimited

  );

-- Create/Recreate primary, unique and foreign key constraints 

alter table BB

  add constraint PK_BB primary key (O)

  using index 

  tablespace HIP_DATA

  pctfree 10

  initrans 2

  maxtrans 255

  storage

  (

    initial 64K

    next 1M

    minextents 1

    maxextents unlimited

  );

插入2条数据后,出现默认值都是0:

修改默认值为000001后再插入1条数据,出现默认值都是1的情况


修改默认值为100000,报错:

同样修改默认值为'000000',报错:



为了避免默认值的位数问题,varchar2类型的默认值尽量加双引号。

来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/70021989/viewspace-3006957/ ,如需转载,请注明出处,否则将追究法律责任。

请登录后发表评论 登录
全部评论
数据库技术爱好者

注册时间:2022-09-12

  • 博文量
    75
  • 访问量
    67608