converter integer para string consulta

32 views
Skip to first unread message

Gilson Rauschkolb

unread,
Dec 16, 2015, 5:39:15 PM12/16/15
to Google Cloud SQL discuss
Boa Noite,

Pessoal estou com um dilema, tenho um campo em uma tabela que é integer, e na consulta gostaria de substituir o valor por um texto.

como faço isso?

Obrigado

Danny Xu

unread,
Dec 17, 2015, 12:01:56 PM12/17/15
to Google Cloud SQL discuss
Hi,

You could add a new field to the table. Copy the original integer field as string type to the new field. Delete the old field in integer. Then you can use the new field in the future.

Razvan Musaloiu-E.

unread,
Dec 18, 2015, 5:45:38 PM12/18/15
to Google Cloud SQL discuss
I think CAST (or CONVERT) is what you need.

Here is an example:

mysql> CREATE TABLE t(i INT);
Query OK, 0 rows affected (0.50 sec)

mysql> INSERT INTO t VALUES (1), (2);
Query OK, 2 rows affected (0.24 sec)
Records: 2  Duplicates: 0  Warnings: 0

mysql> SELECT CAST(i AS CHAR) FROM t;
+-----------------+
| CAST(i AS CHAR) |
+-----------------+
| 1               |
| 2               |
+-----------------+
2 rows in set (0.09 sec)

mysql> 


-- Razvan ME

Gilson Rauschkolb

unread,
Dec 18, 2015, 5:54:19 PM12/18/15
to google-cloud...@googlegroups.com

Thank your all

----
Cordialmente,
Gilson Luiz Rauschkolb

--
You received this message because you are subscribed to a topic in the Google Groups "Google Cloud SQL discuss" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/google-cloud-sql-discuss/dfDzqSaDhH4/unsubscribe.
To unsubscribe from this group and all its topics, send an email to google-cloud-sql-d...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/google-cloud-sql-discuss/e1aa0010-21f3-450b-b745-3f5bb781336e%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Reply all
Reply to author
Forward
0 new messages