jueves, 31 de marzo de 2011

ORA-01403: no data found ,ORA-23494: too many rows for destination and Select Into

ORA-01403:    no data found
Cause: In a host language program, all records have been fetched. The return code from the fetch was +4, indicating that all records have been returned from the SQL query.

Action: Terminate processing for the SELECT statement.

ORA-23494: too many rows for destination "string"
Causa: The specified destination has too many rows
Acción: Ensure the specified destination has at most two valid rows before retrying this operation.

Esto es lo que encuentras al buscar este error.

no data found, Como olvidar este error, y aqui te presento a uno  de los principales culpables:

Select datos
Into variables
from tabla

Dentro de las mas grandes bendiciones/maldiciones que existen en pl/sql esta esta bendita/maldita sentencia, porque se preguntaran?, bueno pues resulta de que cuando te enseñan esta sentencia, debería venir de la mano con un  manual de por que deberías evitar utilizarla, a que me refiero:

Cuando tu utilizas la sentencia select into , significa que de manera directa deseamos obtener información de la base y que nos la deposite dentro de variables en nuestro código, que utilizado correctamente nos puede ahorrar algunas lineas de código dentro de nuestros procedimientos, sin embargo si no estas absoluta y completamente seguros de que tu consulta siempre regresara uno y solo un registro, en caso de que no estés seguro de lo anterior, tu proceso debería estar preparado para lo peor.

es decir deberia por lo menos agregar el siguiente codigo:

begin
Select datos
Into variables
from tabla
exceptions
when no_data_found then
/*lo que quieras hacer cuando no encuentre datos*/
when too_many_rows
/*lo que quieras hacer cuando encuentre mas de un registro */
end;



Espero este pequeño ejemplo sea útil.

martes, 29 de marzo de 2011

ORA-00904 string: invalid identifier

The column name entered is either missing or invalid.

Enter a valid column name. A valid column name must begin with a letter, be less than or equal to 30 characters, and consist of only alphanumeric characters and the special characters $, _, and #. If it contains other characters, then it must be enclosed in double quotation marks. It may not be a reserved word.

 Este error pasa cuando el compilador no puede encontrar la columna que estas tratando de hacer referencia.

lo que yo hago normalmente es una búsqueda binaria quiere decir:

quito la mitad del codigo y trato de ejecutarlo, si funciona el error estaba en la otra mitad, si no esta en la mitad que me encuentro y quito o agrego la otra mitad hasta identificar el error.

Puede sonar muy tardado pero veanlo de la siguiente manera:

en 1500 lineas de código para un error que esta en la lina 643
lo encontrarías con este proceso  al 10 intento y eso sin conocer el código.

recordemos que el identificar el error no es corregirlo, y sin embargo ayuda.
 

ORA-12154: TNS:could not resolve the connect identifier specified

A connection to a database or other service was requested using a connect identifier, and the connect identifier specified could not be resolved into a connect descriptor using one of the naming methods configured. For example, if the type of connect identifier used was a net service name then the net service name could not be found in a naming method repository, or the repository could not be located or reached.
Action:
- If you are using local naming (TNSNAMES.ORA file):

- Make sure that "TNSNAMES" is listed as one of the values of the NAMES.DIRECTORY_PATH parameter in the Oracle Net profile (SQLNET.ORA)

- Verify that a TNSNAMES.ORA file exists and is in the proper directory and is accessible.

- Check that the net service name used as the connect identifier exists in the TNSNAMES.ORA file.

- Make sure there are no syntax errors anywhere in the TNSNAMES.ORA file. Look for unmatched parentheses or stray characters. Errors in a TNSNAMES.ORA file may make it unusable.

- If you are using directory naming:

- Verify that "LDAP" is listed as one of the values of the NAMES.DIRETORY_PATH parameter in the Oracle Net profile (SQLNET.ORA).

- Verify that the LDAP directory server is up and that it is accessible.

- Verify that the net service name or database name used as the connect identifier is configured in the directory.

- Verify that the default context being used is correct by specifying a fully qualified net service name or a full LDAP DN as the connect identifier

- If you are using easy connect naming:

- Verify that "EZCONNECT" is listed as one of the values of the NAMES.DIRETORY_PATH parameter in the Oracle Net profile (SQLNET.ORA).

- Make sure the host, port and service name specified are correct.

- Try enclosing the connect identifier in quote marks. See the Oracle Net Services Administrators Guide or the Oracle operating system specific guide for more information on naming.

Esto normalmente ocurre cuando me trato de conectar pero estoy utilizando un HOME diferente del que estamos utilizando. para resolverlo normalmente verifico:

1.- Que en el archivo tnsnames en tu HOME esta dado de alta el servicio al que quieres acceder .
2.- Probar por medio de la herramienta tnsping que existe la entrada en el archivo y que esta correctamente configurada, si ejecutas en una terminal : TNSPING de entrada te dice la ruta de tu home por defecto, que eso ya es una ayuda.
3.- asegurarte de que estas usando el home que crees.
4.- lea lo anterior, aunque no tengo el tiempo de traducirlo lo dejo  a su criterio.

ORA-06550:line string, column string:string

A PL/SQL compilation error has occurred. The numbers given for line and column are the location in the PL/SQL block where the error occurred.

Refer to the following PL/SQL messages for more information about the error.

Cada vez que me manda este error un gatito murio, (Últimamente no hay muchos gatitos por donde vivo )
Lo único que puedo recomendar de este error es por favor lee los errores que te dan antes.

Los errores mas comunes que a mi me pasan:

Borro el comando CREATE  cuando estoy editando un procedimiento, olvido mis ;

ORA-01476: divisor is equal to zero

An expression attempted to divide by zero.

Dios dijo alguna vez :

"No mataras y no dividirás entre cero"

Como no debemos pecar no se puede dividir entre cero ya que no esta definido, el día que algún genio matemático defina esta operación, seguramente podremos evitar esto.

Como evitarlo:


en query:


select data/data2 from tab_data


substituir por :


select case when data2 = 0 then 0 else data/data2 end from tab_data


claro esto si es que quieres que el resultado sea 0 o lo que sea colocarlo dentro del case .


ORA-06512: at line

This error message indicates the line number in the PLSQL code that the error resulted.
Este mensaje no te dice el error unicamente te dice en que linea ocurrio el error.


declare
v_number number(2);
begin
  v_number := 1/0;
end;



resultado.
aqui te diria
ORA-06512: at line 4
ORA-01476: divisor is equal to zero

WHATS THIS FOR?

Este blog esta hecho para ahorrarme tiempo en buscar los errores que ya me han sucedido y recordar los ejemplos de como los pude resolver en algún momento. Si a alguien mas le es útil pues que mejor.