Question re SUBSTR function
Greetings,
I have a text file with text formatted similarly to this in a variable V1...
I do not want this part,I want this part, I do not want this part.
I am trying to find a way to extract the segment between the two commas and am unable to figure out how to do this. The following code segment is the way I have started....
dbms_output.put_line(substr(V1,(instr(v1,',',1,1)+1),(instr(v1,',',1,2)-1)));
which of course doesn't work properly. Is there a straightforward way to get the length of the string between the two commas and use that in place of the fragment (instr(v1,',',1,2)-1))?
Suggestions greatly appreciated.
Thanks
Bill Wagman
Maybe this is helpful
with testdata as (Select 'abc,def,ghi' as str from dual)
select str,
REGEXP_SUBSTR (str, '[^,]*', 1, 1) "sub1",
REGEXP_SUBSTR (str, '[^,]*', 1, 2) "sub2",
REGEXP_SUBSTR (str, '[^,]*', 1, 3) "sub3",
REGEXP_SUBSTR (str, '[^,]*', 1, 4) "sub4"
from testdata;
STR sub1 sub2 sub3 sub4
abc,def,ghi abc def the * means zero or more repetitions (of any char). You could also write it like this '[^,]{0,}'the + means 1 or more repetitions (of any char) and could also be written as this '[^,]{1,}'REGEXP_SUBSTR works from left to right analyzing each character (or byte). Lets call each repetition of the pattern matching process a "word".
Whenever it meets a character that falls into the pattern, then this character is added to the "word".
As soon as a letter does not match the pattern anymore then it starts looking for a new word.
So let us take your string apart.
"a" => matches the pattern and is added to the word1. "a"
"b"=> matches the pattern and is added to the word1. "ab"
"c"=> matches the pattern and is added to the word1. "abc"
"," => does not match anymore. Therefore the word1 is finished. However this character could be the beginning of a new word.
"," => does match the condition "zero repetitions". Therefore it starts word2. But word2 so far is empty. Because the "not ," condition prevents this character to be included in the output.
"d" => does not match the condition "zero repetitions" for word2 anymore. Therefore word2 is finished.
"d" => matches the pattern and is added to the word3. "d"
"e" => matches the pattern and is added to the word3. "de"
and so on.
I know this explaination is a bit clumsy, but it might help to understand how the pattern matching progress is done.
Edited by: Sven W. on Mar 8, 2011 4:20 PM - improved indention of sample output
Similar Messages
-
Substring function for presentation variables in obiee
I have a presentation variable called period that has the (fromdate and to date)
Is there any way that I can split this one variable into 2 by using substring function??in such a way that it gives one for from date and the other for to date..
any synatx like
SUBSTRING ( '@{period} FROM 0 FOR POSITION
(' - ' IN '@{period})) ???
and how to apply this?The answer to this question is the same for the one you posted here:
can we create two dashboard prompts for the same column in the samepage
You need to split your prompts into two. If you read the link I posted in the other thread and re-posted here, you will find that the reason to do it this way is so you can see the values of the prompts. Read the first paragraph of this link -- again, if you already read it. You cannot split the single presentation variable if you use the BETWEEN operand in the dashboard prompt. You need to put the operand in the filter in your report.
http://oraclebizint.wordpress.com/2008/02/26/oracle-bi-ee-101332-between-prompts-for-date-columns-using-presentation-variables/ -
Hello -
I have the below string and need help with substring function.
String: AMERICAS\JOHN_NOLAN
1st Output Achieved: JOHN_NOLAN
Code used for 1st Output:
UPPER(SUBSTRING(ASSOC_NTWK_LOGIN,CHARINDEX('\',ASSOC_NTWK_LOGIN)+1,LEN(ASSOC_NTWK_LOGIN) - CHARINDEX('\',ASSOC_NTWK_LOGIN)))
2nd Output Needed: AMERICAS (From the string)
Please help.
SSHi,
Please try below solution:
CREATE TABLE #SUB
ASSOC_NTWK_LOGIN VARCHAR(50)
INSERT INTO #SUB(ASSOC_NTWK_LOGIN)
VALUES
('AMERICAS\JONH_NOLAN');
SELECT UPPER(SUBSTRING(ASSOC_NTWK_LOGIN,CHARINDEX('\',ASSOC_NTWK_LOGIN)+1,LEN(ASSOC_NTWK_LOGIN) - CHARINDEX('\',ASSOC_NTWK_LOGIN))) AS NAME
,UPPER(SUBSTRING(ASSOC_NTWK_LOGIN,0,CHARINDEX('\',ASSOC_NTWK_LOGIN))) AS LOGIN_NM
FROM #SUB
Regards,
Reshma
Please Vote as Helpful if an answer is helpful and/or Please mark Proposed as Answer or Mark As Answer when question is answered -
Substring Function is not working
Hi All
I am using substring function like below
SUBSTRING("Year"."Quarter" FROM 3 FOR 7) and its working,
but when I add any computed column like aany measure column from fact then it will show the error.
My datasoyrce is Essbse
Error Codes: OPR4ONWY:U9IM8TAC:OI2DL65P
+State: HY000. Code: 10058. [NQODBC] [SQL_STATE: HY000] [nQSError: 10058] A general error has occurred. [nQSError: 42043] An external aggregate is found in an outer query block. (HY000)+
SQL Issued: SELECT SUBSTRING("Year"."Quarter" FROM 3 FOR 7) saw_0, Market.State saw_1, CCoA.Assets saw_2 FROM localhost ORDER BY saw_0, saw_1_
Thanks to all for reply for previous questions
Hitesh
Edited by: user13805575 on Feb 24, 2011 10:47 AMHi,
try this.
SUBSTRING(cast(measure as char) FROM 3 FOR 7)Please ignore........ -
Informix- Oracle migration: OMWB misapplies SUBSTR function !!!
New problem occured:
OMWB translates Informix's substrings wrong:
Examples of translations:
INFORMIX ORACLE
wvs[1] SUBSTR(wvs,1)
wvs[2,10] SUBSTR(wvs,2,10)
wvs[10] SUBSTR(wvs,10)
It seems, that OMWB only copies index numbers in square brackets as parameters of Oracles's SUBSTR function. But SUBSTR works differently by string indexes closed to [] in Informix !
wvs[1] means 1-st character of wvs string, wvs[3,5] means substring from 3-rd to 5-th character of wvs (length 3), but SUBSTR(wvs,1) means substring from 1-st chracter to end of string, SUBSTR(wvs,3,5) means 5-characters long substring from 3-rd to 7-th character, e.t.c.
Vladimir Kubanka alias Bare Foot
nullWell, I obtained <process_id> from V$SESSION, (...WHERE audsid=to_number(sessid) , ... , sessid:= sys_context('USERENV','SESSIONID') ).
But problem: this process_id is not the same, which has some process, creating standard tracefile "ora_<process_id>_orcl.trc".
In case I run procedure from SQLPLUS, process_id was for example 3258 and trace file had name "ora_3259_orcl.trc". It seems that tracefile was created by some child process, called from sqlplus (having UNIX process_id 3258). But it means, that child's process_id could be bigger more than +1 (when more users works in the same time). And in case I run procedure from some Windows-oriented client on my PC, the <process_id> (obtained from V$SESSION as written above in procedure) had some nonsense value (for ex. 54823716) and tracefile I found under name "ora_3271_orcl.trc" - it seems that process, creating tracefile had normal UNIX-liked process_id 3271. From this issues questions:
1. Is there some way to obtain in procedure process_id, which creates that standard tracefile?
OR:
2. Is there some way to obtain (in procedure) name of that tracefile ? (written into directory defined in USER_DUMP_DEST parameter)
null -
Use of substr function will avoid the use of indexes in a table
i have one table which will contain some 3,00,000 records, it contains some 11 primary keys i am using some update statements to update some fields in the records (of 3,00,000 i will compare some 1,50,000 records with 1,50,000 another records) i am using substr function in all the select statements. whether usage of substr function will avoid the use of index
can any one clarify?contains some 11 primary keys by this I suppose you mean to say the table has a composite PK on 11 columns.
i am using substr function in all the select statementsCould you please post your SQL statement? -
Using substring function in the Universe
What is the correct syntax of using the substring function in the Universe?
I need to extract the numbers and decimal between the #'s, and the character length varies:
From: DOE, JOHN Added the following entry to work history:
A1S#0.25#
To: 0.25
Please help! Thanks!There are ticket details in the text - I replaced certain letters with x, o, or a. I thought you would need the total number of characters in the text.
0.25#"
DOE, JOHN A Xddxd xxx xxllxwOIg xIxxI xx wxxk xOXxxxI:
A1S#0.25#"O xxxxd Oxck xxxm CJ, xx XxOd xxxx wx xxx XuppxXxd xx Ox gxxxOIg xlxxxX xI xxOX. Xx, xxx quxXxOxI xxmxOIX wxxx xx dx Ixw? XOxxxx wx mxkx xxx dxcOXOxI xx OgIxxx xxOX cxIdOxOxI xId xxvx Ox xxmxvxd xxxm XmxxxX, xx wx xxI xx xxXxxxcx xxp xxlkxxX xId Xxx Ox wx cxI Xxxp Xxmx xx xxx xxxxxOc, xx wx xxdxx x OOggxx cOxcuOx xx xxIdlx xxx OuxXxX wOxxxux xII dxxpX. O'll xxI xx xuI xxOX OI mxIxgxmxIx xId xxx xxXx xx xxx xxxm xx Xxx wxOcx wxI wx wxIx xx gx".
1#"
DXX, JXXN X XddXd xxX xxllxAxng XnxrN xx Axrk xxAxxrN:
A1S#1#"X dxn'x AXX xxxA xn AxnAxrd. X AxA gxxng xx AxXAk xxX xnxXrxxAX xx AXX xx ApxkXA xn xxrxugxpux AXrX xbAXrvXd xA xxA bXXn AuggXAxXd, xxAXvXr, xxA nxx xn AxnAxrd. X AxXAkXd Dxrx xnd dxn'x AXX xnN xndxAxxxxn xxxx xxxA xA xn xnN xlxrI grxupA xxr xxrXAxxld Ixnxxxrxng, Ax X'I AxndXrxng AxXrX xxX xlxrI xA AxIxng xrxI. Xx Axuld bX xxxx xxXrX xA nx xnxXnxxxn xx bX xlxrIxng xn xxxA xx xll xnd xxX xlxrIA Axuld bX AxIxng xrxI xn xld Ixnxxxrxng AxurAX xxxx xA nx lxngXr vxlxd (xX, xxxA AlxppXd xxrxugx xxX ArxAkA AxIXxxA). X AXnx xn XIxxl xx AurxxA JxnXA xx AXX xx xX Axn xXll Axxx xxX AxurAX xx xxX xlxrI xA (xX, Axxx Ixnxxxrxng ANAxXI xAxuxllN gXnXrxxXd xxX xlxrI)."
0.5#
DOE, JOHN A Xaaxa xax OolloxixI xxxIx xo xoIk aisxoIx:
A1S#.05# "XIxxsOxIIixI xo IXS XixI x quxux OoI xaaixioxxl ixOoIoxxiox xxa Ixcoooaxxioxs." -
SUBSTR function in the where clause
HI
I want to get a number of 15 digits from a column where the user only know the last 10 digits.
So that when the user enter a number with 10 digits, only the record of that specific number should be displayed.
And then when the user did not enter any number all the records in the table should be displayed.(this part works fine)
The problem is: when the user enters any last digits( last, second last, thirth last and so on) the records which satisfy this are retrieved, which is not supose to be the case.
I' am trying to use the substr function in the where clause but I'm not sure if it's working or not becasue the result of the query is just the same as before i used the substr.
Thanksbetter to pad with '*' me thinks in case u have a number ending with 0's:
1 select empno,ename
2 from emp
3* where empno like '%'||lpad('&1',2,'*')
SQL> /
Enter value for 1: 0
old 3: where empno like '%'||lpad('&1',2,'*')
new 3: where empno like '%'||lpad('0',2,'*')
no rows selected
SQL> /
Enter value for 1: 00
old 3: where empno like '%'||lpad('&1',2,'*')
new 3: where empno like '%'||lpad('00',2,'*')
EMPNO ENAME
7900 JAMES
SQL> /
Enter value for 1:
old 3: where empno like '%'||lpad('&1',2,'*')
new 3: where empno like '%'||lpad('',2,'*')
EMPNO ENAME
7369 SMITH
7499 ALLEN
7521 WARD
7566 JONES
7654 MARTIN
7698 BLAKE
7782 CLARK
7788 SCOTT
7839 KING
7844 TURNER
7876 ADAMS
EMPNO ENAME
7900 JAMES
7902 FORD
7934 MILLER
14 rows selected. -
Substr function? extracting just the records with 4 digits?
have a column like this in a table
SZSCAPD_SEC_SCHOOL_CEEB
364775
460460
460240
2562
164625
460240
230969I need to be able to retrieve just the values with 4 digits like 2562 and add 00 at the front, so it will ended like 002562
I am thinking in the substr function, but it won't work, because I will be extracting the first 4 digits of each number.
How I will do this? I want to only retrieve the numbers with 4 digits Then I will concatenate the 00 in front.
Thank youHi,
peace4all wrote:
... How I will do this? I want to only retrieve the numbers with 4 digits One way to do that is
WHERE TRANSLATE ( szscapd_sec_school_ceeb
, '123456789'
, '000000000'
) = '0000'
Then I will concatenate the 00 in front.
'00' || szscapd_sec_school_ceebThis assumes that szscapd_sec_school_ceeb is a string.
If szscapd_sec_school_ceeb is a positive number, and you want to ignore any fractional part, use
WHERE szscapd_sec_school_ceeb >= 1000
AND szscapd_sec_school_ceeb < 10000to find the numbers and
TO_CHAR (szscapd_sec_school_ceeb, 'FM000000')to display them as 6 digits, with leading 0's.
Edited by: Frank Kulash on Aug 20, 2010 11:01 AM
Added NUMBER alternative. -
Substring function not working in Analytical view
Dear All,
I am trying to use substring function in my analytical view .It says valid expression during syntax check but getting activation error.
thanks
SouravHi Krishna,
This is Kiran, I am trying to restrict a (string) filed value by removing the spaces and wring to calculated column field in an Analytical view for position 6 - 10.
Example: Field name XYZ (Values showing as: ASDFG GETVALUENW 2345) --> (data type :22 VARCHAR)
Output Value must be : GETVALUENW (which is 10 characters, from position 6 after trimming)
Please advice which function use and how to apply the syntax
Your inputs are highly appreciated.
Thanks
Kiran. -
Substring Function without the length!
I know I have seen this before, but cannot find it when searching.
I need to do something similar to the Substring function, where I start from position 4, but the length behind this position is variable. Due to the IDOC it only passes the value...
I think I possibly saw a UDF for this somewhere - unless I can use some standard mapping!
It is probably very simple - but it is late in the day and my eyes are square! = )
<i> I need a drink......</i>
Can anyone help?
Message was edited by:
Barry NeavesFor substring function, you have 1 input and 2 parameters (you set the parameters by double-clicking the function box).
I also didn't understand how you can pass the output of length function two 2nd parameter of substring function (since it is a parameter and not an expected input).
You could always create a UDF...
public String UDSubstring(String a,String b,String c,Container container){
int d = Integer.parseInt(b);
int e = Integer.parseInt(c);
if ((e == 0) && (a.length() >= d)) {
return a.substring(d);
else if ((e > d) && (a.length() >= e)) {
return a.substring(d, e);
else return "";
They don't bite, you know...
Regards,
Henrique.
<b>Edit:</b> followed by Michal's correction... -
Hello Experts,
Iam a rookie in HFR. I needed to know how to implement the Substring functionality in Hyperion. Can anyone throw some light on this?thats a major drawback of hyperion financial reporting of not having any string functions. as per my knowledge there is none.
Let me know if you get to know of the same. Coz even I need it for couple of things in my reports.
regards,
rahul -
Substring Function in formula builder of transfer rule
Hi Gurus
I want to get the domain name from Email address.
For eg: if the email address is [email protected], i want to display only "yahoo.com" in the report.
For that, shall i use Substring function in transfer rule.
If so, please advice me how i can do this.
Thanks
SansenInstead try using a routine using the SPLIT function...
For example if you want to split the value of the field TEST whose value is [email protected] then try writing a code like below in the transfer routine...
DATA: TEST1(30), TEST2(30) TYPE C.
SPLIT TRAN_STRUCTURE-ZEMAILID AT '@' into TEST1 and TEST2.
RESULT = TEST2.
(value of TEST2 would be yahoo.com)
Hope this helps... -
Using substring function with error
Hi Guys,
I have a source field with 1200 characters which need to map to multiple target segments for 132 count of this source field.
This is not a mandatory field so it sometimes come without any value.
I am using substring function to breakout the string for every 132 characters and mapped to the target segments.
There are two problems, first it seems that if source is blank, there will be error.
Second, if source field come with only eg. 300 characters, error will also occurs.
I have searched thru SDN and try some of the UDF but to no avail.
Appreciate your guidance on this problem.
Regards
FNGH Rahul,
I have tried your quote but face some syntax error as follows
Function calculate, Line 6:
cannot find symbol symbol : method length() location: class java.lang.String[] j = input.length();
Function calculate, Line 26:
cannot find symbol symbol : method subString(int,int) location: class java.lang.String[]
result.addValue(input.subString(0,EndIndex)); ^
Function calculate, Line 34:
cannot find symbol symbol : method subString(int,int) location: class java.lang.String[] result.addValue(input.subString(StartIndex,EndIndex)); ^
Function calculate, Line 40:
cannot find symbol symbol : method subString(int,int) location: class java.lang.String[] result.addValue(input.subString(StartIndex,EndIndex)); ^ Note: /usr/sap/D03/DVEBMGS00/j2ee/cluster/server0/./temp/classpath_resolver/Mapd66a3a60002911e09ba9e41f132d6b68/source/com/sap/xi/tf/_MM_MT_COMS_TO_ZME_CRE_CHG_CONTRACT_.java uses or overrides a deprecated API. Note: Recompile with -Xlint:deprecation for details. Note: /usr/sap/D03/DVEBMGS00/j2ee/cluster/server0/./temp/classpath_resolver/Mapd66a3a60002911e09ba9e41f132d6b68/source/com/sap/xi/tf/_MM_MT_COMS_TO_ZME_CRE_CHG_CONTRACT_.java uses unchecked or unsafe operations. Note: Recompile with -Xlint:unchecked for details. 4 errors -
Can I use substring function in DDL? I want to get the prot_id column by combining rest of the columns. Please help me whether I can write like this or any way is there?
create table testsyn(
lega_sty_nr VARCHAR2(6),
col_cd VARCHAR2(6),
del_cd VARCHAR2(2),
prot_id VARCHAR2(60) as
(select SUBSTR(
CASE WHEN(LENGTH(lega_sty_nr) > 0)
THEN lega_sty_nr||'_'||col_cd||'_'||del_cd
ELSE NULL
END )
)No.
+(inspired by Alex ;) )+
edit:
You need to explain more clearly what you're trying to do.
Why the substr?
SQL> create table testsyn(
2 lega_sty_nr VARCHAR2(6),
3 col_cd VARCHAR2(6),
4 del_cd VARCHAR2(2),
5 prot_id VARCHAR2(60) as
6 (select SUBSTR(
7 CASE WHEN(LENGTH(lega_sty_nr) > 0)
8 THEN lega_sty_nr||'_'||col_cd||'_'||del_cd
9 ELSE NULL
10 END )
11 );
prot_id VARCHAR2(60) as
ERROR at line 5:
ORA-00907: missing right parenthesisEdited by: hoek on Jun 10, 2009 11:56 AM
Maybe you are looking for
-
Setting the Administrator password on a MDT Server Task Sequence
I've created a SCCM 2012 R2 CU3 MDT 2013 task sequence using the Server Task Sequence template to deploy Windows Server 2012 R2. I'm not doing a capture but just using the .wim file from the source DVD. The problem I'm having is setting the local adm
-
Mapping debug - target node not being created
Hi Gurus, I have an issue in my mapping. Let's say I have a source structure: ><body> > <maintag> > <value>1</value> > </maintag> > <maintag> > <value>2</value> > </maintag> ><body> I need to map maintag->target node but only in case if val
-
OS X Yosemite 10.10.2, Macbook Air, Finder batch file rename function. I have multiple files I want to rename, that have a date in their name in the mm/dd/yy format. The slashes seem to freak out the batch rename function and it won't work. I took o
-
Exporting my movie to Windows Media File
I am trying to export a thirty second movie to a Windows Media file in Final Cut Express. However, every time I export it, it only does the first 14 seconds and I do not know why. My in and out points on the timeline are at the beginning and end of t
-
Does Mac OS X Vers 10.5.8 need new bluetooth driver to recognize Motorola HX550?
Have read and followed all instructions as well as posts here and nothing works. Motorola suggested I need new bluetooth driver but cant find any info. Help appreciated.