Welcome to WebmasterWorld Guest from 54.163.25.166

Forum Moderators: open

Message Too Old, No Replies

percent colum

     
1:24 pm on Jan 9, 2008 (gmt 0)

New User

5+ Year Member

joined:Jan 9, 2008
posts: 1
votes: 0


can someone tell how to I enter percents in a column( i'm using Oracle), is there some specific data type or?
3:02 pm on Jan 9, 2008 (gmt 0)

Junior Member

5+ Year Member

joined:Sept 10, 2007
posts:50
votes: 0


Have you tried adding a backslash in front of the % sign. Not 100% sure as I haven't used oracle since college. That may help.
4:21 am on Jan 11, 2008 (gmt 0)

Administrator

WebmasterWorld Administrator coopster is a WebmasterWorld Top Contributor of All Time 10+ Year Member

joined:July 31, 2003
posts:12533
votes: 0


Welcome to WebmasterWorld, spring.

Are you talking about entering data into a column using the INSERT statement? If so you may need to escape the % character as 8kobe mentioned. Check the documentation to be certain.

5:41 am on Jan 11, 2008 (gmt 0)

Senior Member

WebmasterWorld Senior Member 5+ Year Member

joined:Nov 11, 2007
posts:769
votes: 1



I believe the following will work in both Oracle and SQL*Server:

SELECT * FROM products WHERE description LIKE '%\%%' ESCAPE '\'

The predicate "ESCAPE '\'" tells Oracle that you are using the '\' in the like predicate to 'escape' special characters. Normally a % sign in a string following LIKE has a special meaning - it is a wildcard. But in this case the 2nd '%' is escaped meaning take it as a literal.

So the above statement should return all rows from products where the description contains any number of characters (1st % is a wildcard) followed by at least one '%' character (2nd % is an escaped literal) followed by any number of characters (3rd % is another wildcard).

Hope that helps.

3:34 pm on Jan 11, 2008 (gmt 0)

Senior Member

WebmasterWorld Senior Member jtara is a WebmasterWorld Top Contributor of All Time 10+ Year Member

joined:Nov 26, 2005
posts:3041
votes: 0


Do you really want to enter a literal percent-sign in a column?

Or do you want a column to represent a percentage value?

If the former, I assume you are using some kind of text data type. You will have to check the specific rules for escaping characters for your SQL if % is a special character inside of a string. But I don't know of any SQL system where % is a special character in a string. Just make sure you put quotation marks around the string.

I suspect, though, that you want a column to represent a percentage value. In most (if not all) SQL systems, there's no specific data type for percentages.

Just use an integer or float data type. You will need to add the percentage sign on output, remove it on input, and scale the value (divide by 100) when using it as a multiplier.