Convertir valores en MySQL

A veces nos encontramos con campos en las tablas de MySQL que queremos tratar de forma distinta a como están definidos. Por ejemplo nos podemos encontrar con la intención de ordenar un campo alfanumérico del que conocemos que todos los datos son numericos. La ordenación obtenida no será la esperada ya que 11 tendrá preferencia sobre 2 y no sobre 20, poer ejemplo. Para solucionar esto podemos utilizar las funciones de conversión CAST y CONVERT.

La utilización es muy sencilla, basta con utilizar la función del modo

CAST (expresión AS tipo), CONVERT (expresión, tipo) o CONVERT (exprsión USING formato).

Expresión será lo que queramos convertir o forzar al tipo, por ejemplo el nombre de una columna. En el caso de formato lo utilizaremos para cambiar el formato de una expresión y pasar, por ejemplo de latin1 a utf8. Esto puede ser muy útil al insertar valores en una nueva tabla.

Un ejemplo lo podemos encontrar en la ordenación indicada al principio.

SELECT enum_col FROM tbl_name ORDER BY CAST(enum_col AS CHAR);

Los valores que pueden adaptar son:

  • BINARY. Produce una expresión binaria, apta para comparaciones byte a byte en lugar de por caráceres.
  • CHAR.
  • DATE.
  • DATETIME.
  • DECIMAL. Solo está disponible a partir de la versión 5.0.8 de MySQL.
  • SIGNED. Valores enteros.
  • TIME.
  • UNSIGNED. Valores enteros con signo.

Con estas funciones solucionamos de forma sencilla un problema que puede llegar a producir bastantes quebradreros de cabeza.

Etiquetas: 

Comentarios

hola tengo una duda como le ago para convertir un dato del tipo datetime que obtengo de un input en php y convertirlo a bigint y q me salga con 10 digitos

Modapk TownThanks for sharing<a href="https://modapktown.com">Modapk Town</a><a href="https://modapktown.com/shadow-fight-2-mod-apk">Shadow Fight 2 Mod Apk</a><a href="https://modapktown.com/dragon-hills-2-apk">Dragon Hills 2 Apk</a><a href="https://modapktown.com/the-simpsons-tapped-out-mod-apk">The Simpsons Tapped out Mod Apk</a><a href="https://modapktown.com/camscanner">Camscanner</a><a href="https://modapktown.com/hill-climb-racing-2-mod-apk">Hill Climb Racing 2 Mod Apk</a><a href="https://modapktown.com/blackplayer-ex">Blackplayer Ex</a><a href="https://modapktown.com/iron-force">Iron Force</a><a href="https://modapktown.com/golf-clash">Golf Clash</a><a href="https://modapktown.com/inotia-4">Inotia 4</a><a href="https://modapktown.com/supersu-pro">Supersu Pro</a><a href="https://modapktown.com/plex-android">Plex Android</a> 

<a href="https://cartoonhdapp.co"> Cartoon HD App </a>  <a href="https://snaptubedownloadapk.co"> Snaptube App </a>  <a href="https://allapkcollection.com"> All APK Collection </a>  <a href="https://playboxhdapkapp.com"> Playbox HD App </a>  <a href="https://snaptubeappapkdownload.com"> Snaptube App </a>  <a href="https://cartoonhdapkdownload.co"> Cartoon HD App </a>  <a href="https://luckypatcherappapk.com"> Lucky Patcher App </a>  <a href="https://tutuapkdownloadapp.com"> Tutuapk App </a>  <a href="https://playboxhdapkdownload.com"> Playbox HD App </a>  <a href="https://acmarketapp.org"> AcMarket App </a>  <a href="https://snaptubeapkdownloadapp.com"> Snaptube App </a>

Thanks for sharing.....<a href="https://supersuapp.com">SuperSu</a><a href="https://supersuapp.com/download">Download SuperSu</a><a href="https://supersuapp.com/supersu-zip">SuperSU Zip</a><a href="https://supersuapp.com/supersu-pro-apk">SuperSu Pro Apk</a> 

