Oracle 建表,递增序列,触发器,分析函数row_number() ,partition by 子句。

create table SC ( Id INTEGER, Name nvarchar2(20) , KC_Name nvarchar2(20), KC_score INTEGER , constraint SC_pk primary key (Id) );

create sequence SC_seq minvalue 1 maxvalue 99999999    increment by 1    start with 1;   

create or replace trigger SC_tri           before insert on SC     /*触发条件:当向表dectuser执行插入操作时触发此触发器*/            for each row                        /*对每一行都检测是否触发*/            begin                                  /*触发器开始*/                  select SC_seq.nextval into :new.Id from dual;   /*触发器主题内容,即触发后执行的动作,在此是取得序列dectuser_tb_seq的下一个值插入到表user_info_T中的id字段中*/           end; /* 提交 */ commit

insert into SC values(null,'张三','语文',80);

insert into SC values(null,'李四','语文',70);

insert into SC values(null,'钟情','语文',75);

insert into SC values(null,'张三','数学',85);

insert into SC values(null,'李四','数学',88);

insert into SC values(null,'钟情','数学',79);

insert into SC values(null,'张三','英语',80);

insert into SC values(null,'李四','英语',55);

select s.kc_name,s.KC_score,row_number() over (partition by s.kc_name order by s.KC_score) rt from SC s
Oracle 建表,递增序列,触发器,分析函数row_number() ,partition by 子句。_第1张图片

你可能感兴趣的:(Oracle 建表,递增序列,触发器,分析函数row_number() ,partition by 子句。)