[pgsql-jp: 27338] Re: データ変換

Takao Kato sirius @ jp.fujitsu.com
2002年 9月 6日 (金) 09:43:24 JST


加藤@川崎です。

> データ型の変換について質問させていただきます。
> 項目 A  varchar(04);
> このAの項目には、"0001" "001"というようにデータが
> 入力されています。
> この場合、"0001"と"001"をイコールとして検索したいのですが
> どのようにすればいいのか、教えて頂きたいのですが。
> よろしくお願い致します。

to_numberを使えばよろしいかと思いますが。

-- 8< -- 8< -- 8< --
test=# select version();
                             version
------------------------------------------------------------------
 PostgreSQL 7.1.2 on sparc-sun-solaris2.8, compiled by GCC 2.95.3
(1 row)

test=# select version();
test=# create temp table test2 (a varchar(5),b varchar(3));
CREATE
test=# insert into test2 values('0001','02');
INSERT 11371403 1
test=# insert into test2 values('0010','010');
INSERT 11371404 1
test=# insert into test2 values('001','001');
INSERT 11371405 1
test=# select * from test2 where to_number(a,'99999') = to_number(b,'99999');
  a   |  b
------+-----
 0010 | 010
 001  | 001
(2 rows)
-- 8< -- 8< -- 8< --

----
加藤%頭の朝の体操@川崎



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