Concatenaçao to_char

View: New views
5 Messages — Rating Filter:   Alert me  

Concatenaçao to_char

by paulo matadr :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Some parts of this message have been removed. Learn more about Nabble's security policy.
Galera , tenho a seguinte situação:

create table teste_string( a int,b  int );


insert into teste_string values (111,22);
insert into teste_string values (112,223);
insert into teste_string values (13,224);
insert into teste_string values (114,225);
insert into teste_string values (15,226);

select  (to_char(a,'999'))||'.'||(to_char(b,'999')) as juncao from teste_string

o resultado ta vindo assim:

select  (to_char(a,'999'))||'.'||(to_char(b,'999')) as juncao from teste_string;
  juncao
-----------
  111.  22
  112. 223
   13. 224
  114. 225
   15. 226
(5 rows)

111.  22 colocando espaco entre os campos , como eu faço eliminar isso?

agradeço desde ja

Paulo





Veja quais são os assuntos do momento no Yahoo! + Buscados: Top 10 - Celebridades - Música - Esportes
_______________________________________________
pgbr-geral mailing list
pgbr-geral@...
https://listas.postgresql.org.br/cgi-bin/mailman/listinfo/pgbr-geral

Re: Concatenaçao to_char

by Osvaldo Kussama :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

2009/11/3 paulo matadr <saddoness@...>:

> Galera , tenho a seguinte situação:
>
> create table teste_string( a int,b  int );
>
>
> insert into teste_string values (111,22);
> insert into teste_string values (112,223);
> insert into teste_string values (13,224);
> insert into teste_string values (114,225);
> insert into teste_string values (15,226);
>
> select  (to_char(a,'999'))||'.'||(to_char(b,'999')) as juncao from
> teste_string
>
> o resultado ta vindo assim:
>
> select  (to_char(a,'999'))||'.'||(to_char(b,'999')) as juncao from
> teste_string;
>   juncao
> -----------
>   111.  22
>   112. 223
>    13. 224
>   114. 225
>    15. 226
> (5 rows)
>
> 111.  22 colocando espaco entre os campos , como eu faço eliminar isso?
>


Creio que ltrim(to_char(b,'999'),' ') resolve.
http://www.postgresql.org/docs/current/interactive/functions-string.html

Osvaldo
_______________________________________________
pgbr-geral mailing list
pgbr-geral@...
https://listas.postgresql.org.br/cgi-bin/mailman/listinfo/pgbr-geral

Re: Concatenaçao to_char

by Osvaldo Kussama :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

2009/11/3 Osvaldo Kussama <osvaldo.kussama@...>:

> 2009/11/3 paulo matadr <saddoness@...>:
>> Galera , tenho a seguinte situação:
>>
>> create table teste_string( a int,b  int );
>>
>>
>> insert into teste_string values (111,22);
>> insert into teste_string values (112,223);
>> insert into teste_string values (13,224);
>> insert into teste_string values (114,225);
>> insert into teste_string values (15,226);
>>
>> select  (to_char(a,'999'))||'.'||(to_char(b,'999')) as juncao from
>> teste_string
>>
>> o resultado ta vindo assim:
>>
>> select  (to_char(a,'999'))||'.'||(to_char(b,'999')) as juncao from
>> teste_string;
>>   juncao
>> -----------
>>   111.  22
>>   112. 223
>>    13. 224
>>   114. 225
>>    15. 226
>> (5 rows)
>>
>> 111.  22 colocando espaco entre os campos , como eu faço eliminar isso?
>>
>
>
> Creio que ltrim(to_char(b,'999'),' ') resolve.
> http://www.postgresql.org/docs/current/interactive/functions-string.html
>


Oops!
Creio também que você deveria utilizar '000' no lugar de '999' para
sair 111.022 e não 111.22. (não sei se é efetivamente seu caso)

Osvaldo
_______________________________________________
pgbr-geral mailing list
pgbr-geral@...
https://listas.postgresql.org.br/cgi-bin/mailman/listinfo/pgbr-geral

Re: Concatenaçao to_char

by Osvaldo Kussama :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

2009/11/3 Osvaldo Kussama <osvaldo.kussama@...>:

> 2009/11/3 Osvaldo Kussama <osvaldo.kussama@...>:
>> 2009/11/3 paulo matadr <saddoness@...>:
>>> Galera , tenho a seguinte situação:
>>>
>>> create table teste_string( a int,b  int );
>>>
>>>
>>> insert into teste_string values (111,22);
>>> insert into teste_string values (112,223);
>>> insert into teste_string values (13,224);
>>> insert into teste_string values (114,225);
>>> insert into teste_string values (15,226);
>>>
>>> select  (to_char(a,'999'))||'.'||(to_char(b,'999')) as juncao from
>>> teste_string
>>>
>>> o resultado ta vindo assim:
>>>
>>> select  (to_char(a,'999'))||'.'||(to_char(b,'999')) as juncao from
>>> teste_string;
>>>   juncao
>>> -----------
>>>   111.  22
>>>   112. 223
>>>    13. 224
>>>   114. 225
>>>    15. 226
>>> (5 rows)
>>>
>>> 111.  22 colocando espaco entre os campos , como eu faço eliminar isso?
>>>
>>
>>
>> Creio que ltrim(to_char(b,'999'),' ') resolve.
>> http://www.postgresql.org/docs/current/interactive/functions-string.html
>>
>
> Oops!
> Creio também que você deveria utilizar '000' no lugar de '999' para
> sair 111.022 e não 111.22. (não sei se é efetivamente seu caso)
>


Melhor ainda, utilize o FM (havia me esquecido dele):

bdteste=# SELECT to_char(111,'999') || '.' || to_char(22, 'FM000');
 ?column?
----------
  111.022
(1 registro)

Osvaldo
_______________________________________________
pgbr-geral mailing list
pgbr-geral@...
https://listas.postgresql.org.br/cgi-bin/mailman/listinfo/pgbr-geral

Res: Concatenaçao to_char

by paulo matadr :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Some parts of this message have been removed. Learn more about Nabble's security policy.
Muito obrigado osvaldo
resolveu!!

att


De: Osvaldo Kussama <osvaldo.kussama@...>
Para: Comunidade PostgreSQL Brasileira <pgbr-geral@...>
Enviadas: Terça-feira, 3 de Novembro de 2009 12:54:22
Assunto: Re: [pgbr-geral] Concatenaçao to_char

2009/11/3 Osvaldo Kussama <osvaldo.kussama@...>:

> 2009/11/3 Osvaldo Kussama <osvaldo.kussama@...>:
>> 2009/11/3 paulo matadr <saddoness@...>:
>>> Galera , tenho a seguinte situação:
>>>
>>> create table teste_string( a int,b  int );
>>>
>>>
>>> insert into teste_string values (111,22);
>>> insert into teste_string values (112,223);
>>> insert into teste_string values (13,224);
>>> insert into teste_string values (114,225);
>>> insert into teste_string values (15,226);
>>>
>>> select  (to_char(a,'999'))||'.'||(to_char(b,'999')) as juncao from
>>> teste_string
>>>
>>> o resultado ta vindo assim:
>>>
>>> select  (to_char(a,'999'))||'.'||(to_char(b,'999')) as juncao from
>>> teste_string;
>>>   juncao
>>> -----------
>>>   111.  22
>>>   112. 223
>>>    13. 224
>>>   114. 225
>>>    15. 226
>>> (5 rows)
>>>
>>> 111.  22 colocando espaco entre os campos , como eu faço eliminar isso?
>>>
>>
>>
>> Creio que ltrim(to_char(b,'999'),' ') resolve.
>> http://www.postgresql.org/docs/current/interactive/functions-string.html
>>
>
> Oops!
> Creio também que você deveria utilizar '000' no lugar de '999' para
> sair 111.022 e não 111.22. (não sei se é efetivamente seu caso)
>


Melhor ainda, utilize o FM (havia me esquecido dele):

bdteste=# SELECT to_char(111,'999') || '.' || to_char(22, 'FM000');
?column?
----------
  111.022
(1 registro)

Osvaldo
_______________________________________________
pgbr-geral mailing list
pgbr-geral@...
https://listas.postgresql.org.br/cgi-bin/mailman/listinfo/pgbr-geral


Veja quais são os assuntos do momento no Yahoo! + Buscados: Top 10 - Celebridades - Música - Esportes
_______________________________________________
pgbr-geral mailing list
pgbr-geral@...
https://listas.postgresql.org.br/cgi-bin/mailman/listinfo/pgbr-geral