SET SERVEROUTPUT ON @

BEGIN
 DECLARE NMBR VARCHAR(100) DEFAULT '1';
 DECLARE J SMALLINT DEFAULT 1;

 CALL DBMS_OUTPUT.PUT_LINE(NMBR);
 WHILE (J < 10) DO
  BEGIN
  DECLARE I SMALLINT;
  DECLARE SIZE SMALLINT;
  DECLARE ACTUAL CHAR(1);
  DECLARE REPEAT CHAR(1);
  DECLARE RESULT VARCHAR(100);
  DECLARE TIMES SMALLINT;

  SET REPEAT = SUBSTR(NMBR, 1, 1);
  SET NMBR = SUBSTR(NMBR, 2) || ' ';
  SET TIMES = 1;
  SET I = 1;
  SET SIZE = LENGTH(NMBR);

  WHILE (I <= SIZE) DO
   SET ACTUAL = SUBSTR(NMBR, I, 1);
   IF (ACTUAL <> REPEAT) THEN
    SET RESULT = COALESCE(RESULT, '') || TIMES || '' || REPEAT;
    SET TIMES = 1;
    SET REPEAT = ACTUAL;
   ELSE
    SET TIMES = TIMES + 1;
   END IF;
   SET I = I + 1;
  END WHILE;

  CALL DBMS_OUTPUT.PUT_LINE(RESULT);
  SET NMBR = RESULT;
  END ;
  SET J = J + 1;
 END WHILE;
END @
