homepage Welcome to WebmasterWorld Guest from
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member
Visit PubCon.com
Home / Forums Index / Code, Content, and Presentation / Databases
Forum Library, Charter, Moderator: open

Databases Forum

percent colum

 1:24 pm on Jan 9, 2008 (gmt 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)

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)

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)

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)

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.

Global Options:
 top home search open messages active posts  

Home / Forums Index / Code, Content, and Presentation / Databases
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved