Oracle FAQ Your Portal to the Oracle Knowledge Grid
HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US
 

Home -> Community -> Mailing Lists -> Oracle-L -> Re: Coercion issue

Re: Coercion issue

From: Igor Neyman <ineyman_at_perceptron.com>
Date: Wed, 04 Sep 2002 14:03:23 -0800
Message-ID: <F001.004C7DC5.20020904140323@fatcity.com>


Content-Type: text/plain;
 charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

John,

Oracle will apply both "where" clauses: table_name =3D =
'BUY_PRICE_PIECE_TYPE_HISTORY' and to_number(substr(partition_name,5,2)) =
=3D buy_price_pkg.cnv_bpt_to_bp_id(5)
 to each row at the same time.

If you want to force oracle to do it sequencially (first - table_name, = then - the other one), use in-line view:

SELECT to_number(substr(partition_name,5,2)), = buy_price_pkg.cnv_bpt_to_bp_id(5)
FROM (select partition_name from

        all_tab_partitions
         WHERE  table_name =3D 'BUY_PRICE_PIECE_TYPE_HISTORY'
        and partition_name !=3D 'TYPE01')
WHERE to_number(substr(partition_name,5,2)) =3D = buy_price_pkg.cnv_bpt_to_bp_id(5)

This should do it for you.

Igor Neyman, OCP DBA
ineyman_at_perceptron.com
 =20

  There are partitions with names that don't have the 5th and 6th = characters equal to
  numbers, but not for this table:

  SQL> select partition_name from all_tab_partitions=20

       2 where table_name =3D 'BUY_PRICE_PIECE_TYPE_HISTORY';

  PARTITION_NAME



  TYPE01
  TYPE09
  TYPE10
  TYPE11
  TYPE12   The query should be restricting things to only those partition names = for the one table.
  John P Weatherman=20
  Database Administrator=20
  Replacements Ltd.=20

    -----Original Message-----
    From: Igor Neyman [mailto:ineyman_at_perceptron.com]     Sent: Wednesday, September 04, 2002 1:14 PM     To: Multiple recipients of list ORACLE-L     Subject: Re: Coercion issue

    John,

    Do you have other partitions with such names, that 5th and 6th = characters are not convertible into numbers?

    Like: 'TYPEA1'?

    Igor Neyman, OCP DBA
    ineyman_at_perceptron.com
     =20

      Hi all,

      I'm writing a package to manipulate a partitioned table for the = duhvelopers and have run into

      a weird query that I can't figure out. I can convert a substring = to a number in a select clause,

      but as soon as I try to use that same number in the where clause, = the thing chokes. Has=20

      anyone else seen anything like this?

      I'm on 9.0.1.3, Solaris 8. The buy_price_pkg.cnv_bpt_to_bp_id in = the query is a custom

      function that returns a number corresponding with which partition = is current, old, next,

      etc.

      SQL> SELECT to_number(substr(partition_name,5,2)), = buy_price_pkg.cnv_bpt_to_bp_id(5)

        2  FROM   all_tab_partitions
        3  WHERE  table_name =3D 'BUY_PRICE_PIECE_TYPE_HISTORY'
        4*        and partition_name !=3D 'TYPE01'
      SQL> /

      TO_NUMBER(SUBSTR(PARTITION_NAME,5,2)) =
BUY_PRICE_PKG.CNV_BPT_TO_BP_ID(5)
      ------------------------------------- =
---------------------------------
                                          9                              =
   9
                                         10                              =
   9
                                         11                              =
   9
                                         12                              =
   9

      SQL> SELECT to_number(substr(partition_name,5,2)), = buy_price_pkg.cnv_bpt_to_bp_id(5)

        2  FROM   all_tab_partitions
        3  WHERE  table_name =3D 'BUY_PRICE_PIECE_TYPE_HISTORY'
        4         and partition_name !=3D 'TYPE01'
        5*       and to_number(substr(partition_name,5,2)) =3D =