butterfly hair clips best micro loop human hair extensions hair extensions 16 18 20 inch curly hair her given hair coily clip ins hair extensions uk bellami wig leyla beaded hair extensions before and after cheap hair extensions asda hair loss shampoo human hair wigs blonde human hair wigs balayage hair extensions tape in hair perfume uk cheap hair extensions

This is extremely awesome article and instructive post mercifully checkViper4android For iOS 

terhadap alam. Oke, masyarakat bersalah di hadapan link10 jual plat high tensile sm490ya jual plat kapal jual plat stainless ss304 jual plat stainless ss310 jual plat stainless ss316 jual plat sumihard jual round bar besi aisi 440s45c jual round bar scm440 jual steel rail jual steel sheet pile Supplier besi siku baja Supplier besi siku baja Agen besi h beam Agen pipa besi baja sch 40 sch 80 undangan pernikahan yang unik Supplier Atap Spandek Sni Toko Pipa Besi baja Supplier besi h beam baja Supplier besi beton bjku Toko besi siku baja Toko besi siku baja Agen besi wf Agen besi hollow undangan pernikahan ala jepang Supplier Plat Bordes Kembang Jual Pipa Besi baja Toko besi h beam baja Supplier besi beton Sni Ulir Polos Agen besi siku baja Agen besi siku baja Agen wiremesh Agen besi beton Sni Ulir Polos undangan pernikahan arab Supplier Plat Besi Hitam Harga Pipa Besi baja Agen besi h beam baja Supplier besi beton ais Pabrik besi siku baja Pabrik besi siku baja Agen besi unp Agen besi wf baja undangan pernikahan ala jepang Supplier Plat Kapal Bki Krakatau Steel Pabrik Pipa Besi baja Pabrik besi h beam baja Supplier besi beton Distributor besi wf Distributor besi wf Agen besi cnp Agen besi unp undangan pernikahan bermanfaat Supplier Jual Besi Siku Baja Distributor Plat Kapal Besi baja Distributor plat besi hitam Harga besi wf Harga besi wf Agen besi hollow Agen besi siku undangan pernikahan ada fotonya Supplier Besi Unp Baja Profil Kanal Supplier Plat Kapal Besi baja Harga plat besi hitam www.pusatbesibaja.co.id Jual besi wf Jual besi wf Agen besi beton Sni Ulir Polos Agen Plat besi plat kapal undangancinta.com Supplier Besi Cnp Profil Baja Gording Agen Plat Kapal Besi baja Jual plat besi hitam www.pusatbesibaja.com Supplier besi wf Supplier besi wf ironsteelcenter.com Agen besi h beam baja undangan pernikahan cantik dan murah Supplier Besi Hollow Toko Plat Kapal Besi baja Pabrik Besi Cnp Profil Baja Gording Pabrik Besi Siku Baja Pabrik besi siku baja Pabrik besi beton Distributor sch 40 Distributor sch 40 Supplier atap spandek Supplier wiremesh undangan pernikahan bunga Pabrik Besi Hollow Distributor Besi Unp Baja Distributor besi wf Harga sch 40 Harga sch 40 Supplier baja ringan Supplier pipa besi baja sch 40 sch 80 undangan pernikahan islami Pabrik Wiremesh Supplier Besi Unp Baja Harga besi wf

This is extremely awesome article and instructive post mercifully checkiTube Android    

new years eve countdown Which you can put on whatsapp or Facebook or any other social networking websites. new years eve countdown is a great chance to upgrade your Facebook and WhatsApp status.  

Merry Christmas falls on 25th of December. This is the festival which is celebrated all around the world. Merry Christmas People collect their quality time and use it to spend with their family and friends with whatsapp messages and wishes. Some people buy gift to give it to their loved ones to show them that they love them. 

