我是学习Oracle SQL新人,请教各位大神,我想在现有表基础上新增三个字段,“是否实名”,“手机状态”,和“在网时长”。
具体需求:
是否实名:如进行过实名,显示“是”;没有则“否;如果没有查询到结果,则为空”。
手机状态:需要显示“未启用”,“正常”,“停机”,“不在网”,“”或“无法查询”。
在网时长:需要显示“1个月以下”,“2个月”,“3-6个月”,“7-12个月”,“13-24个月”,“25-36个月”,“37个月以上”,“手机不在网”或“该手机号码不存在”。
请教各位大神,具体代码应该怎么写,谢谢!

解决方案 »

  1.   

    增加字段用这样的语法alter table t add column 实名 varchar(20)要显示“是” 和 “否”,这些数据从哪里来的?
      

  2.   

    应该是打标签吧,例如case when b.serv_number is not null then 'Y' else 'N' end is_online 
      

  3.   

    添加字段的语法:alter table tablename add (column datatype [default value][null/not null],….);
    你把字段加上,表结构列下,SQL语句可以作好相应的逻辑判断。
      

  4.   

    给你个参考建表:
    -- Create table
    create table T_SP_SQL_RESULT
    (
      project_id         VARCHAR2(40),
      select_id          VARCHAR2(40),
      data_from          VARCHAR2(40),
      instance_name      VARCHAR2(100),
      text_st            LONG,
      if_correct         VARCHAR2(40),
      etl_sige           VARCHAR2(40),
      daylog             DATE,
      branchid           VARCHAR2(40),
      starttime0         DATE,
      starttime1         VARCHAR2(40),
      starttime2         VARCHAR2(40),
      starttime3         VARCHAR2(40),
      starttime4         DATE,
      starttime5         DATE,
      endtime            DATE,
      total              NUMBER,
      data_no_num        NUMBER,
      fail_record_num    NUMBER,
      fail_data_no_num   NUMBER,
      update_data_no_num NUMBER,
      db_table_name      VARCHAR2(200),
      id                 NUMBER,
      type_fage          NUMBER
    )
    tablespace TBS_URS_SERVICE
      pctfree 10
      initrans 1
      maxtrans 255
      storage
      (
        initial 64K
        next 1M
        minextents 1
        maxextents unlimited
      );
    -- Add comments to the columns 
    comment on column T_SP_SQL_RESULT.project_id
      is '项目编号';
    comment on column T_SP_SQL_RESULT.select_id
      is '批示号';
    comment on column T_SP_SQL_RESULT.data_from
      is '数据来源 v8 ,万能,短险';
    comment on column T_SP_SQL_RESULT.instance_name
      is '实例';
    comment on column T_SP_SQL_RESULT.text_st
      is 'sql 文本';
    comment on column T_SP_SQL_RESULT.if_correct
      is '是否正确';
    comment on column T_SP_SQL_RESULT.etl_sige
      is 'etl 状态,0初始待,1mssql运行中,2mssql 运行同步完,3msqll推送完成,4oracle 处理中,6完成,9失败';
    comment on column T_SP_SQL_RESULT.daylog
      is '项目批示记录数更新时间';
    comment on column T_SP_SQL_RESULT.branchid
      is '机构号';
    comment on column T_SP_SQL_RESULT.starttime0
      is '0初始待时间';
    comment on column T_SP_SQL_RESULT.starttime1
      is '1mssql运行中时间,mssql端更新';
    comment on column T_SP_SQL_RESULT.starttime2
      is '2mssql 运行同步完时间,mssql端更新';
    comment on column T_SP_SQL_RESULT.starttime3
      is '3msqll推送完成时间,mssql端更新';
    comment on column T_SP_SQL_RESULT.starttime4
      is '4oracle 处理开始处理时间';
    comment on column T_SP_SQL_RESULT.endtime
      is '结束时间';
    comment on column T_SP_SQL_RESULT.total
      is '项目批示记录数';
    comment on column T_SP_SQL_RESULT.data_no_num
      is '项目批示记录数,按保单号去重汇总';
    comment on column T_SP_SQL_RESULT.fail_record_num
      is '失败总记录数';
    comment on column T_SP_SQL_RESULT.fail_data_no_num
      is '失败保单记录数';
    comment on column T_SP_SQL_RESULT.update_data_no_num
      is '更新量';
    comment on column T_SP_SQL_RESULT.db_table_name
      is '中间表(orace及mssql)';
    comment on column T_SP_SQL_RESULT.id
      is '编号';
    comment on column T_SP_SQL_RESULT.type_fage
      is '类型,0为字段,1为手段';