buy_price_pkg.cnv_bpt_to_bp_id(5)
      SQL> /
            and to_number(substr(partition_name,5,2)) =3D =
buy_price_pkg.cnv_bpt_to_bp_id(5)
                          *
      ERROR at line 5:
      ORA-01722: invalid number

      TIA,
      John P Weatherman=20
      Database Administrator=20
      Replacements Ltd.=20


------=_NextPart_000_0302_01C25435.D9D68630 Content-Type: text/html;
 charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META http-equiv=3DContent-Type content=3D"text/html; =
charset=3Diso-8859-1">
<META content=3D"MSHTML 5.50.4731.2200" name=3DGENERATOR>
<STYLE></STYLE>
</HEAD>
<BODY bgColor=3D#ffffff>
<DIV><FONT size=3D2>John,</FONT></DIV>
<DIV><FONT size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT size=3D2>Oracle will apply both "where" clauses:&nbsp;<FONT=20
color=3D#0000ff>table_name =3D 'BUY_PRICE_PIECE_TYPE_HISTORY' and=20 to_number(substr(partition_name,5,2)) =3D=20 buy_price_pkg.cnv_bpt_to_bp_id(5)</FONT></FONT></DIV>
<DIV><FONT size=3D2>&nbsp;to each row at the same time.</FONT></DIV>
<DIV><FONT size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT size=3D2>If you want to force oracle to do it sequencially =
(first -=20
table_name, then - the other one), use in-line view:</FONT></DIV> <DIV><FONT size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT size=3D2><FONT color=3D#0000ff>SELECT=20 to_number(substr(partition_name,5,2)),=20 buy_price_pkg.cnv_bpt_to_bp_id(5)<BR>FROM&nbsp;&nbsp; (select = partition_name=20
from</FONT></FONT></DIV>
<DIV><FONT size=3D2><FONT color=3D#0000ff>&nbsp;&nbsp;&nbsp; = &nbsp;&nbsp;&nbsp;=20
all_tab_partitions<BR>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; = &nbsp;WHERE&nbsp;=20
table_name =3D=20
'BUY_PRICE_PIECE_TYPE_HISTORY'<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nb=
sp; and=20
partition_name !=3D =
'TYPE01')<BR>WHERE&nbsp;to_number(substr(partition_name,5,2))=20
=3D buy_price_pkg.cnv_bpt_to_bp_id(5)</FONT><BR></DIV></FONT>
<DIV><FONT size=3D2>This should do it for you.</FONT></DIV>
<DIV><FONT size=3D2></FONT>&nbsp;</DIV>
<DIV>Igor Neyman, OCP DBA<BR><A=20

