Re: Query in 10g

  • From: "Norman Dunbar" <norman.dunbar@xxxxxxxxxxxxxxxxxxxxxxxxx>
  • To: <oracle-l@xxxxxxxxxxxxx>
  • Date: Wed, 08 Nov 2006 16:27:18 +0000

OK, 

apologies for my Spanish first of all. (Nombre)


Now then, you are using varchars to hold numbers in some columns. I
would expect that you either have a NULL in at least one row in one of
those columns - which normally wouldn't be a problem, and/or you have a
non-numeric character in one or more rows.

Going back to your original query :

select ACUM_PERIODO,con_nombre, ACUM_UNIDADES || ' ' || DESC_UNIDAD
desc_unidad, pec_saldo_valor, acum_valor_local from
VRH_PRO_ACU_COL_PAG
WHERE emp_codigo = 43103973 and ACUM_ANO = 2006 and acum_mes=9

It looks to me like the only place you have an implicit conversion
using TO_NUMBER is here :

WHERE emp_codigo = 43103973

Oracle takes the column's data type (varchar2) and converts it to the
data type on the right side of the comparison operator. So emp_codigo is
effectively TO_NUMBER(emp_codigo) in this WHERE clause. The fact that
you are having an error implies that you must have something in that
column that is not a number.

To test, try this :

SELECT TO_NUMBER(emp_codigo) 
FROM VRH_PRO_ACU_COL_PAG;

If you get a similar error you have a problem in tha data there. All
the other comparisons in your WHERE clause are comparing numbers with
numbers - so that is ok.

If you do get the error then we can find out which row it is in by the
folowing :

set serverout on size 1000000
begin
for x in (select emp_codigo from VRH_PRO_ACU_COL_PAG) loop
  begin
    if (translate(x.emp_codigo, '0123456789','0000000000') = 0) then
      null;
    end if;
  exception
    when value_error then
      dbms_output.put_line('Error at <<' || x.emp_codigo || '>>');
  end;
end loop;
end;
/

If you see a message then the bits between << and >> are the failing
non-numeric characters.



Cheers,
Norman.


Norman Dunbar.
Contract Oracle DBA.
Rivers House, Leeds.

Internal : 7 28 2051
External : 0113 231 2051


Information in this message may be confidential and may be legally privileged. 
If you have received this message by mistake, please notify the sender 
immediately, delete it and do not copy it to anyone else.

We have checked this email and its attachments for viruses. But you should 
still check any attachment before opening it.

We may have to make this message and any reply to it public if asked to under 
the Freedom of Information Act, Data Protection Act or for litigation.  Email 
messages and attachments sent to or from any Environment Agency address may 
also be accessed by someone other than the sender or recipient, for business 
purposes.

If we have sent you information and you wish to use it please read our terms 
and conditions which you can get by calling us on 08708 506 506.  Find out more 
about the Environment Agency at www.environment-agency.gov.uk
--
//www.freelists.org/webpage/oracle-l


Other related posts: