Mostrando postagens com marcador sql. Mostrar todas as postagens
Mostrando postagens com marcador sql. Mostrar todas as postagens

segunda-feira, 24 de novembro de 2008

Conversão Explícita de Tipos (CAST)

Conversão Explícita de Tipos (CAST)
CAST ( expressão AS tipo ) AS apelido; -- Sintaxe SQL ANSI


Outra forma:


Tipo ( expressão );


Exemplo:


SELECT DATE '10/05/2002' - DATE '10/05/2001'; -- Retorna a quantidade de dias - -entre as duas datas


Para este tipo de conversão devemos:

Usar float8 ao invés de double precision;

Usar entre aspas alguns tipos como interval, time e timestamp


Obs.: aplicações portáveis devem evitar esta forma de conversão e em seu lugar usar o CAST explicitamente.


A função CAST() é utilizada para converter explicitamente tipos de dados em outros.

SELECT CAST(2 AS double precision) ^ CAST(3 AS double precision) AS "exp";

SELECT ~ CAST('20' AS int8) AS "negativo"; - Retorna -21

SELECT round(CAST (4 AS numeric), 4); - Retorna 4.0000

SELECT substr(CAST (1234 AS text), 3);

SELECT 1 AS "real" UNION SELECT CAST('2.2' AS REAL);

O material foi retirado do endereço:

http://pt.wikibooks.org/wiki/PostgreSQL_Pr%C3%A1tico/Fun%C3%A7%C3%B5es_Internas/Convers%C3%A3o_de_Tipos

Continue visitando o site

sexta-feira, 21 de novembro de 2008

Starting today

Hello people who love computer languages, programming, software engineering, computers and technology. I am doing this blog to report, share and help people with my experiences in programming and the topics related. I have worked with programming since i was 15 years old when I have started High School. The first language I have studied was Clipper. After three years with Clipper and some of Delphi I stayed 2 years without programming. So I started Information Technology studies where I learned some languages like c, c++, java, pascal, delphi, php, asp, javascript, html... Of course I have learned the basic of any language but after I worked 4 years with Visual Fox Pro and 2 years with Delphi and I made some Home Pages with html, flash, php i got some "Know How" I guess. Therefore I have had experience in languages and algorithms I have many things i want to know and I feel that I need to share with you. I also will post questions because now i am working with C++ and its a wide language and you can make a lot of differents applications and get differents doubts.

I hope you all like this blog and put your question and code here and I will try to help you.
My name is Carlos Augusto from Brazil, I am 26 years old.

Links

Related Posts with Thumbnails