href=3D"mailto:ineyman_at_perceptron.com">ineyman_at_perceptron.com</A><BR>&nbs= p;=20
<BR><BR></DIV>
<BLOCKQUOTE dir=3Dltr=20
style=3D"PADDING-RIGHT: 0px; PADDING-LEFT: 5px; MARGIN-LEFT: 5px; = BORDER-LEFT: #000000 2px solid; MARGIN-RIGHT: 0px">   <DIV style=3D"FONT: 10pt arial">----- Original Message ----- </DIV>   <DIV=20
  style=3D"BACKGROUND: #e4e4e4; FONT: 10pt arial; font-color: = black"><B>From:</B>=20
  <A title=3Djohn.weatherman_at_replacements.com=20   href=3D"mailto:john.weatherman_at_replacements.com">John Weatherman</A> = </DIV>
  <DIV style=3D"FONT: 10pt arial"><B>To:</B> <A = title=3DORACLE-L_at_fatcity.com=20
  href=3D"mailto:ORACLE-L_at_fatcity.com">Multiple recipients of list = ORACLE-L</A>=20
  </DIV>
  <DIV style=3D"FONT: 10pt arial"><B>Sent:</B> Wednesday, September 04, = 2002 4:59=20
  PM</DIV>
  <DIV style=3D"FONT: 10pt arial"><B>Subject:</B> RE: Coercion = issue</DIV>
  <DIV><BR></DIV>
  <DIV><FONT face=3DArial color=3D#0000ff size=3D2><SPAN=20   class=3D711230717-04092002>There are partitions with names that don't = have the=20
  5th and 6th characters equal to</SPAN></FONT></DIV>   <DIV><FONT face=3DArial color=3D#0000ff size=3D2><SPAN=20   class=3D711230717-04092002>numbers, but not for this = table:</SPAN></FONT></DIV>
  <DIV><FONT face=3DArial color=3D#0000ff size=3D2><SPAN=20   class=3D711230717-04092002></SPAN></FONT>&nbsp;</DIV>   <DIV><FONT face=3DArial color=3D#0000ff size=3D2><SPAN=20   class=3D711230717-04092002>SQL&gt; select partition_name from = all_tab_partitions=20
  </SPAN></FONT></DIV>
  <DIV><FONT face=3DArial color=3D#0000ff size=3D2><SPAN=20   class=3D711230717-04092002>&nbsp;&nbsp;&nbsp;&nbsp; 2&nbsp;&nbsp; = where=20
  table_name =3D 'BUY_PRICE_PIECE_TYPE_HISTORY';</SPAN></FONT></DIV>   <DIV>&nbsp;</DIV>
  <DIV><FONT face=3DArial color=3D#0000ff size=3D2><SPAN=20   =
class=3D711230717-04092002>PARTITION_NAME<BR>----------------------------=
--<BR>TYPE01<BR>TYPE09<BR>TYPE10<BR>TYPE11<BR>TYPE12<BR></SPAN></FONT></D= IV>
  <DIV><FONT face=3DArial color=3D#0000ff size=3D2><SPAN = class=3D711230717-04092002>The=20
  query should be restricting&nbsp;things to only those partition names = for the=20
  one table.</SPAN></FONT></DIV>
  <P><FONT face=3D"Courier New" size=3D2>John P Weatherman</FONT> = <BR><FONT=20
  face=3D"Courier New" size=3D2>Database Administrator</FONT> <BR><FONT=20   face=3D"Courier New" size=3D2>Replacements Ltd.</FONT> </P>   <BLOCKQUOTE dir=3Dltr style=3D"MARGIN-RIGHT: 0px">     <DIV class=3DOutlookMessageHeader dir=3Dltr align=3Dleft><FONT = face=3DTahoma=20

    size=3D2>-----Original Message-----<BR><B>From:</B> Igor Neyman=20     [mailto:ineyman_at_perceptron.com]<BR><B>Sent:</B> Wednesday, September = 04,=20

    2002 1:14 PM<BR><B>To:</B> Multiple recipients of list=20     ORACLE-L<BR><B>Subject:</B> Re: Coercion issue<BR><BR></DIV></FONT>

    <DIV><FONT size=3D2>John,</FONT></DIV>
    <DIV><FONT size=3D2></FONT>&nbsp;</DIV>
    <DIV><FONT size=3D2>Do you have other partitions with such names, =
that 5th and=20

    6th characters are not convertible into numbers?</FONT></DIV>

    <DIV><FONT size=3D2>Like: 'TYPEA1'?</FONT></DIV>
    <DIV><FONT size=3D2></FONT>&nbsp;</DIV>
    <DIV>Igor Neyman, OCP DBA<BR><A=20

    =
href=3D"mailto:ineyman_at_perceptron.com">ineyman_at_perceptron.com</A><BR>&nbs= p;=20

    <BR><BR></DIV>
    <BLOCKQUOTE dir=3Dltr=20
    style=3D"PADDING-RIGHT: 0px; PADDING-LEFT: 5px; MARGIN-LEFT: 5px; = BORDER-LEFT: #000000 2px solid; MARGIN-RIGHT: 0px">

      <DIV style=3D"FONT: 10pt arial">----- Original Message ----- = </DIV>

      <DIV=20
      style=3D"BACKGROUND: #e4e4e4; FONT: 10pt arial; font-color: =
