Jump to content

Mysql cell looks blank, but is something in the cell?


Recommended Posts

I have a MySQL table with a field called student_id.  This table is populated by a text file.  For some rows, a student id is not imported.  I would like to delete these rows like this:

 

DELETE FROM mytable WHERE student_id = "" ;

 

However, this does not work.  Nothing seems to work.  I have tried a lot of things to determine what is in this this field.  In the table structure it is

 

CHAR(9) NULL  is ALLOWED

 

How can I determine what is in this field so that I can delete a row based on the field's contents or non-contents.

 

Thank you.

 

FOLLOW-UP --  Whatever is in the field has a length of 2.  When I issue this select, it brings up the rows appropriately:

 

SELECT * FROM mytable WHERE LENGTH(student_id) = 2 ;

They are probably crlf \r\n

 

You can use the mysql ORD() function in a SELECT query to display what value the characters are.

 

What method are you using to import the data, because you should probably validate (or trim()) what is being imported.

 

Edit: Also, you can probably use the mysql TRIM() function or smiler in an UPDATE query to remove the characters once you find what they are (you likely have them on the end of actual data if they are the \r\n from a text file.)

Well,  thank you!  Yes, you were correct about the contents of these cells.  I have never used ORD() before, and I did some research and learned a lot.  I've imported thousands of text files, but I have never (knowingly) run into this, although this import had to be done a little differently.

 

My appreciations again for you help, PFMaBiSmAd.  I'll remember ORD()!

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.