Playbox HD APK is an app that lets you watch your favorite TV shows and favorite videos, all use it to watch videos and TV shows online, most people mostly use PlayBox HD to watch your favorite TV shows and movies. We do. Between millions of people, praise of PlayBox HD is increasing and there is a great deal of praise. The best thing about Playbox HD is that it does not buffer when you are watching TV shows and movies. 

<a href="https://luckypatcherguide.com">Lucky Patcher</a>  <a href="https://luckypatcherbox.com">Lucky Patcher</a>  <a href="https://luckypatcherstar.com">Lucky Patcher</a>  <a href="https://www.luckypatchercity.com">Lucky Patcher</a>  <a href="https://luckypatcherapkapp.com">Lucky Patcher</a>  <a href="http://downloadluckypatcher.com">Lucky Patcher</a>

Prix Du Cialis 5mg En Pharmacie Dapoxetine And Cialis Best Buy Worldwide Amoxicilina online pharmacy How To Buy Omifin Comprar Cialis En Las Palmas Viagra 50mg Pas Cher

Notas De Propecia Levitra Pharmacie vardenafil hcl 20mg tab Buy Diflucan Without No Prescription Vetrinary Cheap Viagra Uk Cialis One Day

In this age people share videos so many times a day they need a decent and 100% safe app to do this task. Xender is one of them. With this app you can transfer your video everywhere you want, from your computer to iPhone and vice versa. You can download Xender app from https://xender-download.com for free!

Любите играть в игрушки на Андроид? Но не каждый любит рекламу! Для удаления рекламы из популярных Андроид-игр есть несколько вариантов, самым надежным из них является установка последней версии Лаки Патчера. Это приложение на Android, что взламывает игры и удаляет всю рекламу, что там есть. Уже сейчас можно скачать Лаки Патчер и наслаждаться игрушками!

Acheter Levitra En Luxembourg Side Effects Of Cephalexin For Dogs Amoxicillin Dosage For Adults Buy Amoxicillin For People

Albenza Propecia Effects On Women Become Pregnant buy zoloft uk Keflex Insomnia Cialis Wirkungseintritt

Vendite Kamagra In Spagna Generic Propecia Reviews Mutuabile Finasteride Propecia cialis online Cheap Silagra 100 Mg Get Priligy Prescription Online

What's cookin, good lookin? http://7d.tel/mzK6aN

Scrap aluminum recycling process http://7d.tel/ZTcfFU Aluminum machining scrap

Aluminium scrap buyers http://7d.tel/GNk1bu Aluminum scrap and environmental impact

Copper scrap processing plant http://7d.tel/2jE3DJ Copper scrap permits

Copper scrap metal prices http://7d.tel/bOs10p Environmental impact of Copper scrap recycling

Aluminium stamping scrap recycling http://7d.tel/zblxvH Aluminum scrap grade classification

Scrap metal market competition http://7d.tel/qCmBog Aluminium scrap industry certifications
Efficient metal scrap handling, Aluminum cable for sale, Scrap metal recovery plant

Scrap metal salvage depot http://7d.tel/ge5xWl Aluminium alloy reclamation
Metal reclamation solutions, Aluminum cable scrap exporters, Scrap metal reclaiming center

Añadir nuevo comentario

Filtered HTML

  • Las direcciones de las páginas web y las de correo se convierten en enlaces automáticamente.
  • Etiquetas HTML permitidas: <a> <em> <strong> <cite> <blockquote> <code> <ul> <ol> <li> <dl> <dt> <dd>
  • Saltos automáticos de líneas y de párrafos.

Plain text

  • No se permiten etiquetas HTML.
  • Las direcciones de las páginas web y las de correo se convierten en enlaces automáticamente.
  • Saltos automáticos de líneas y de párrafos.
CAPTCHA
Esta pregunta se realiza para comprobar que se trata de un humano y prevenir los accesos automatizados para publicar spam.