begin;

create table tfoo (cod_cta text, des_cta text);

INSERT INTO tfoo VALUES ('11010101', 	  'BILLETES Y MONEDAS');
INSERT INTO tfoo VALUES ('11010101000000', 'CAJA OF PRINCIPAL');
INSERT INTO tfoo VALUES ('110102', 		  'AGENCIAS');
INSERT INTO tfoo VALUES ('11010201000001', 'CAJA AG.01 MOSHOQUEQUE');
INSERT INTO tfoo VALUES ('11010201000002', 'CAJA AG.02 JAEN');
INSERT INTO tfoo VALUES ('110109',		  'EFECTIVO EN TRANSITO');
INSERT INTO tfoo VALUES ('11010901',		  'BILLETES Y MONEDAS');
INSERT INTO tfoo VALUES ('11010901000000', 'EFECTIVO EN TRANSITO');
INSERT INTO tfoo VALUES ('1118030602',	  'CUENTAS DE AHORROS');
INSERT INTO tfoo VALUES ('11180306020001', 'INTERES-AHORROS');
INSERT INTO tfoo VALUES ('1118030603',	  'CUENTAS A PLAZO');
INSERT INTO tfoo VALUES ('11180306030001', 'INTERES DEPOS PZO-CONTINENTAL');
INSERT INTO tfoo VALUES ('11180309', 	  'BCO FINANCIERO DEL PERU');
INSERT INTO tfoo VALUES ('1118030903',	  'DEPOS A PZO-BCO FINANCIERO');

select count(*) from tfoo where length(cod_cta) = 8;

create view vfoo as select * from tfoo where length(cod_cta) = 8;
create rule rul_insert as on update to vfoo 
       do instead update tfoo set cod_cta = new.cod_cta,
	                              des_cta = new.cod_cta;

declare foo scroll cursor for select * from vfoo;

fetch foo;
update vfoo set des_cta = des_cta || ' - prueba' where current of foo;
fetch prior from foo;

rollback;
