String equivalent in mysql datatypes - mysql

I want a create a column that needs to store unknown length strings.
I am making a parsing of some file and pushing it's content to the DB and I have no idea about the length , can be pretty big.
So is there any equivalent to String type ?
Thanks

Depends on what your storing...
CHAR is a fixed length string
VARCHAR is a variable length string
TINYTEXT/TEXT/MEDIUMTEXT/LONGTEXT is a text field (long string)
Choose the format that is most appropriate for what your storing.
See http://dev.mysql.com/doc/refman/5.0/en/blob.html for more information on the TEXT field and the differences.

Related

Converting string to integer with "%" special character in Pentaho

Hi I am facing an issue while converting string value to integer.
Actually I am reading data from the table and there are fields like 39% and they are string data type.
Now i want to convert them into INteger datatype and load them in to another table.
I tried using select values in PDI but it is giving me error like. "Could't convert String to Integer."
Please help me in resolving this issue.
The percentage sign isn't part of the integer type in Java, so first you need to remove that character in order to make the type casting.
Add a new "Replace in string" step between the data origin and "Select values"
Double click on the new added step and on the "In stream field" select the field that needs to be cleaned
On "Search", type "%" (without the parentheses) and click Ok to close the dialog.
That should do the trick.

MySQL: Which data type can handle special character?

I have MySQL table, and in message field I want to store encrypted data. Encrypted data looks like
�O-�H,,E%P!�O-�H-!E%!P!�O-�H,E%�P!�O-�H,,E$�P"�O-!H,E%P!�O-H+�E%P"
Hence, I cannot store such characters in message either I did utf_general_ci or blog.
Please help me to figure out which datatype can store such characters.
Take a look at this URL: https://dev.mysql.com/doc/refman/5.5/en/encryption-functions.html
"Many encryption and compression functions return strings for which the result might contain arbitrary byte values. If you want to store these results, use a column with a VARBINARY or BLOB binary string data type. This will avoid potential problems with trailing space removal or character set conversion that would change data values, such as may occur if you use a nonbinary string data type (CHAR, VARCHAR, TEXT)."

Effects of changing datatype of a column from varchar to text

The text data I have for a column in database in an enterprise application (uses hibernate) is huge and after increasing varchar size to a specific number, I don't have any other choice but to change the datatype to text. Can anyone help me understand how it may affect my application. Do I need to take care of anything else or just changing the datatype works ?
You should use TEXT. Although, that's the same thing as VARCHAR:
If the declared type of the column contains any of the strings "CHAR",
"CLOB", or "TEXT" then that column has TEXT affinity. Notice that the
type VARCHAR contains the string "CHAR" and is thus assigned TEXT
affinity
Also note
Note that numeric arguments in parentheses that following the type
name (ex: "VARCHAR(255)") are ignored by SQLite - SQLite does not
impose any length restrictions (other than the large global
SQLITE_MAX_LENGTH limit) on the length of strings, BLOBs or numeric
values.
Your application work fine with datatype text.You don't need to take care of any thing
if you want to be sure, create backup database first just in case,
or at least backup/duplicate table you were going to make changes
for me I also prefer varchar than text
because varchar used to be using smaller memory than text
ex : address (100) , records only using 80 character, will be saved as 80 character in varchar
while in text , will be saved as 100 character

What data type does a URL correspond to in MySQL?

I am going to store URLs inside of my database and I just had a simple question. Do URLs have to be a certain data type?
Simply put the data type should be VARCHAR
URLs can contain any number of characters, and can be any length (within reason on the smaller end). A CHAR field can only contain the number of characters that is set in the table definition. A VariableCharacter (VARCHAR) field can contain a variable number of characters. So since not all URL's are of equal length you need the variability. You could make an argument to use a TEXT field if you needed to store really long URLs; however, for most use cases VARCHAR will suffice.
An url has special, numerically and normal chars.
Therefor you should use the type "VARCHAR" in MySql.

Can you set a CHAR to NULL or an empty string?

I haven't used CHAR much in the past as I seemed to use VARCHAR too much; I'm trying to use CHAR when appropriate lately & from what I understand you use it when the data is all the same length in that certain column (else it is padded with spaces).
Because all the data is supposed to be the same length I was wondering can a CHAR field be NULL or an empty string? Such for cases when that specific field doesn't have a value whilst others do.
The answer to your question(s) is Yes.
Yes, the CHAR type can be NULLable. I believe every column type can allow for NULL.
Yes, the CHAR type can be an empty string. The DB will not see an empty string as any different from any other string. I wouldn't suggest ever using empty string though because, in almost every case, an empty string (lack of ANY characters) is trying to represent a lack of data, which is what NULL is for.
If you want to know more specific details around the difference of CHAR vs. VARCHAR in MySQL specifically...
MySQL 5.0 Reference - The CHAR and VARCHAR Types
Yes, both NULL and empty string can be used. The data doesn't have to be the same length in the column, as you noted, anything smaller is just padded with spaces to fill the column.