Last 3 characters of a string
How to get the last 3 characters of a string occuring after a character / alphabet without using REGEXP_SUBSTR ?
Ex: 10000A001 is the string.
Note: - I want to use it in Oracle reports 6i, therefore i cannot use the statement REGEXP_SUBSTR
Sanjay
SELECT '1000'|| INITCAP ('a') || '001'
FROM DUALregards,
friend
Similar Messages
-
How do I drop the last 3 characters in a string?
Hello. I'm trying to find a way to drop the last 3 characters in a string. The length varies because it is a last name field. The problem is that when a customer has a suffix on their name, III for example, it is appended to the last name all in the last name field. If I use the ProperCase function, I end up with "Smith Iii". How can I tell it to drop the last 3 characters? I'll then append an UpperCase edition of the last 3 characters to that. Thank you!
Use the instring and right string functions then UpperCase
-
Trim last two characters of a String
Hi,
I have a task to trim the last two characters of a string in a column and get the rest as output for comparison purpose.
the length of column value is not fixed.
For example
I/p O/p
India_1 India
America_2 America
I achieved the result using the below query:
SELECT SUBSTR (TRIM ('India_1'), 1, LENGTH (TRIM ('India_1')) - 2) FROM DUAL;
I have used the trim function to remove the leading and trailing spaces in the column value.
Could somebody please let me know if there is a better way to get the result .. like in one shot query.
Thanks,
PratikI have a task to trim the last two characters of a string in a column
SQL> with t as (
select 'India_1' str from dual union all
select 'America_2' from dual
select regexp_replace(str, '..$') str1 from t
STR1
India
America
2 rows selected. -
how can i change the last 4 characters of a string to .txt?
Come, come. Have you not even bothered to look at the String api??????????????????
String s = "changeme";
s = s.substring(0, s.length()-4) + ".txt";Ta da....
Rob. -
Removing last 2 characters from string field
I am trying to remove the last 2 characters of a string field.
there is no consistant length in the field
316R1
12364R1
i want to remove everything after R
i tried instrrev but i that didnt do it.
is there a way to say
start position1 and go the R
thanksformula,
left (field, length_formula) is the solution
the length_formula is the number of chars form left
f.i
left(field, length (field)-2)
left (field, InstrRev, field,"R")
of course a combination with Right is also possible -
How can I select the last 2 chars of a string
Hello all,
I am trying to select the last 2 characters of a string to match them to another string. This is for a Poem generator that contains 20 or so words and I have to pick 2 words at random, them look at the last 2 characters to see if they match in each string. Say "Plain" and "Rain" would match because they both have "in" at the end. The length of each word could vary. I don't want this doing for me just what Method should I be looking at.
Thanks.hi,
try this:
public class StringTest {
public static void main(String args[]) {
StringTest obj = new StringTest();
obj.same();
void same() {
String rain = new String("Rain");
String plain = new String("Plain");
int rainLength = rain.length();
int plainLength = plain.length();
if(rain.substring(rainLength-2).equals(plain.substring(plainLength-2))) {
System.out.println("same");
else {
System.out.println("different");
}you can use the length method to get the length of a string and then use the substring method, passing it length-2, so get the last 2 chars. -
Hi Gurus,
I have a requirement to show only those values of an infoobject where,
First 2 characters are AB.I have written code for this and is working.
Additionally I need to show the values where the last 2 characters are PR.
How to write code for this part.
Please help.
Regards,
SunitaHi,
Write a simple code.
Suppose value is "ABCDPR".
DATA :V_CHAR type any,
v_char1 type c,
V_LENGTH type n.
v_lenght = strlen(v_char).
v_length = v_length - 2.
v_char1 = v_char+v_length(2).
This will give you the last two characters of the string.
- Jaimin -
Replace characters in a string
Hi,
I need to replace all occurrences of control characters except space,newline,tabs in a string . I can give a replace statement for each of these characters but I want to avoid this by making use of regular expressions. Can anyone help me in this regard.
I tried using the following replace statements with regular expression, but i am not getting the required results:
replace all occurrences of REGEX '[[:cntrl:]]' in lv_char with space replacement count lv_count_r.
---> this replaces even the spaces
replace all occurrences of REGEX '[[:cntrl:]][^[:space:]]' in lv_char with space replacement count lv_count_r.
--> this replaced even some alpha numeric characters
Thanks and Regards,
Shankaris there anyway to do this without using regular
expressions.. regular expressions are the last
solution for me..Remember that you can never really replace the characters of a String. Strings are immutable. Once created they cannot change. -
Validating Characters in a String
Hey everyone first post here, I have a question about validating characters in a string. I have a program where u need to enter an item code and it must have 2 letters in the begining and 3 numbers at the end, all one word.
Now I already have an error test to see whether or not the string is 5 characters and all that but i have no idea where to start on checking whether or not each character meets the criteria, i've thought of checking each character individually but I thought there had to be an easier way.yea right now i'm completley lost, i kind of
understand regex but i just have no idea how i would
type it out, Go step by step. You want a string that has five characters. The first
test could be this (let's call that string 'string' by lack of creativity):if (string == null || string.length() != 5) return false;This is the first test: if there is no string or if it doesn't contain five
characters, all bets are off. Here's the second test:for (int i= 0; i < 2; i++)
if (!Character.isLetter(string.charAt(i)))
return false;If the first two characters aren't letters the string is incorrect (according
to your specifications). Here's the last test:for (int i= 2; i < 5; i++)
if (!Character.isDigit(string.charAt(i)))
return false;If all those tests succeed, you simply do this:return true;All you have to do now is join these code fragments in a simple method
and you're in business. Comprendo, partner?
kind regards,
Jos -
How can I get last 3 characters of the record
Hello,
This statement [cdoe]select substr(password,1,3) from admin; is getting first 3 characters whereas I want to read last 3 characters
Best regardsTRy SUBSTR(string, -3):
SQL> -- generating sample table t
SQL> with t as (
2 select 'blabla' str from dual union
3 select 'yaddahyaddah' from dual
4 )
5 --
6 -- actual query:
7 --
8 select str
9 , substr(str, -3)
10 from t;
STR SUB
blabla bla
yaddahyaddah dah
2 rows selected. -
wondering.. anyone knows how to remove characters in a string
e.g.
string: applepie
after removing last 3 chars become "apple"
thanks...That of course will only work for this example. Better solution is to use indexOf() to locate the position of the string you wish to remove. If the string you wish to remove is in the middle, then you will have to do a bit of extra work and concat two substrings.
-
Need to check whether first two characters of a string is Alphabets or not
Hi,
Need to check whether first two characters of a string is alphabet or not.
Lets say for Ex,
String as 'DE123456' i need to check whether first character is non-numeric and then second character as non numeric.
kindly help me on this.
IF length(trim(p_parserec(31))) = 22 AND p_parserec(31) LIKE 'DE%' THEN
AUFTRAGGEBERKONTONR := trim(p_parserec(31)) ;
ELSIF (length(trim(p_parserec(31))) > 22 AND length(trim(p_parserec(31))) < 35) AND p_parserec(31) NOT LIKE 'DE%' THEN
AUFTRAGGEBERKONTONR := lpad(trim(p_parserec(31)), 34, 0) ;
ELSIF length(trim(p_parserec(31))) > 10 AND ascii(substr(p_parserec(31), 1, 2)) between 48 and 57 THEN
AUFTRAGGEBERKONTONR := lpad(trim(p_parserec(31)), 10, 0) ;
ELSE
p_errorcd := sqlcode ;
p_errordata := sqlerrm ;
END IF ;
Note : In the third else if condition the character should be greater than 10 and first 2 characters should not be alphabets.Siva.V wrote:
Need to check whether first two characters of a string is alphabet or not.
To this requirement only regexp_like will work too! No need of some other string function!
Like:-
-- in regexp_like last parameter shows to ignore case (optional).
SQL> with t as
2 (select 'AB123456' as key from dual union all
3 select 'CD234567' from dual union all
4 select 'A1234567' from dual union all
5 select 'A52H4341' from dual union all
6 select 'Dk274341' from dual union all
7 select 'DE234556' from dual)
8 select key
9 from t
10 where regexp_like(key,'^[A-Z]{2}','i') -- even '^[[:alpha:]]{2}' or '^\D{2}' pattern can be replaced for same result..
11 /
KEY
AB123456
CD234567
Dk274341
DE234556
Thanks! -
How to count number of repeated characters in a String
I have a String.... 10022002202222.
I need to know how many 2's are there in the string... here the string contains eight 2's..
Thanks in advance..it is workingYes, but... attention to surprises...
SQL> var v1 varchar2(1000);
SQL> exec :v1 := 'How to count the number of occurences of a characters in a string';
PL/SQL procedure successfully completed.
SQL> select length(:v1) - length(replace(:v1,'c')) from dual;
LENGTH(:V1)-LENGTH(REPLACE(:V1,'C'))
6
SQL> exec :v1 := 'cccccc';
PL/SQL procedure successfully completed.
SQL> select length(:v1) - length(replace(:v1,'c')) from dual;
LENGTH(:V1)-LENGTH(REPLACE(:V1,'C'))
SQL> select length(:v1) - nvl(length(replace(:v1,'c')),0) from dual;
LENGTH(:V1)-NVL(LENGTH(REPLACE(:V1,'C')),0)
6
SQL> -
How to search special characters in a string
Hi all,
I want to search special characters in all string columns and all rows in the table.
The table has about 5 string columns and about 5.000.000 rows. For each row and column, I have to search entries, which included special characters like ", !, ? or something else (f.ex. "Mama?Mia" or "!!!Hotel out of order!!!"). The problem, the character could stand at each position in the string.
What's the best and most performance possibility to search such entries?? Is it possibility only by SQL; is there a special function for this?? Or must I use PL/SQL.
Thanks for helping
DanaHTH
Laurent Schneider
OCM DBA
SQL> select * from z;
S
Mama?Mia
a b c
123
SQL> select * from z where translate(s,'~ABCDEFGHIJKLMNOPQRSTUVWXYZ abcdefghijklmnopqrstuvwxyz1234567890','~') is not null;
S
Mama?Mia
SQL> select * from z where regexp_like(s, '[^[:alnum:][:space:]]');
S
Mama?Mia -
Last two characters are cut out when entering data in a text form
Whenever I try leaving a comment on a page, it always cuts out the last two characters, and replaces them with "Pr". This happens across multiple browsers, (Chrome, FF, and Camino), but not Safari.
In addition, if a '<' character was put in, it'll cut out the last two characters in its code, and replace them with Pr again, leaving %Pr.
This happens on a mac (I'm posting for my friend who I talk to all the time).We did end up checking keyboard related settings in her Mac Preferences, but there wasn't anything related. I will end up trying Apple's forums if no one here can help. Anyways the "Pr" I believe might've come from the source code, as there is "editProfile" in the page. I don't really do web development, so I'd have no idea here. This is the page's source from around that area btw (I had to convert them to all HTML character codes because it kept parsing it):
<div class="clFloat"></div></div></div><div class="horizLine"><hr/></div><div 
class="dataSection"><a class="rt" id="addcmtlnk" 
href="javascript:void(0);">Add Comment</a><label>Comments</label><div id="postcmt" 
class="dataFrameHLFB hidden"><div class="userEntry"><div 
class="editProfile"><form ajaxify="1" action="http://www.onverse.com/profile/ajax/comments/add.php" 
method="POST"><input name="toid" type="hidden" 
value="70981" /><table class="frame" 
cellspacing="0"><tr><td class="imageCell"><div class="smallImgFrame"><a 
href="http://www.onverse.com/profile/profile.php?id=5414"><img src="http://photos.onverse.com/photo.php?size=2&amp;profile=5414" alt="Pluto 
is a Planet" 
title="Pluto is a 
Planet" /></a></div></td><td class="commentCell"><p><a 
class="user" href="http://www.onverse.com/profile/profile.php?id=5414">Pluto is 
a Planet</a></p><div class="editFrame"><textarea 
name="text"></textarea></div><div class="submit"><INPUT type="submit" 
value="Post Comment" /></div></td></tr></table></form></div></div></div><div 
id="moreDropGroup_ldt" class="hidden"><img src="http://staticdata.ovstatic.com/img/bar_loading.gif" 
alt=""/></div><div id="moreDropGroup"><script type="text/javascript">
And this is what it looked like to me: http://img442.imageshack.us/img442/5656/97668645.png
Thanks for your reply, I appreciate it!
Maybe you are looking for
-
I am getting this Error while trying to open the Open Document Syntax
SYNTAX ="<a href=\"http://<MyServerIP>:8080/BUSINESSOBJECTS/ENTERPRISE115/INFOVIEW/OpenDocument/opendoc/openDocument.jsp?sDocType=wid&sDocName=59813204&sWindow=New&sRefresh=Y&lsSParameter="URLEncode(""[Parameter])"\" title=\"\" target=\"_self\" nav=\
-
Creating Delivery based on the Inbound IDOC received.
Hi all, I have a requirement where in, Outbound Delivery for Sales order is to be created based on the inbound IDOC received from a third party. The standard idoc type DELIVERY03, requires the Delivery Number for updating the order but it cannot cre
-
Dear All, I have some code like this [EXAMPLE] select CASE WHEN customer_name = 'FRANK' THEN '1' END from customer_table; [EXAMPLE] What I would like to do is declare a variable and store the parameter FRANK in it, as FRANK is used through out my pro
-
hi , We are creating a RFC Funtion module to SOAP Webservices scenario. while executing FM thru SE37. I am getting following errors. I am not getting the error solution. pls suggest the solutions. the output says Exception SYSTEM_FAILURE Message ID:
-
My graphical display of converted hexadecimal numbers changes with every run!
Dear all, I've created a Vi that can select and convert hexadecimal numbers from a string array. These hexadecimal numbers contain acceleration data (units g). My string array (from line 68+) places every 10 rows a 1 line of hexadecimal number with a