well, you are passing in a string
'fuzzy((MANAGER),,,w)'
when you meant perhaps to pass in
fuzzy((MANAGER),,,w)
(no quotes)
ops$tkyte@ORA9IR2> create table emp as select * from scott.emp;
Table created.
ops$tkyte@ORA9IR2>
ops$tkyte@ORA9IR2> create index myindex on emp(job) indextype is ctxsys.context;
Index created.
ops$tkyte@ORA9IR2>
ops$tkyte@ORA9IR2> CREATE OR REPLACE PROCEDURE get_emps
2 IS
3 CURSOR c_emps IS
4 SELECT deptno, ename, empno, job, sal
5 FROM emp
6 ORDER BY deptno, ename;
7 v_count NUMBER;
8 BEGIN
9 FOR v_rec IN c_emps
10 LOOP
11 select Count(*) cnt INTO v_count
12 from emp
13 WHERE deptno = v_rec.deptno
14 AND empno <> v_rec.empno
15 AND contains (job, 'fuzzy(('||v_rec.job||'),,,w)', 1) > 0;
16 Dbms_Output.put_line(v_rec.deptno||' '||v_rec.ename||' '||v_count);
17 END LOOP;
18 END;
19 /
Procedure created.
ops$tkyte@ORA9IR2>
ops$tkyte@ORA9IR2> exec get_emps
10 CLARK 0
10 KING 0
10 MILLER 0
20 ADAMS 1
20 FORD 1
20 JONES 0
20 SCOTT 1
20 Smith 1
30 Allen 3
30 BLAKE 0
30 JAMES 0
30 MARTIN 3
30 TURNER 3
30 WARD 3
PL/SQL procedure successfully completed.
<b>although I'd rather see you use a scalar subquery --as the database will cache scalar subquery results nicely -- that query will not be run for every record necessarily, just when deptno/job changes....</b>
ops$tkyte@ORA9IR2>
ops$tkyte@ORA9IR2> select deptno, ename, empno, job, sal,
2 (select count(*)-1
3 from emp e2
4 where deptno = e1.deptno
5 and contains( job, 'fuzzy(('||e1.JOB||'),,,w)' ) > 0 ) cnt
6 from emp e1
7 order by deptno, ename;
DEPTNO ENAME EMPNO JOB SAL CNT
---------- ---------- ---------- --------- ---------- ----------
10 CLARK 7782 MANAGER 2450 0
10 KING 7839 PRESIDENT 5000 0
10 MILLER 7934 CLERK 1300 0
20 ADAMS 7876 CLERK 1100 1
20 FORD 7902 ANALYST 3000 1
20 JONES 7566 MANAGER 2975 0
20 SCOTT 7788 ANALYST 3000 1
20 Smith 7369 CLERK 800 1
30 Allen 7499 SALESMAN 1600 3
30 BLAKE 7698 MANAGER 2850 0
30 JAMES 7900 CLERK 950 0
30 MARTIN 7654 SALESMAN 1250 3
30 TURNER 7844 SALESMAN 1500 3
30 WARD 7521 SALESMAN 1250 3
14 rows selected.