black"><B>From:</B>=20
      <A title=3Djohn.weatherman_at_replacements.com=20
      href=3D"mailto:john.weatherman_at_replacements.com">John =
Weatherman</A> </DIV>
      <DIV style=3D"FONT: 10pt arial"><B>To:</B> <A =
title=3DORACLE-L_at_fatcity.com=20
      href=3D"mailto:ORACLE-L_at_fatcity.com">Multiple recipients of list=20
      ORACLE-L</A> </DIV>
      <DIV style=3D"FONT: 10pt arial"><B>Sent:</B> Wednesday, September =
04, 2002=20
      12:43 PM</DIV>
      <DIV style=3D"FONT: 10pt arial"><B>Subject:</B> Coercion =
issue</DIV>
      <DIV><BR></DIV>
      <DIV><FONT face=3DArial color=3D#0000ff size=3D2><SPAN=20
      class=3D024323315-04092002>Hi all,</SPAN></FONT></DIV>
      <DIV><FONT face=3DArial color=3D#0000ff size=3D2><SPAN=20
      class=3D024323315-04092002></SPAN></FONT>&nbsp;</DIV>
      <DIV><FONT face=3DArial color=3D#0000ff size=3D2><SPAN=20
      class=3D024323315-04092002>I'm writing a package to manipulate a =
partitioned=20
      table for the duhvelop</SPAN></FONT><FONT face=3DArial =
color=3D#0000ff=20
      size=3D2><SPAN class=3D024323315-04092002>ers and have run=20
      into</SPAN></FONT></DIV>
      <DIV><FONT face=3DArial color=3D#0000ff size=3D2><SPAN=20
      class=3D024323315-04092002>a weird query that I can't figure =
out.&nbsp; I=20
      can convert a substring to a number in a select=20
clause,</SPAN></FONT></DIV>
      <DIV><FONT face=3DArial color=3D#0000ff size=3D2><SPAN=20
      class=3D024323315-04092002>but as soon as I try to use that same =
number in=20
      the where clause, the thing chokes.&nbsp; Has </SPAN></FONT></DIV>
      <DIV><FONT face=3DArial color=3D#0000ff size=3D2><SPAN=20
      class=3D024323315-04092002>anyone else seen anything like=20
      this?</SPAN></FONT></DIV>
      <DIV><FONT face=3DArial color=3D#0000ff size=3D2><SPAN=20
      class=3D024323315-04092002></SPAN></FONT>&nbsp;</DIV>
      <DIV><FONT face=3DArial color=3D#0000ff size=3D2><SPAN=20
      class=3D024323315-04092002>I'm on 9.0.1.3, Solaris 8.&nbsp;=20
      The&nbsp;buy_price_pkg.cnv_bpt_to_bp_id in the query is a=20
      custom</SPAN></FONT></DIV>
      <DIV><FONT face=3DArial color=3D#0000ff size=3D2><SPAN=20
      class=3D024323315-04092002>function that returns a number =
corresponding with=20
      which partition is current, old, next,</SPAN></FONT></DIV>
      <DIV><FONT face=3DArial color=3D#0000ff size=3D2><SPAN=20
      class=3D024323315-04092002>etc.</SPAN></FONT></DIV>
      <DIV><FONT face=3DArial color=3D#0000ff size=3D2><SPAN=20
      class=3D024323315-04092002></SPAN></FONT>&nbsp;</DIV>
      <DIV><FONT face=3DArial color=3D#0000ff size=3D2><SPAN=20
      class=3D024323315-04092002></SPAN></FONT>&nbsp;</DIV>
      <DIV><FONT face=3DArial color=3D#0000ff size=3D2>SQL&gt; SELECT=20
      to_number(substr(partition_name,5,2)),=20
      buy_price_pkg.cnv_bpt_to_bp_id(5)<BR>&nbsp; 2&nbsp; =
