the format of your select statement is slightly off. It should be:
SELECT col1, col2 ...
INTO var1, var2
FROM table
WHERE ...
Try this:
Main Topics
Browse All TopicsI keep getting an error in the next pl sql function:
No group function allowe here says
This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.
Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.
If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.
Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.
Access the answers to your technology questions today.
30-day free trial. Register in 60 seconds.
Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Try it out and discover for yourself.
30-day free trial. Register in 60 seconds.
Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.
ORA-00904: "%s": invalid identifier.
It's not recognising NOMBRE_CHOFER as a column, I suspect that column name is a quoted identifier.
In SQL*Plus can you issue the command "DESC tchofer"? You should see output similar to the following:
SQL> DESC tchofer
Name ....
-----------
NOMBRE_CHOFER
....
You need to quote the column name in your query, and copy the case as returned by the command above e.g.
"Nombre_chofer"
>>this should return the name of the "chofer" with most "pasajeros" witht the given conditions...
angelIII is correct, your query will NOT give the right answer. In order to get the result you want, you should try either angelIII's solution (http:#24745780) or my solution (http:#24745784).
CREATE OR REPLACE FUNCTION chofer(horarioini IN NUMBER, horariofin IN INTEGER)
RETURN VARCHAR2
AS
v_nombre VARCHAR2(32);
v_cuenta NUMBER;
BEGIN
SELECT d.nombre_chofer
INTO v_nombre
FROM (SELECT tchofer.nombre_chofer,
COUNT(tcliente.cod_cliente
FROM tchofer,
tconduce,
testa_constituida,
tviaja,
tcliente,
tlineahorario
WHERE tchofer.cod_chofer = tconduce.cod_chofer
AND tconduce.cod_bus = testa_constituida.cod_bus
AND tviaja.cod_linea = testa_constituida.cod_line
AND tviaja.cod_cliente = tcliente.cod_cliente
AND tlineahorario.cod_linea = testa_constituida.cod_line
AND tcliente.movilidad_reducid
AND tlineahorario.horario BETWEEN horarioini AND horariofin
GROUP BY tchofer.nombre_chofer
ORDER BY pasajeros DESC) d
WHERE ROWNUM = 1;
RETURN v_nombre;
EXCEPTION
WHEN NO_DATA_FOUND
THEN
RETURN NULL;
END chofer;
hello axtur:
1 . tu necesitas una funcion que te traiga el nombre del chofer, dandole solo el horario de inicio y fin.
2. necesitas modificar tu consulta:
- el error te lo marca porque tienes un count y no tienes un group by.
select tchofer.nombre_chofer, count(tcliente.cod_cliente
INTO v_nombre, v_cuenta
FROM tchofer, tconduce, testa_constituida, tviaja, tcliente, tlineahorario
where tchofer.cod_chofer = tconduce.cod_chofer
AND tconduce.cod_bus = testa_constituida.cod_bus
AND tviaja.cod_linea = testa_constituida.cod_line
AND tviaja.cod_cliente = tcliente.cod_cliente
AND tlineahorario.cod_linea = testa_constituida.cod_line
AND tcliente.movilidad_reducid
AND tlineahorario.horario between horarioini and horariofin
group by tchofer.nombre_chofer
// tambien puedes consultarme en joaquin_ma hotmail
preguntas:
1. creo que no necesitas la tabla de clientes para esta consulta.
2. es interesante ver que este querie te puede traer mas de un registro porque puedes tener 2 choferes con los mismos horarios. creo que aqui tienes un problema de la definicion del problema.
Business Accounts
Answer for Membership
by: angelIIIPosted on 2009-06-30 at 07:25:23ID: 24745622
>select tchofer.nombre_chofer into v_nombre, count(tcliente.cod_cliente )as pasajero
a function can only return 1 single value, not a complete rowset
please clarify what the function should actually do?