Data conversion for MySQL

Source: Internet
Author: User

The data that is converted into a character type in the SQL statement is completed for the numeric type.
Like this time will read out the float type of data in the Jsonobject.fromobject (object). toString ();
This method does not retain the data type to be retained after the decimal point, like 100.00 of this data, into the JSON data converted into 100, not conducive to the effect of the display.
At the same time, since I am a list collection queried through SQL statements, it is difficult and inefficient to modify them in Java code, so consider implementing them in SQL.

Implemented in MyBatis, CONVERT (Q.quotediscountamount,char (20))
------------------------------
SELECT S.taskcode,p.prvshotname,convert (Q.quotediscountamount,char) as Quoteamount,q.inscomcode,s.taskstate From Insbworkflowmain m
Left JOIN insbworkflowsub s on m.instanceid = S.maininstanceid
Left JOIN insbquoteinfo q on q.workflowinstanceid = S.instanceid
Left JOIN Insbprovider p on p.prvcode = Q.inscomcode where m.instanceid= #{processinstanceid}
------------------------------
CONVERT (Q.quotediscountamount,char); You can also remove the length limit here.

Similarly, other formats can also be converted
binary[(N)]

char[(N)]

DATE

Time

DateTime Date Time

DECIMAL floating-point number

Signed [integer] integer

UNSIGNED [integer] unsigned integer
-----------------------------------------
Date,time,datetime three different kinds of time:
Date: Type, MySQL retrieves and displays the date value in ' YYYY-MM-DD ' format, with no time portion.
Time: Date type, which represents the time of day, MySQL retrieves and displays the value in "HH:MM:SS" format.
DateTime: Date and Time type, sum of both.

In addition, MySQL also has one of the following:
TIMESTAMP, a column type provides a type that you can use to automatically mark an INSERT or update operation with the current date and time.

Data conversion for MySQL

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.