I've found this code for solving a sudoku:

http://technology.amis.ns/2007/06/05...-model-clause/
(you have to use nl, not ns, but putting nl in the link resulted in it being replaced with four asterisks for some reason).

and now I'd like to use it in a function that I can then call with a string. Since I need to see the result, my function returns a table of a type I've created myself with these two scripts:

Code:
create or replace type tab is object
(
sol varchar(81)
)
/
Code:
create or replace type tabel as table of tab
/
I created a function with the necessary parameters and returns and then pasted in the code. This gave some errors which I've consequently tried to fix, but I am stuck with two syntax errors and with my limited knowledge of Oracle, I'm not able to fix them, so I hope I can get some help from in here to make this function work. The function code is as follows:

Code:
create or replace function function1(s in varchar(81)) return tabel as 
vtab tabel;
begin

select substr( s, ( rownum - 1 ) * 9 + 1, 9 ) sudoku
bulk collect into vtab
from ( select x, s
from ( select s
       from dual
     )
  model
    reference xxx on 
      ( select i, j, r
        from dual
        model
          dimension by ( 1 i, 1 j )
          measures ( 1 x, 1 y, 1 r )
          rules
            ( x[for i from 1 to 81 increment 1, 1] = trunc( ( cv(i) - 1 ) / 9 ) * 9
            , y[for i from 1 to 81 increment 1, 1] = mod( cv(i) - 1, 9 ) + 1
            , r[for i from 1 to 81 increment 1, for j from 1 to 8 increment 1] = case when x[ cv(i), 1 ] + cv(j) < cv(i)
                                                                                   then x[ cv(i), 1 ] + cv(j)
                                                                                   else x[ cv(i), 1 ] + cv(j) + 1
                                                                                 end
            , r[for i from 1 to 81 increment 1, for j from 9 to 16 increment 1] = case when y[ cv(i), 1 ] + ( cv(j) - 9 ) * 9 < cv(i)
                                                                                    then y[ cv(i), 1 ] + ( cv(j) - 9 ) * 9
                                                                                    else y[ cv(i), 1 ] + ( cv(j) - 8 ) * 9
                                                                                  end
            , r[for i from 1 to 81 increment 1, 17] = case mod( x[ cv(i), 1 ] / 9, 3 )
                                                        when 0 then x[ cv(i), 1 ] + 9  
                                                        when 1 then x[ cv(i), 1 ] - 9  
                                                        when 2 then x[ cv(i), 1 ] - 18  
                                                      end + mod( y[ cv(i), 1 ], 3 ) + trunc( (y[ cv(i), 1 ] - 1) / 3 ) * 3 + 1
            , r[for i from 1 to 81 increment 1, 18] = case mod( x[ cv(i), 1 ] / 9, 3 )
                                                        when 0 then x[ cv(i), 1 ] + 18  
                                                        when 1 then x[ cv(i), 1 ] + 9  
                                                        when 2 then x[ cv(i), 1 ] - 9  
                                                      end + mod( y[ cv(i), 1 ], 3 ) + trunc( (y[ cv(i), 1 ] - 1) / 3 ) * 3 + 1
            , r[for i from 1 to 81 increment 1, 19] = case mod( x[ cv(i), 1 ] / 9, 3 )
                                                        when 0 then x[ cv(i), 1 ] + 9  
                                                        when 1 then x[ cv(i), 1 ] - 9  
                                                        when 2 then x[ cv(i), 1 ] - 18  
                                                      end + mod( y[ cv(i), 1 ] + 1, 3 ) + trunc( (y[ cv(i), 1 ] - 1) / 3 ) * 3 + 1
            , r[for i from 1 to 81 increment 1, 20] = case mod( x[ cv(i), 1 ] / 9, 3 )
                                                        when 0 then x[ cv(i), 1 ] + 18  
                                                        when 1 then x[ cv(i), 1 ] + 9  
                                                        when 2 then x[ cv(i), 1 ] - 9  
                                                      end + mod( y[ cv(i), 1 ] + 1, 3 ) + trunc( (y[ cv(i), 1 ] - 1) / 3 ) * 3 + 1
            )
      ) dimension by ( i, j ) measures ( r )
    main solve 
    dimension by ( 1 x )
    measures ( cast( s as varchar2(81) ) s
             , length( replace( s, ' ' ) ) it
             , 1 m
             , 1 i
             , cast( '' as varchar2(20) ) v
             , 1 j
             )
    rules iterate ( 999999 ) until ( length( replace( s[1], ' ' ) ) >= 81 )
          ( i[ it[1] ] = case 
                           when m[1] = 1 then instr( s[1], ' ' )
                           else i[ cv() ]
                         end
          , v[ it[1] ] = case 
                           when m[1] = 1 then
                             translate( '123456789'
                                , '#' || 
                                  substr( s[1], xxx.r[ i[cv()], 1], 1 ) ||
                                  substr( s[1], xxx.r[ i[cv()], 2], 1 ) ||
                                  substr( s[1], xxx.r[ i[cv()], 3], 1 ) ||
                                  substr( s[1], xxx.r[ i[cv()], 4], 1 ) ||
                                  substr( s[1], xxx.r[ i[cv()], 5], 1 ) ||
                                  substr( s[1], xxx.r[ i[cv()], 6], 1 ) ||
                                  substr( s[1], xxx.r[ i[cv()], 7], 1 ) ||
                                  substr( s[1], xxx.r[ i[cv()], 8], 1 ) ||
                                  substr( s[1], xxx.r[ i[cv()], 9], 1 ) ||
                                  substr( s[1], xxx.r[ i[cv()],10], 1 ) ||
                                  substr( s[1], xxx.r[ i[cv()],11], 1 ) ||
                                  substr( s[1], xxx.r[ i[cv()],12], 1 ) ||
                                  substr( s[1], xxx.r[ i[cv()],13], 1 ) ||
                                  substr( s[1], xxx.r[ i[cv()],14], 1 ) ||
                                  substr( s[1], xxx.r[ i[cv()],15], 1 ) ||
                                  substr( s[1], xxx.r[ i[cv()],16], 1 ) ||
                                  substr( s[1], xxx.r[ i[cv()],17], 1 ) ||
                                  substr( s[1], xxx.r[ i[cv()],18], 1 ) ||
                                  substr( s[1], xxx.r[ i[cv()],19], 1 ) ||
                                  substr( s[1], xxx.r[ i[cv()],20], 1 )
                                , '#' )
                           else v[ cv() ]
                         end
          , m[1] = nvl2( v[ it[1] ], m[1], 0 )  
          , it[1] = case 
                      when m[1] = 1 then it[1]
                      else it[1] - 1
                    end 
          , j[ it[1] ] = case 
                           when m[1] = 1 then 1
                           else j[ cv() ] + 1
                         end 
          , m[1] = case
                        when length( v[ it[1] ] ) >= j[ it[1] ] then 1
                        else m[1]
                      end  
          , s[1] = case 
                      when m[1] = 1 then substr( s[1], 1, i[ it[1] ] - 1 ) || substr( v[ it[1] ], j[ it[1] ], 1 ) || substr( s[1], i[ it[1] ] + 1 )
                      else substr( s[1], 1, i[ it[1] ] - 1 ) || ' ' || substr( s[1], i[ it[1] ] + 1 )
                   end  
          , it[1] = case 
                      when m[1] = 1 then it[1] + 1
                      else it[1]
                    end 
          )
)
where x = 1 
connect by rownum < 10
/
return vtab;
end function1;
And the errors I get are:

Code:
Error(1,32): PLS-00103: Encountered the symbol "(" when expecting one of the following:     := . ) , @ % default character The symbol ":=" was substituted for "(" to continue. 
Error(12,5): PLS-00103: Encountered the symbol "REFERENCE" when expecting one of the following:     ) , with group having intersect minus order start union where    connect