Code Newbie
News     Forums     Search     Members     Sign Up    

My Code Newbie
Username

Password

Articles/Snippets
ASP Classic
ASP.NET
C
C#
C++
HTML / CSS
Java
Javascript
Linux / BSD
Perl
PHP
Python
Ruby
SQL
VB 6
VB.NET

C.N. Friends
  Planet Rome

Link to Us!
Code Newbie
  Code Newbie
    forums
Go Back   Code Forums > Application and Web Development > Everything SQL ( MySQL, MSSQL, DB2, Postgre, Oracle, etc...)
User Name
Password

Reply
 
LinkBack Thread Tools Display Modes
Old 10-18-2007, 08:56 AM   #1 (permalink)
aliaga61
Recruit
 
Join Date: Oct 2007
Posts: 2
aliaga61 is on a distinguished road
pl/sql truncating string after character

i have a value from a database field which is formatted as 123-45. I want to take 123 and assign it to variable a, and 45 and assign it to variable b, but I can't find what I need to do this. can i use the ltrim and rtrim functions? the problem is that the values left and right of the '-' can vary in length.
__________________
aliaga61 is offline   Reply With Quote
Old 10-19-2007, 08:14 AM   #2 (permalink)
redhead
Newbie
 
redhead's Avatar
 
Join Date: Jun 2002
Location: Denmark
Posts: 1,680
redhead is on a distinguished road
You need to use a split function, with '-' as the defined delimiter.
__________________
Don't worry Ma'am, We're university students, We know what We're doing.
-----
If you pull the pin, Mr.Grenade would no longer be your friend.
-----
01000111 01101111 00100000 01000011 00100000 00100001
redhead is offline   Reply With Quote
Old 10-23-2007, 07:16 AM   #3 (permalink)
technobard
Centurion Nova Prime
 
technobard's Avatar
 
Join Date: May 2002
Location: Oak Park, IL (USA)
Posts: 284
technobard is on a distinguished road
Another solution, using built-in Oracle functions, is to use the INSTR function to find the position of the '-' and then use the SUBSTR function to return portions of the string relative to the '-' position. For example:

select substr('123-45',1,instr('123-45','-',1,1)-1) from dual

will return: 123

instr('123-45','-',1,1) finds the first occurrence of '-' in the string starting with position 1. In the example above, I substract 1 from that position and use that as the end location of the string to the left of the '-'.
__________________
It takes 2 points to draw a straight line, but at least 3 points to draw a conclusion.
technobard is offline   Reply With Quote
Old 10-23-2007, 08:26 AM   #4 (permalink)
aliaga61
Recruit
 
Join Date: Oct 2007
Posts: 2
aliaga61 is on a distinguished road
thank you both. the instr option fit my situation a little better.
__________________
aliaga61 is offline   Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Help for another program Androto Standard C, C++ 54 10-15-2004 07:21 AM
From C to Java HighterDK Java 11 07-13-2004 07:15 PM
String Functions rdove ASP Classic 0 03-24-2004 07:45 PM
Character String Number rdove Code Wars ( One Language vs Another ) 13 12-18-2003 08:46 AM
Logging into a Password Protected Site technobard Java 0 02-24-2003 01:19 PM


All times are GMT -8. The time now is 07:29 PM.


Powered by vBulletin Version 3.6.2
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.0.0 RC8





Copyright © 2000-2006, Milano Interactive
Web Hosting provided by Portal 360 Web Hosting
Open Circle