text: CREATE TABLE  "MM_USUARIOS" 
     (	"ID" NUMBER GENERATED BY DEFAULT ON NULL AS IDENTITY MINVALUE 1 MAXVALUE 9999999999999999999999999999 INCREMENT BY 1 START WITH 1 CACHE 20 NOORDER  NOCYCLE  NOKEEP  NOSCALE  NOT NULL ENABLE, 
  	"NICK" VARCHAR2(50 CHAR) NOT NULL ENABLE, 
  	"NOMBRE" VARCHAR2(100 CHAR), 
  	"APELLIDO" VARCHAR2(100 CHAR), 
  	"PASS" VARCHAR2(100 CHAR), 
  	"CREATED" TIMESTAMP (6) WITH LOCAL TIME ZONE NOT NULL ENABLE, 
  	"CREATED_BY" VARCHAR2(255 CHAR) NOT NULL ENABLE, 
  	"UPDATED" TIMESTAMP (6) WITH LOCAL TIME ZONE NOT NULL ENABLE, 
  	"UPDATED_BY" VARCHAR2(255 CHAR) NOT NULL ENABLE, 
  	 CONSTRAINT "MM_USUARIOS_ID_PK" PRIMARY KEY ("ID")
    USING INDEX  ENABLE
     )
  /
  CREATE TABLE  "MM_MOVIMIENTOS" 
     (	"ID" NUMBER GENERATED BY DEFAULT ON NULL AS IDENTITY MINVALUE 1 MAXVALUE 9999999999999999999999999999 INCREMENT BY 1 START WITH 1 CACHE 20 NOORDER  NOCYCLE  NOKEEP  NOSCALE  NOT NULL ENABLE, 
  	"USUARIO_ID" NUMBER, 
  	"DESCRIPCION" VARCHAR2(255 CHAR) NOT NULL ENABLE, 
  	"CREATED" TIMESTAMP (6) WITH LOCAL TIME ZONE NOT NULL ENABLE, 
  	"CREATED_BY" VARCHAR2(255 CHAR) NOT NULL ENABLE, 
  	"UPDATED" TIMESTAMP (6) WITH LOCAL TIME ZONE NOT NULL ENABLE, 
  	"UPDATED_BY" VARCHAR2(255 CHAR) NOT NULL ENABLE, 
  	 CONSTRAINT "MM_MOVIMIENTOS_ID_PK" PRIMARY KEY ("ID")
    USING INDEX  ENABLE
     )
  /
  CREATE TABLE  "MM_TIPOS_MOVIMIENTOS" 
     (	"ID" NUMBER GENERATED BY DEFAULT ON NULL AS IDENTITY MINVALUE 1 MAXVALUE 9999999999999999999999999999 INCREMENT BY 1 START WITH 1 CACHE 20 NOORDER  NOCYCLE  NOKEEP  NOSCALE  NOT NULL ENABLE, 
  	"DESCRIPCION" VARCHAR2(50 CHAR), 
  	"CREATED" TIMESTAMP (6) WITH LOCAL TIME ZONE NOT NULL ENABLE, 
  	"CREATED_BY" VARCHAR2(255 CHAR) NOT NULL ENABLE, 
  	"UPDATED" TIMESTAMP (6) WITH LOCAL TIME ZONE NOT NULL ENABLE, 
  	"UPDATED_BY" VARCHAR2(255 CHAR) NOT NULL ENABLE, 
  	 CONSTRAINT "MM_TIPOS_MOVIMIENT_ID_PK" PRIMARY KEY ("ID")
    USING INDEX  ENABLE, 
  	 CONSTRAINT "MM_TIPOS_MOVIMI_DESCRIPCIO_UNQ" UNIQUE ("DESCRIPCION")
    USING INDEX  ENABLE
     )
  /
  CREATE TABLE  "MM_USUARIOS_MOVIMIENTOS" 
     (	"ID" NUMBER NOT NULL ENABLE, 
  	"USUARIO_ID" NUMBER NOT NULL ENABLE, 
  	"MOVIMIENTO_ID" NUMBER NOT NULL ENABLE, 
  	"TIPO_MOVIMIENTO_ID" NUMBER NOT NULL ENABLE, 
  	"FECHA" DATE NOT NULL ENABLE, 
  	"MONTO" NUMBER(18,2) NOT NULL ENABLE, 
  	"PAGADO" VARCHAR2(2) NOT NULL ENABLE, 
  	"OBS" VARCHAR2(255), 
  	"REGISTRADO" TIMESTAMP (6) WITH LOCAL TIME ZONE NOT NULL ENABLE, 
  	"CANTIDAD" NUMBER NOT NULL ENABLE, 
  	 CONSTRAINT "MM_USUARIOS_MOVIMIENTOS_PK" PRIMARY KEY ("ID")
    USING INDEX  ENABLE
     )
  /
  ALTER TABLE  "MM_MOVIMIENTOS" ADD CONSTRAINT "MM_MOVIMIENTOS_USUARIO_ID_FK" FOREIGN KEY ("USUARIO_ID")
  	  REFERENCES  "MM_USUARIOS" ("ID") ON DELETE CASCADE ENABLE
  /
  ALTER TABLE  "MM_USUARIOS_MOVIMIENTOS" ADD CONSTRAINT "MM_USU_MOV_MOVIMIENTO_FK" FOREIGN KEY ("MOVIMIENTO_ID")
  	  REFERENCES  "MM_MOVIMIENTOS" ("ID") ENABLE
  /
  ALTER TABLE  "MM_USUARIOS_MOVIMIENTOS" ADD CONSTRAINT "MM_USU_MOV_TIPO_MOV_FK" FOREIGN KEY ("TIPO_MOVIMIENTO_ID")
  	  REFERENCES  "MM_TIPOS_MOVIMIENTOS" ("ID") ENABLE
  /
  ALTER TABLE  "MM_USUARIOS_MOVIMIENTOS" ADD CONSTRAINT "MM_USU_MOV_USUARIO_FK" FOREIGN KEY ("USUARIO_ID")
  	  REFERENCES  "MM_USUARIOS" ("ID") ENABLE
  /
  CREATE OR REPLACE EDITIONABLE FUNCTION  "MM_AUTHENTICATE_USER" 
    (p_username in varchar2, 
     p_password in varchar2)
  return boolean is
  l_c number;
  begin
    select distinct 1 into l_c
    from mm_usuarios
    where trim(upper(nick)) = trim(upper(p_username))
    and pass = p_password;
    return true;
  exception
    when no_Data_found then
    return false;
  end;
  /
  
  CREATE OR REPLACE EDITIONABLE FUNCTION  "MM_GET_USER_ID" (
          in_user in varchar2
      )return number is
        l_id number;
      begin
        select u.id
        into l_id
        from mm_usuarios u
        where u.nick = in_user;
        return l_id;
      exception
        when no_Data_found then
          return 0;
      end mm_get_user_id;
  /
  
  CREATE INDEX  "MM_MOVIMIENTOS_I1" ON  "MM_MOVIMIENTOS" ("USUARIO_ID")
  /
  CREATE OR REPLACE EDITIONABLE PACKAGE  "PAQ_MM" is
  co_ingreso constant number := 1;
  co_egreso  constant number := 2;
  co_first_name   constant varchar2(1) := 'N';
  co_last_name    constant varchar2(1) := 'A';
   
  function ingreso return number;
  function egreso  return number;
  
  procedure add_mov(
      in_user_id number,
      in_mov_id  number,
      in_tipo_id number,
      in_cant    number,
      in_fecha   date,
      in_total   number,
      in_pagado  varchar2,
      in_obs     varchar2
  );
  
  function get_data_user_str(
      in_user varchar2,
      in_dato varchar2 -- N || A (Nombre o Apellido)
  )return varchar2;
  
  end paq_mm;
  /
  CREATE OR REPLACE EDITIONABLE PACKAGE BODY  "PAQ_MM" is
  function ingreso return number is
  begin
    return co_ingreso;
  end ingreso;
  function egreso return number is
  begin
    return co_egreso;
  end egreso;
  
  procedure add_mov(
      in_user_id number,
      in_mov_id  number,
      in_tipo_id number,
      in_cant    number,
      in_fecha   date,
      in_total   number,
      in_pagado  varchar2,
      in_obs     varchar2
  )as
  begin
    if nvl(in_cant, 0) <= 0 then
      raise_application_Error(-20000, 'Complete la cantidad con un número superior a 0');
    end if;
  
    if in_mov_id is null then
      raise_application_Error(-20000, 'Seleccione un movimiento');
    end if;
  
    if in_fecha is null then
      raise_application_Error(-20000, 'Complete la fecha');
    end if;
  
    if in_total is null then
      raise_application_Error(-20000, 'Complete el total del movimiento');
    end if;
  
    insert into MM_USUARIOS_MOVIMIENTOS(USUARIO_ID, MOVIMIENTO_ID, TIPO_MOVIMIENTO_ID, FECHA, CANTIDAD, MONTO, PAGADO, OBS, REGISTRADO)
    values(in_user_id, in_mov_id, in_tipo_id, in_fecha, in_cant, in_total, in_pagado, in_obs, current_timestamp);
  
  end add_mov;
  
  function get_data_user_str(
      in_user varchar2,
      in_dato varchar2 -- N || A (Nombre o Apellido)
  )return varchar2 is
  l_data varchar2(2500);
  begin
    select case when in_dato = co_first_name then u.nombre else u.apellido end
    into l_data
    from mm_usuarios u
    where u.nick = in_user;
    
    return l_data;
  exception
    when no_Data_found then
      return 'Usuario no identificado';
  end get_data_user_str;
  
  end paq_mm;
  /
  
   CREATE SEQUENCE   "MM_USUARIOS_MOVIMIENTOS_SEQ"  MINVALUE 1 MAXVALUE 9999999999999999999999999999 INCREMENT BY 1 START WITH 441 CACHE 20 NOORDER  NOCYCLE  NOKEEP  NOSCALE  GLOBAL
  /
  CREATE OR REPLACE EDITIONABLE TRIGGER  "BI_MM_USUARIOS_MOVIMIENTOS" 
    before insert or update on "MM_USUARIOS_MOVIMIENTOS"               
    for each row  
  begin   
    if inserting and :NEW."ID" is null then 
      select "MM_USUARIOS_MOVIMIENTOS_SEQ".nextval into :NEW."ID" from sys.dual; 
    end if;
  
    :new.registrado := current_timestamp;
  end; 
  
  /
  ALTER TRIGGER  "BI_MM_USUARIOS_MOVIMIENTOS" ENABLE
  /
  CREATE OR REPLACE EDITIONABLE TRIGGER  "MM_MOVIMIENTOS_BIU" 
      before insert or update  
      on mm_movimientos 
      for each row 
  begin 
      if inserting then 
          :new.created := localtimestamp; 
          :new.created_by := coalesce(sys_context('APEX$SESSION','APP_USER'),user); 
      end if; 
      :new.updated := localtimestamp; 
      :new.updated_by := coalesce(sys_context('APEX$SESSION','APP_USER'),user); 
  end mm_movimientos_biu; 
  
  /
  ALTER TRIGGER  "MM_MOVIMIENTOS_BIU" ENABLE
  /
  CREATE OR REPLACE EDITIONABLE TRIGGER  "MM_TIPOS_MOVIMIENTOS_BIU" 
      before insert or update  
      on mm_tipos_movimientos 
      for each row 
  begin 
      if inserting then 
          :new.created := localtimestamp; 
          :new.created_by := coalesce(sys_context('APEX$SESSION','APP_USER'),user); 
      end if; 
      :new.updated := localtimestamp; 
      :new.updated_by := coalesce(sys_context('APEX$SESSION','APP_USER'),user); 
  end mm_tipos_movimientos_biu; 
  
  /
  ALTER TRIGGER  "MM_TIPOS_MOVIMIENTOS_BIU" ENABLE
  /
  CREATE OR REPLACE EDITIONABLE TRIGGER  "MM_USUARIOS_BIU" 
      before insert or update  
      on mm_usuarios 
      for each row 
  begin 
      if inserting then 
          :new.created := localtimestamp; 
          :new.created_by := coalesce(sys_context('APEX$SESSION','APP_USER'),user); 
      end if; 
      :new.updated := localtimestamp; 
      :new.updated_by := coalesce(sys_context('APEX$SESSION','APP_USER'),user); 
  end mm_usuarios_biu; 
  
  /
  ALTER TRIGGER  "MM_USUARIOS_BIU" ENABLE
  /
  