FROM&nbsp;&nbsp;=20
      all_tab_partitions<BR>&nbsp; 3&nbsp; WHERE&nbsp; table_name =3D=20
      'BUY_PRICE_PIECE_TYPE_HISTORY'<BR>&nbsp;=20
      4*&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; and partition_name =
!=3D=20
      'TYPE01'<BR>SQL&gt; /</FONT></DIV>
      <DIV>&nbsp;</DIV>
      <DIV><FONT face=3DArial color=3D#0000ff=20
      size=3D2>TO_NUMBER(SUBSTR(PARTITION_NAME,5,2))=20
      =
BUY_PRICE_PKG.CNV_BPT_TO_BP_ID(5)<BR>------------------------------------=
-=20
      =
---------------------------------<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&= nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&n= bsp;&nbsp;&nbsp;&nbsp;&nbsp;=20

      =
9&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp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p;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&n= bsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nb= sp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=20

      =
12&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp= ;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;= &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=20

      9</FONT></DIV>
      <DIV>&nbsp;</DIV>
      <DIV><FONT face=3DArial color=3D#0000ff size=3D2>SQL&gt; SELECT=20
      to_number(substr(partition_name,5,2)),=20
      buy_price_pkg.cnv_bpt_to_bp_id(5)<BR>&nbsp; 2&nbsp; =
FROM&nbsp;&nbsp;=20
      all_tab_partitions<BR>&nbsp; 3&nbsp; WHERE&nbsp; table_name =3D=20
      'BUY_PRICE_PIECE_TYPE_HISTORY'<BR>&nbsp;=20
      4&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; and =
partition_name !=3D=20
      'TYPE01'<BR>&nbsp; 5*&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; and=20
      to_number(substr(partition_name,5,2)) =3D=20
      buy_price_pkg.cnv_bpt_to_bp_id(5)<BR>SQL&gt;=20
      /<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; and=20
      to_number(substr(partition_name,5,2)) =3D=20
      =

buy_price_pkg.cnv_bpt_to_bp_id(5)<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;= &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&= nbsp;=20

      *<BR>ERROR at line 5:<BR>ORA-01722: invalid = number<BR></FONT></DIV>

      <DIV><FONT face=3DArial color=3D#0000ff size=3D2><SPAN=20
      class=3D024323315-04092002>TIA,</SPAN></FONT></DIV>
      <P><FONT face=3D"Courier New" size=3D2>John P Weatherman</FONT> =
<BR><FONT=20
      face=3D"Courier New" size=3D2>Database Administrator</FONT> =
<BR><FONT=20
      face=3D"Courier New" size=3D2>Replacements Ltd.</FONT>=20
  </P></BLOCKQUOTE></BLOCKQUOTE></BLOCKQUOTE></BODY></HTML>

------=_NextPart_000_0302_01C25435.D9D68630--

-- 
Please see the official ORACLE-L FAQ: http://www.orafaq.com
-- 
Author: Igor Neyman
  INET: ineyman_at_perceptron.com

Fat City Network Services    -- (858) 538-5051  FAX: (858) 538-5051
San Diego, California        -- Public Internet access / Mailing Lists
--------------------------------------------------------------------
To REMOVE yourself from this mailing list, send an E-Mail message
to: ListGuru_at_fatcity.com (note EXACT spelling of 'ListGuru') and in
the message BODY, include a line containing: UNSUB ORACLE-L
(or the name of mailing list you want to be removed from).  You may
also send the HELP command for other information (like subscribing).
Received on Wed Sep 04 2002 - 17:03:23 CDT

Original text of this message

HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US