Convert mysql LONGTEXT value to VARCHAR value? - mysql

I have a function that post on a users facebook wall.
One thing that I send to facebook is some text that I get from my mysql table that is set to LONGTEXT. If I have the table set as LONGTEXT then the text is not send to facebook, but if I set the table to VARCHAR then the text is send to facebook!
So how can I convert the LONGTEXT value that I get so it becomes like a VARCHAR value, before I send it to facebook?
I use the table in many other places so I just cant convert the table itself to VARCHAR, its to much work! I have to convert the output instead.
Any input appreciated thanks!

In mysql you can do:
SELECT ID, CAST(YourLongText as char(255)) AS YourVarchar FROM some_table
Did you mean like that

use cast as in the post from #Sudhir or use the mysql function convert:
http://dev.mysql.com/doc/refman/5.1/de/charset-convert.html

use the CONVERT or CAST functions: http://www.geeksengine.com/database/single-row-functions/conversion-functions.php
CONVERT(expr,type)
In this form, CONVERT takes a value in the form of expr and converts it to a value of type.
CAST(expr AS type)
Using CAST() function is the same as using CONVERT() function except that it uses keyword AS in between expr and type rather than a comma.

Related

Parsing Custom Date Format in MySQL

Problem
I need to query out a date value for use in some ETL processing. However, the data is stored in MySQL as a VARCHAR column in values like 1/1/19.
What I've tried
A simple CAST(myDateColumn as DATE) fails as I get values like 0001-01-19 returned back.
Question
Am I able to pass a custom date format string into the CAST call somehow to tell it how to parse out the date parts? If not, could a SUBSTRING type of function help here?
As discussed in the comments above, you can use the STR_TO_DATE() function to parse a string into a proper YYYY-MM-DD date.

How to insert data in table using the data type double

Whenever I tried to save my table using double data type this error appears please help I'm a newbie.
So your answer depends upon how you want to add double value in MYSQL.
If you want to query MYSQL through SQL then you should do the query using decimal value in your query instead of a comma.
a query should be like this...
INSERT INTO `comment` ( `no_of_comments` , `newField` ) VALUES (12,23.5)
Here newField is the double type and this query works fine.
And if you want to insert the default Decimal value in MYSQL database using PHPMYADMIN portal then you should add double value using the comma for decimal as...
Don't forget that you add comma just for defining the length of the decimal part, You add value in a proper double format for defining the value of the field.
There might have issue in Table Structure.
You have to Set Double Datatype with Length,Values Format.

Convert varchar string data to time format in mysql

I need to convert varchar string data to time format in mysql.
For example,
I have a varchar column in table which stores time. The accepted values should be like 9:30 AM or 1200 PM. But currently it has either blank values or it has values like 9.30am or 12:00
There are many records like this, so cannot update manually.
Ithere any work around or function or procedure to do so?
please help.
Thanks
You can use the STR_TO_DATE() MySQL function to convert any string to a date.
Additionally you can use TIME() to extract the time portion of a datetime. A combination of both function is used to convert an arbitrary date string to a datetime and then you can extract the time portion from it as a valid MySQL TIME.
By default MySQL functions follow standard format but custom format can be specified and if your values don't use the international formats you'll need to check with the documentation and provide the format your system is using.

Selecting a Point datatype from MYSQL

Good Day,
I am trying to get a point from an SQL column. CUrrently it is encoded as a string of characters: Gþ`C#Ëóàî¬Ë]À
So is there any way to actually decode it to get the actual value?
Use MySQL's AsText() function:
SELECT AsText(myPoint) FROM myTable

mysql: CONVERT() function not working to bytes from GROUP_CONCAT() into VARCHAR

I am using mysql's GROUP_CONCAT() for one of my query. But I am getting data in bytes.
To convert the bytes into VARCHAR I used the CONVERT() function.
But I dont see any difference even after that. I am still getting data in bytes.
Below is what I have tried:
CONVERT(GROUP_CONCAT((T1.CASE NODE_ID WHEN 103 THEN CONCAT(T1.CUSTOMER_ATTRIBUTE,'~',T2.DISPLAY_TEXT) ELSE NULL END)) USING LATIN1)AS HEADER,
but I am getting the output as:
HEADER
----------
Name [4B]
Help needed.
Thanks.
Use like this CONCAT(GROUP_CONCAT(your_column)) this will give as the string as output
cheers..
This is because different types are passed into CONCAT function. MySQL converts them into appropriate type, in your case it is BLOB or something else.
The solution is to convert all non-string types to string, or just convert result of CONCAT function to string once. For example -
SELECT CAST(CONCAT(id, '~', column1, column2) AS CHAR)