-- Create table create table T_DATOS ( CADENA VARCHAR2(2500) ) tablespace USERS pctfree 10 initrans 1 maxtrans 255 storage ( initial 64K minextents 1 maxextents unlimited ); ------------------- -- Create table create table T_PUNTOS ( USUARIO VARCHAR2(20) not null, SECUENCIA NUMBER not null, PUNTO NUMBER not null, BPM NUMBER not null, FECHA TIMESTAMP(6) not null, MARCA VARCHAR2(1) ) tablespace USERS pctfree 10 initrans 1 maxtrans 255 storage ( initial 64K minextents 1 maxextents unlimited ); -- Create/Recreate primary, unique and foreign key constraints alter table T_PUNTOS add constraint PK_T_PUNTOS primary key (USUARIO, SECUENCIA) using index tablespace USERS pctfree 10 initrans 2 maxtrans 255 storage ( initial 64K minextents 1 maxextents unlimited ); ----------------------- -- Create table create table T_PUNTOS_HIST ( USUARIO VARCHAR2(20) not null, SECUENCIA NUMBER not null, PUNTO NUMBER not null, BPM NUMBER not null, FECHA TIMESTAMP(6) not null, MARCA VARCHAR2(1) ) tablespace USERS pctfree 10 initrans 1 maxtrans 255 storage ( initial 64K minextents 1 maxextents unlimited ); -- Create/Recreate primary, unique and foreign key constraints alter table T_PUNTOS_HIST add constraint PK_T_PUNTOS_HIST primary key (USUARIO, SECUENCIA) using index tablespace USERS pctfree 10 initrans 2 maxtrans 255 storage ( initial 64K minextents 1 maxextents unlimited ); ---------------------- -- Create table create table T_USUARIO ( CODIGO VARCHAR2(200) not null, PACIENTE VARCHAR2(200), EDAD NUMBER, SEXO VARCHAR2(1), ESTATURA NUMBER, PESO NUMBER ) tablespace USERS pctfree 10 initrans 1 maxtrans 255 storage ( initial 64K minextents 1 maxextents unlimited ); -- Create/Recreate primary, unique and foreign key constraints alter table T_USUARIO add constraint PK_TUSUARIO primary key (CODIGO) using index tablespace USERS pctfree 10 initrans 2 maxtrans 255 storage ( initial 64K minextents 1 maxextents unlimited ); ---------------------- -- Create sequence create sequence SEQ_PUNTOS minvalue 1 maxvalue 9999999999 start with 649261 increment by 1 cache 20; ----------------------- -- Create sequence create sequence SEQ_PUNTOS_HIST minvalue 1 maxvalue 9999999999 start with 649261 increment by 1 cache 20; ---------------------- create or replace procedure prueba(cadena varchar2) is PRAGMA AUTONOMOUS_TRANSACTION; puntos varchar2(2500); cadena_new varchar2(2500); longitud number; punto varchar2(5); bandera varchar2(3); codigo t_usuario.codigo%type; paciente t_usuario.paciente%type; edad t_usuario.edad%type; sexo t_usuario.sexo%type; estatura t_usuario.estatura%type; peso t_usuario.peso%type; begin puntos:= cadena; longitud:= length(puntos); bandera:= substr(puntos,2,1); cadena_new:= substr(puntos,4,longitud); delete t_puntos; delete t_usuario; commit; if bandera='N' then loop punto := substr(cadena_new,1,instr(cadena_new,'|',1)-1); insert into t_puntos values ('cvramire',seq_puntos.nextval,to_number(punto),10,systimestamp,null); insert into t_puntos_hist values ('cvramire',seq_puntos_hist.nextval,to_number(punto),10,systimestamp,null); longitud:= length(cadena_new); cadena_new:= substr(cadena_new,instr(cadena_new,'|',1)+1,longitud); exit when instr(cadena_new,'|',1)=0; end loop; insert into t_puntos values ('cvramire',seq_puntos.nextval,to_number(cadena_new),10,systimestamp,null); insert into t_puntos_hist values ('cvramire',seq_puntos_hist.nextval,to_number(cadena_new),10,systimestamp,null); commit; else codigo := substr(cadena_new,1,instr(cadena_new,'|',1)-1); longitud:= length(cadena_new); cadena_new:= substr(cadena_new,instr(cadena_new,'|',1)+1,longitud); paciente:= substr(cadena_new,1,instr(cadena_new,'|',1)-1); longitud:= length(cadena_new); cadena_new:= substr(cadena_new,instr(cadena_new,'|',1)+1,longitud); edad := to_number(substr(cadena_new,1,instr(cadena_new,'|',1)-1)); longitud:= length(cadena_new); cadena_new:= substr(cadena_new,instr(cadena_new,'|',1)+1,longitud); sexo:= substr(cadena_new,1,instr(cadena_new,'|',1)-1); longitud:= length(cadena_new); cadena_new:= substr(cadena_new,instr(cadena_new,'|',1)+1,longitud); estatura := to_number(substr(cadena_new,1,instr(cadena_new,'|',1)-1)); longitud:= length(cadena_new); cadena_new:= substr(cadena_new,instr(cadena_new,'|',1)+1,longitud); peso:= to_number(cadena_new); insert into t_usuario values (codigo,paciente,edad,sexo,estatura,peso); commit; end if; exception when others then rollback; end prueba; ----------------------------------- create or replace trigger trig_datos after insert on t_datos for each row declare begin prueba(:new.cadena); end trig_datos;