tabelle1:Compile Fehler in SQL-Prozedur
id_client | XY
--------------
01 | str1
02 | str2
03 | str1
table2:
id_client | id_something
-------------------
02 | 32
02 | 48
01 | 32
table3:
id_something | name
--------------------
48 | john
32 | george
Ich möchte ein Verfahren schreiben, die als eine der XY
von table1 Werte annimmt ein Argument und gibt die name
aus Tabelle3 der am häufigsten aufgetretenen id_something
i n Tabelle2. Ich habe diesen Code:
CREATE or REPLACE PROCEDURE myprocedure(XYvalue in VARCHAR2(100))
is
cursor countsCursor is select id_something, count(*) count
from table1 join table2 using (id_client)
WHERE XY=XYvalue
group by id_something;
cnt countsCursor%ROWTYPE;
max NUMBER;
idMax table2.id_something%TYPE;
maxName table3.name%TYPE;
BEGIN
max := 0;
open countsCursor;
loop
fetch countsCursor into cnt;
exit when countsCursor%NOTFOUND;
IF (cnt.count > max) THEN
max := cnt.count;
idMax := cnt.id_something;
END IF;
END loop;
select name into maxName from table3 where id_something = idMax;
if (max = 0) THEN
dbms_output.put_line('No id found');
else
dbms_output.put_line('Most occured is ' || maxName || ', with count: ' || max || '.');
END;
/
Und das ist der Fehler, der ein bekam und kann nicht herausfinden, was das Problem ist:
1/59 PLS-00103: Encountered the symbol "(" when expecting one of the following:
:= .) , @ % default character
The symbol ":=" was substituted for "(" to continue.
3/71 PLS-00103: Encountered the symbol "JOIN" when expecting one of the following:
, ; for group having intersect minus order start union where
connect
ich hoffe, Sie verstehen, was ich zu erklären versuchen.
Danke, ich habe 'count' nicht in meinem Code verwendet, es war nur als Erklärung, ich habe auch' VARCHAR2' ohne maximale Länge versucht, aber ich habe 'max' als Variablennamen verwendet und das war das Problem, es funktioniert jetzt gut. –