[pgsql-jp: 30865] Re: to_numberでFormat エラーになります

gotou gotou @ hokkou.co.jp
2003年 8月 30日 (土) 17:45:47 JST


ごとうです。
石田様、谷口様、ありがとうございます。

> こんにちは。石田@苫小牧市です。
>
> >
> > to_numberを使用して、指定した数値と比較して対象を絞り込む、
> > というSQLなのですが、それが、実行時に
> >
> > Bad numeric input format ' '
> >
> > と言うエラーになってしまいます。
>
> select to_number('', '99');
>
> を実行しても、
>
> ERROR:  Bad numeric input format ' '
>
> というエラーになるようです。(7.3.2 ですが)。
>
> > テストサーバ-------------------------------------------
> > SELECT COUNT (customer_base_mst.cust_cd)
> > FROM (customer_add_mst
> > 		LEFT JOIN employ_mst
> > 		ON customer_add_mst.employ_cd = employ_mst.employ_cd)
> > 	RIGHT JOIN customer_base_mst
> > 	ON customer_add_mst.cust_cd = customer_base_mst.cust_cd
> > WHERE (
> > 		(customer_base_mst.del_flg='0' Or
> customer_base_mst.del_flg Is Null)
> > 	AND (customer_add_mst.del_flg='0' Or
> customer_add_mst.del_flg Is Null)
> > 	AND (employ_mst.del_flg='0' Or employ_mst.del_flg Is Null)
> > 	)
> > AND (customer_base_mst.crt_cd='xxxxxxxxxxxxxxx')
> > AND customer_base_mst.st_cd in ('xxxxx')
> > AND (to_number(substr(birthday,5,2),'99') = 9 );
>
> substr(birthday, 5, 2) が空白などを返さないかを調べて
> みてはどうでしょうか?
>


> 谷口と申します。
>
> つまり、以下の予想が立ちます。
> ・カラム birthday の値が空白
> ・substr(birthday,5,2) の値が空白 -> birthday の長さが 4以下

データベースを確認したところ、確かにNullが入っているデータもあるのですが、
テスト環境にもNull値があるのです。(というより、テスト環境のほうが圧倒的に多
いです。)
しかし、テスト環境では、エラーにはならず、正しい件数が返ってきます。

そして、substrしているのは、名前からわかるように誕生日データで、char(8)で
入っています。
そして、9月の誕生日の人を数える、というSQLになっています。

ヒットするはずのデータが、下記になります。
----------------------------------------------------
            cust_cd            		        | birthday
--------------------------------+----------
 000001730017300001730000000115  | 19790902
 000001730017300001730000000112  | 19800909
 000001730017300001730000000116  | 19740906
 000001730017300001730000000118  | 19790923
 000001730017300001730000000127  | 19690911
 000001730017300001730000000026  | 19780906
 000001730017300001730000000039  | 19800913
 000001730017300001730000000067  | 19830905
 000001730017300001730000000068  | 19770910
 000001730017300001730000000084  | 19730920
 000001730017300001730000000059  | 19800906
 000001730017300001730000000088  | 19780906
 000001730017300001730000000094  | 19740907
 000001730017300001730000000095  | 19820912
 000001730017300001730000000096  | 19760907


たびたびすみませんが、どうかよろしくお願いします。





pgsql-jp メーリングリストの案内