Search...
FAQs
Subscribe
Pie
FAQs
Recent topics
Flagged topics
Hot topics
Best topics
Search...
Search within JDBC and Relational Databases
Search Coderanch
Advance search
Google search
Register / Login
Post Reply
Bookmark Topic
Watch Topic
New Topic
programming forums
Java
Mobile
Certification
Databases
Caching
Books
Engineering
Micro Controllers
OS
Languages
Paradigms
IDEs
Build Tools
Frameworks
Application Servers
Open Source
This Site
Careers
Other
Pie Elite
all forums
this forum made possible by our volunteer staff, including ...
Marshals:
Campbell Ritchie
Jeanne Boyarsky
Ron McLeod
Paul Clapham
Liutauras Vilda
Sheriffs:
paul wheaton
Rob Spoor
Devaka Cooray
Saloon Keepers:
Stephan van Hulst
Tim Holloway
Carey Brown
Frits Walraven
Tim Moores
Bartenders:
Mikalai Zaikin
Forum:
JDBC and Relational Databases
Cast number to varchar in select
Theodore David Williams
Ranch Hand
Posts: 102
posted 11 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
I would like to form a select statement to cast a number column to a varchar so I can append some additional info in the response.
Ie
[code]
Select 'test-' || CAST(id as varchar(10)) as testcolumn from some_table;
[code]
However I cannot get this to work in MySQL and oracle. I would like this statement to stay database agnostic. Any ideas?
Thanks.
Rajit vreddi
Greenhorn
Posts: 17
posted 11 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
Use To_char if you use oracle DB.
Ex: SELECT To_char(CUSTOMER_ID) || 'Simple
string
' FROM TB_CUSTOMER
Theodore David Williams
Ranch Hand
Posts: 102
posted 11 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
Please database agnostic. Ie I want one and only one (if possible) query that will work on oracle, MySQL and Postgres.
According to the docs CAST is a standard and implemented on all DBs just can't get this one query to work on MySQL.
Wendy L Gibbons
Bartender
Posts: 1111
I like...
posted 11 years ago
1
Number of slices to send:
Optional 'thank-you' note:
Send
If you want db agnostic you need to do it in
java
Paul Clapham
Marshal
Posts: 28193
95
I like...
posted 11 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
Here's a link to
the MySQL documentation for the CAST function
. Note that "varchar" isn't one of the types it supports as a result type. You would have to cast to char instead.
reply
reply
Bookmark Topic
Watch Topic
New Topic
Boost this thread!
Similar Threads
com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException
How to Get values from defined Data Type
Running a procedure in JDBC
Problem in retieving user defined datatypes
How to Convert type in sql or jasper i report
More...