Amy Anuszewski
Amy Anuszewski

Reputation: 1853

Obfuscate a mysql query result for a string

I need to do something rather strange in MySQL, and I'm hoping to get some ideas on how to go about doing it in a query rather than post-processing the query results.

I have a field in the database that in some cases I need to return the value and in some cases, I don't want the value to be shown. Because of a variety of reasons, I can't simply remove the field from the query when I don't want the value to be shown. I need to obfuscate it - either by blanking it out, or replacing it with # signs, etc.

With dates, I can use DATE_FORMAT to return the date in the desired format. Is there any kind of function I can do in MySQL that will hide the results of the column for me?

Amy

Upvotes: 1

Views: 1252

Answers (2)

Explosion Pills
Explosion Pills

Reputation: 191779

MySQL has an IF:

IF(secure, '', field) as field

Upvotes: 2

hsz
hsz

Reputation: 152266

You can use IF statement in your SELECT query.

In IF() you specify some conditions and then name it as a column name:

SELECT col1, col2, IF(5 > 6, col3, '') AS col3 FROM table

Upvotes: 4

Related Questions