Substr with instr
Hi Gurus,
Please let me know how to pick the numbers in between these words like ( '123.22.111','111.123.12','124.1.1').
for above query i want the answer should be (22,123,1)
And I would like to pick the number in between dots. Sometimes its two number and some times its three numbers or some time its one number.
Please let me know.
Thanks in advance.
RS
SELECT
trim(both '.' from REGEXP_SUBSTR(token,'\.[^,]+\.'))
from(
SELECT LEVEL
, SUBSTR
( STRING_TO_TOKENIZE
, DECODE(LEVEL, 1, 1, INSTR(STRING_TO_TOKENIZE, DELIMITER, 1, LEVEL-1)+1)
, INSTR(STRING_TO_TOKENIZE, DELIMITER, 1, LEVEL) -
DECODE(LEVEL, 1, 1, INSTR(STRING_TO_TOKENIZE, DELIMITER, 1, LEVEL-1)+1)
)token
FROM ( SELECT q'('123.22.111','111.123.12','124.1.1')'||',' AS STRING_TO_TOKENIZE
, ',' AS DELIMITER
FROM DUAL
CONNECT BY INSTR(STRING_TO_TOKENIZE, DELIMITER, 1, LEVEL)>0
ORDER BY LEVEL ASC);
Similar Messages
-
How to Split the string using Substr and instr using loop condition
Hi every body,
I have below requirement.
I need to split the string and append with single quotes('') followed by , (comma) and reassign entire values into another variable. so that i can use it where clause of update statement
for example I am reciveing value as follows
ALN varchar2(2000):=(12ERE-3MT-4Y,4IT-5O-SD,OP-K5-456,P04-SFS9-098,90P-SSF-334,3434-KJ4-O28,AS3-SFS0-J33,989-3KL-3434);
Note: In the above variable i see 8 transactions, where as in real scenario i donot how many transaction i may recive.
after modification i need above transactions should in below format
ALTR Varchar2(2000):=('12ERE-3MT-4Y','4IT-5O-SD','OP-K5-456','P04-SFS9-098','90P-SSF-334','3434-KJ4-O28','AS3-SFS0-J33','989-3KL-3434');
kindly help how to use substr and instr in normal loop or for loop or while loop while modifying the above transactions.
Please help me to sort out this issue.
Many Thanks.
Edited by: user627525 on Dec 15, 2011 11:49 AMTry this - may not be the best way but...:
create or replace type myTableType as table of varchar2(255)
declare
v_array mytabletype;
v_new_str varchar2(4000);
function str2tbl
(p_str in varchar2,
p_delim in varchar2 default '.')
return myTableType
as
l_str long default p_str || p_delim;
l_n number;
l_data myTableType := myTabletype();
begin
loop
l_n := instr( l_str, p_delim );
exit when (nvl(l_n,0) = 0);
l_data.extend;
l_data( l_data.count ) := ltrim(rtrim(substr(l_str,1,l_n-1)));
l_str := substr( l_str, l_n+length(p_delim) );
end loop;
return l_data;
end;
begin
v_array := str2tbl ('12ERE-3MT-4Y,4IT-5O-SD,OP-K5-456,P04-SFS9-098,90P-SSF-334,3434-KJ4-O28,AS3-SFS0-J33,989-3KL-3434', ',');
FOR i IN 1 .. v_array.COUNT LOOP
v_new_str := v_new_str || ''''||v_array(i)||'''' || ',';
END LOOP;
dbms_output.put_line(RTRIM(v_new_str, ','));
end;
OUTPUT:
=======
'12ERE-3MT-4Y','4IT-5O-SD','OP-K5-456','P04-SFS9-098','90P-SSF-334','3434-KJ4-O28','AS3-SFS0-J33','989-3KL-3434'HTH
Edited by: user130038 on Dec 15, 2011 12:11 PM -
Hello all,
I need help in simple query how can show only MCCODE
SELECT SUBSTR('VMTOPIC=MCCODE', INSTR('VMTOPIC=MCODE', 'VMTOPIC=')+8,20) AS output FROM DUAL;But also when i used
SELECT SUBSTR('VMTOPIC=MCCODE', INSTR('VMTOPIC=MCODE', 'HHH')+8,20) AS output FROM DUAL;show same results, what i need only if words begin with " VMTOPIC= " retrived characters after "VMTOPIC=".
regards
DheyaHi, Dheya,
Here's one way:
SELECT SUBSTR ( str
, INSTR ( str || 'VMTOPIC='
, 'VMTOPIC='
) + 8
, 20 -- or omit this argument
) AS output
FROM table_x
;where tabe_x.str is the string you need to test.
You could also do this with REGEXP_SUBSTR or REGEXP_REPLACE, but you can do this easily enough without any slow regular expressions.
973907 wrote:
... But also when i used
SELECT SUBSTR('VMTOPIC=MCCODE', INSTR('VMTOPIC=MCODE', 'HHH')+8,20) AS output FROM DUAL;show same results, what i need only if words begin with " VMTOPIC= " retrived characters after "VMTOPIC=".That's because 'HHH' wasn't found, and so INSTR returned 0. SUBSTR treats 0 like 1 in its 2nd argument, so, using that expresssion, not fnding the string is te same as finding it at position 1.
Of couse, looking for 'HHH' in a string that cotains 'VMTOPIC=' isn't the problem here; the real problem is looking for 'VMTOPIC=' in a string that doesn't contain it.
Making a special case when INSTR returns 0, as Solomon suggested, is one way to get around the problem. Another is what I posted above, which guarantees that INSTR will never return 0. If the 'VMTOPIC=' is not found in str, then lookng for it in str || 'VMTOPIC=' will cause INSTR to return a very high number; so high that SUBSTR will then return NULL.
I hope this answers your question.
If not, post CREATE TABLE and INSERT statements for a little sample data (maybe 5 rows), and the results you want from that data.
Point out where the query above is producing the wrong results, and explain, using specific examples, how you get those results from the sample data in those places.
Always say what version of Oracle you're using (e.g. 11.2.0.2.0).
See the forum FAQ {message:id=9360002} -
Hi Gurus,
I have the data as follows:
data
'BIDIE01H/TXT:ZUNE=HA011, CellIndex=144 /CAI:452-01-32201-47001/CAI:45201F7dc9b79a'
'BIDIE01H/TXT:ZUNE=HA111, CellIndex=124 /CAI:452-01-32201-471/CAI:45201F7dc9b79b'
and I am trying to write a SQL to get the results:
CAI
452-01-32201-47001
452-01-32201-471
Any idea to get it done? I did try around with SUBSTR and INSTR functions but not yet sucessed.
Thanks,
Alexselect substr (str, instr (str, '/CAI:') + 5
, (instr (str, '/CAI:', -1) - instr (str, '/CAI:'))-5
from dataas in
SQL> with data
2 as
3 (select 'BIDIE01H/TXT:ZUNE=HA011, CellIndex=144 /CAI:452-01-32201-47001/CAI:45201F7dc9b79a' str from dual union all
4 select 'BIDIE01H/TXT:ZUNE=HA111, CellIndex=124 /CAI:452-01-32201-471/CAI:45201F7dc9b79b' from dual
5 )
6 select substr (str, instr (str, '/CAI:') + 5
7 , (instr (str, '/CAI:', -1) - instr (str, '/CAI:'))-5
8 )
9 from data
10 /
SUBSTR(STR,INSTR(STR,'/CAI:')+5,(INSTR(STR,'/CAI:',-1)-INSTR(STR,'/CAI:'))-5)
452-01-32201-47001
452-01-32201-471 -
Substr and instr for variables assginement in a csv file
Hi gurus
Belows is my input csv file like with no fixedl enght
vinput_file:
WESTERN SAHARA,Moroccan Dirham,MAD,504,2,
YEMEN,Yemeni Rial,YER,886,2,
ZAMBIA,Zambian Kwacha,ZMW,967,2,
ZIMBABWE,Zimbabwe Dollar,ZWL,932,2,
and i want to assign 3 letter alphabetical to DESC and the 3 digit numerical to CODE
CODE := SUBSTR(vinput_rec,1,INSTR(vinput_file,',',1,1)-1);
DESC := SUBSTR(vinput_rec, INSTR(vinput_file,',',1,1)+1);
can anyone help me please with the above kindlyHi,
Sorry, it's not clear what you want.
975482 wrote:
Hi gurus
Belows is my input csv file like with no fixedl enghtIf you read the file as an external table, each comma-delimited substring will be a column. It should be easy to use SUBSTR on those columns
vinput_file:
WESTERN SAHARA,Moroccan Dirham,MAD,504,2,
YEMEN,Yemeni Rial,YER,886,2,
ZAMBIA,Zambian Kwacha,ZMW,967,2,
ZIMBABWE,Zimbabwe Dollar,ZWL,932,2,
and i want to assign 3 letter alphabetical to DESC and the 3 digit numerical to CODE
CODE := SUBSTR(vinput_rec,1,INSTR(vinput_file,',',1,1)-1);
DESC := SUBSTR(vinput_rec, INSTR(vinput_file,',',1,1)+1);
can anyone help me please with the above kindlyIf str is a comma-delimited string, and you want to the first 3 characters after the N-th comma, then you can use
SUBSTR ( str
, 1 + INSTR (str, ',', 1, n)
, 3
)Do you need to worry about not having 3 characters between the N-th comma and the next one? What if there are fewer than N commas?
I hope this answers your question.
If no, what is your question?
Does it involve reading a csv file that is not already in a table? Post a small sample file.
Does your qestion involve parsing strings that are already in a table? Post CREATE TABLE and INSERT statements.
In any case, post the exact results you want from the given data.
See the forum FAQ {message"id=9360002} -
Dear all,
I am very new to oracle. I am learning oracle now. I have small doubt could any one can help me.
I have a string like 'robert alias: 09-047 position now: CLARK'
now i need to store the word
'09-047' in to a variable x
and clark in to a variable y
i.e in X i have to store from the word 'robert alias:' till before the word 'position now:' then my out put is ' 09-047 '.
for this i tried as below
select trim(substr('robert alias: 09-047 position now: CLARK',
instr('robert alias: 09-047 position now: CLARK',':',1)+1)) from dual;
I am getting the o/p as '09-047 position now:: CLARK'
But i have to get '09-047' only. For that i need to give the 3rd parameter i.e length of the string.
In my substring i used only 2parameter i.e string and position now i have to give the length.
Could you please help me.
Thanks & Regards
Diliptest@ORA10G>
test@ORA10G> with t as (
2 select 'robert alias: 09-047 position now: CLARK' x from dual)
3 --
4 select x,
5 substr(x,instr(x,':',1,1)+2,instr(x,' position now')-instr(x,':',1,1)-2) y,
6 substr(x,instr(x,':',1,2)+2) z
7 from t;
X Y Z
robert alias: 09-047 position now: CLARK 09-047 CLARK
test@ORA10G>
test@ORA10G>isotope -
Hi,
I have column which is having values like
EMEA/MEA/IT
EMEA/WE/GE
EMEA/MEA/SA
EMEA/WE/jk
but i need to get all these rows based on some front selected values where we will select like EMEA/MEA & EMEA/WE.But that value will be ';' separated like EMEA/MEA%;EMEA/WE%.Based on this value l need to retrieve all the rows based on this value (Note ';' as the delimiter) .I tried with INSTR , but not able to sort out.
Could some one please me on this one how to make this condition in my query.
Thanks,Thanks Frank for your response.
Table will have thousands of rows where column which I comparing(OU_DIV_REG) will be like with many combination's.I am attaching some data for reference.
EMEA/DIV/
EMEA/DIV/HYP
EMEA/EE
EMEA/EE&CIS
EMEA/EE&CIS/
EMEA/EE&CIS/CENT
EMEA/EE&CIS/CIS
EMEA/EE&CIS/GR
EMEA/EE&CIS/RO
EMEA/EE&CIS/RTG
EMEA/EE&CIS/SBL
EMEA/EE&CIS/SEES
EMEA/EE&CIS/TR
EMEA/EMEA_OTM/
EMEA/FMEA/FR
EMEA/FMEA/MEA
EMEA/IL
EMEA/MEA
EMEA/MEA/
EMEA/MEA/EG
EMEA/MEA/SA
EMEA/MEA/ZA
EMEA/NE/BLX
EMEA/SE
EMEA/SE/ALPS
EMEA/SE/IBE
EMEA/UK
EMEA/UK/
But I am using this condition in APEX.Actually I have a report with return query and that will execute. I need this condition to be in where clause.I am attaching my APEX report query for your reference. I updating that where clause condition in BOLD letters where i need to add this condition that will consider all the rows from the table wherever input from APEX page will be like fallowing with ';' as delimter.
EMEA/MEA%;EMEA/EE&CIS%
Considering this input values, I need to consider all the rows above where that column value us having EMEA/MEA% and EMEA/EE&CIS%.
I tried adding the where clause which in BOLD letter (cluster condition).Please let me know will it work or also I need to how to add these XMLtable separation based on ',' in where clause.
For you reference I am just my full report query(which is not needed i know - but just have the full understanding).
DECLARE
lc_query VARCHAR2(4000);
BEGIN
lc_query := 'SELECT INITCAP(SUBSTR(end_cli_name,1,20)) Customer
,DECODE(cps_id,NULL,INITCAP(SUBSTR(title,1,20)),''<a href="http://cpotsi.oraclecorp.com/pls/cpotsiweb/CPOTSI.EP_WITHDRDTA_RAG_L.show_cps?p_cps_id=''||cps_id||''&p_uptodate=''||:P_DD||''" target=_blank>''||INITCAP(SUBSTR(title,1,20))||''</a>'') Project
,ou_ctry_code
,funding_amnt
,budgeted_margin_amnt
,TO_NUMBER(eac_margin_amnt)
,decode(substr(PREV_CPS_RAGU_L_1,1,1),
''R'',''<img src="#APP_IMAGES#red.jpg" alt="Red">'',
''A'',''<img src="#APP_IMAGES#amber.jpg" alt="Amber">'',
''G'',''<img src="#APP_IMAGES#green.jpg" alt="Green">'',
''U'',''<img src="#APP_IMAGES#unknown.jpg" alt="Unknown">'',
''<img src="#APP_IMAGES#unknown.jpg" alt="Unknown">'') RAGU
FROM emea_pmr_disco_input WHERE
month=:P_SELECTED_MONTH
AND year=:P_SELECTED_YEAR
AND region IN (SELECT region_code
FROM emea_pmr_regions
START WITH ( INSTR('':''||:P_SELECTED_REGION||'':'','':''||region_code||'':'',1,1) > 0 )
CONNECT BY PRIOR region_code=parent_region_code)
AND prof_com_text LIKE :P_SELECTED_INDUSTRY ';
IF :P_SELECTED_CLUSTER <> '%' THEN
lc_query := lc_query ||
*' AND upper(ou_div_reg) LIKE ''*
SUBSTR(:P_SELECTED_CLUSTER,1,INSTR(:P_SELECTED_CLUSTER,'';'',1,1)-1 )'' OR
upper(ou_div_reg) LIKE ''
SUBSTR(:P_SELECTED_CLUSTER,INSTR(:P_SELECTED_CLUSTER,'';'',1,1)+1,(INSTR(:P_SELECTED_CLUSTER,'';'',1,2) - (INSTR(:P_SELECTED_CLUSTER,'';'',1,1)-1) ) ) ''
OR upper(ou_div_reg) LIKE ''
SUBSTR(:P_SELECTED_CLUSTER,INSTR(:P_SELECTED_CLUSTER,'';'',1,2)+1,(INSTR(:P_SELECTED_CLUSTER,'';'',1,3) - (INSTR(:P_SELECTED_CLUSTER,'';'',1,2)-1) ) ) ''
OR upper(ou_div_reg) LIKE ''
SUBSTR(:P_SELECTED_CLUSTER,INSTR(:P_SELECTED_CLUSTER,'';'',1,3)+1,(INSTR(:P_SELECTED_CLUSTER,'';'',1,4) - (INSTR(:P_SELECTED_CLUSTER,'';'',1,3)-1) ) ) ''
OR upper(ou_div_reg) LIKE ''
SUBSTR(:P_SELECTED_CLUSTER,INSTR(:P_SELECTED_CLUSTER,'';'',1,4)+1,(INSTR(:P_SELECTED_CLUSTER,'';'',1,5) - (INSTR(:P_SELECTED_CLUSTER,'';'',1,4)-1) ) ) ''
OR upper(ou_div_reg) LIKE ''
SUBSTR(:P_SELECTED_CLUSTER,INSTR(:P_SELECTED_CLUSTER,'';'',1,5)+1,(INSTR(:P_SELECTED_CLUSTER,'';'',1,6) - (INSTR(:P_SELECTED_CLUSTER,'';'',1,5)-1) ) ) ''
OR upper(ou_div_reg) LIKE ''
SUBSTR(:P_SELECTED_CLUSTER,INSTR(:P_SELECTED_CLUSTER,'';'',1,6)+1,(INSTR(:P_SELECTED_CLUSTER,'';'',1,7) - (INSTR(:P_SELECTED_CLUSTER,'';'',1,6)-1) ) ) ''
END IF;
IF :P1_TIER2 <> '%' THEN
lc_query := lc_query || ' AND INSTR('';''||upper(:p1_tier2)||'';'','';''||upper(T2)||'';'',1,1) > 0 ';
END IF;
IF :P1_TIER3 <> '%' THEN
lc_query := lc_query || ' AND INSTR('';''||upper(:p1_tier3)||'';'','';''||upper(T3)||'';'',1,1) > 0 ';
END IF;
IF :P1_TIER4 <> '%' THEN
lc_query := lc_query || ' AND INSTR('';''||upper(:p1_tier4)||'';'','';''||upper(T4)||'';'',1,1) > 0 ';
END IF;
IF :P_SELECTED_COUNTRY <> '%' THEN
lc_query := lc_query || ' AND INSTR('';''||upper(:P_SELECTED_COUNTRY)||'';'','';''||upper(ou_ctry_code)||'';'',1,1) > 0 ';
ELSE
IF :P_IS_ADMIN = 'N' THEN
lc_query := lc_query || 'AND ou_ctry_code IN (SELECT country_code
FROM emea_pmr_user_countries
WHERE INSTR('':''||:P_SELECTED_REGION||'':'','':''||region_code||'':'',1,1) > 0
AND user_id = :P_SELECTED_USER_ID
AND view_access = ''Y'') ';
END IF;
END IF;
IF :P_TOPMARLOV='Current' THEN
lc_query := lc_query || ' AND UPPER(ep_state_name)=''STARTED''';
ELSIF :P_TOPMARLOV='Closed' THEN
lc_query := lc_query || ' AND UPPER(ep_state_name)=''CLOSED''';
END IF;
IF:P1_MARGIN_STATUS='R' THEN
lc_query := lc_query || ' AND
UPPER(substr(PREV_CPS_RAGU_L_1,1,1))=''R''';
ELSIF:P1_MARGIN_STATUS='G' THEN
lc_query := lc_query || ' AND
UPPER(substr(PREV_CPS_RAGU_L_1,1,1))=''G''';
ELSIF:P1_MARGIN_STATUS='A' THEN
lc_query := lc_query || ' AND
UPPER(substr(PREV_CPS_RAGU_L_1,1,1))=''A''';
ELSIF:P1_MARGIN_STATUS='U' THEN
lc_query := lc_query || ' AND
UPPER(substr(PREV_CPS_RAGU_L_1,1,1))=''U''';
END IF;
htp.p(lc_query);
RETURN lc_query;
END; -
Substri and instr problem --Please help
Hi ,
I would like to get the find tablename starts with 'EXP' using substring and instring . I am using oracle 9i. Please help me out
Example : 'Schema.explogtable'
I will use table name ' EXP' in one of my procedure as input parameter to procedure
If tablename= substr('schema.explogtable','instr('schema.explog','.',1,3) then
Execute Procedure1('tablename')
Else
Execute procedure2('tablename')
I would appreciate your help
Regards,
ClarkcClarkC,
Here just replace procedure1 and procedure2 with your procedure names;
create table temp_table
( table_name varchar2(30)
insert into temp_table values ('TESTME.MY_OBJECTS');
insert into temp_table values ('TESTME.OBJECTS');
insert into temp_table values ('ABC.ECFOBJECTLOG');
insert into temp_table values ('XYZ.BDEOBJECTTABLE');
insert into temp_table values ('ABC.ABCTABLE');
insert into temp_table values ('ZYD.CLIENTTABLE');
insert into temp_table values ('NMS.CLIENTLOGTABLE');
COMMIT;
pl/sql anonymous blocks I defined 2 variables for readibility and understanding
DECLARE
CURSOR tcur
IS
SELECT table_name
FROM temp_table;
table_name VARCHAR2 (40);
my_table VARCHAR2 (40);
BEGIN
FOR cur IN tcur
LOOP
my_table := NULL;
my_table := cur.table_name;
table_name := SUBSTR (my_table, INSTR (my_table, '.') + 1);
IF (table_name LIKE ('%OBJ%'))
THEN
DBMS_OUTPUT.put_line ('table_name containing OBJ=' || table_name);
-- NOTE : CALL YOUR PROCEDURE1 HERE for tables containing OBJ;
procedure1(table_name);
ELSE
DBMS_OUTPUT.put_line('table_name not containing OBJ=' || table_name);
-- NOTE : CALL YOUR PROCEDURE2 HERE for tables not containing OBJ;
procedure2(table_name);
END IF;
END LOOP;
EXCEPTION
WHEN OTHERS
THEN
DBMS_OUTPUT.put_line (SUBSTR (SQLERRM, 1, 300));
RAISE;
END;
Here is the output of the above block
table_name containing OBJ=MY_OBJECTS
table_name containing OBJ=OBJECTS
table_name containing OBJ=ECFOBJECTLOG
table_name containing OBJ=BDEOBJECTTABLE
table_name not containing OBJ=ABCTABLE
table_name not containing OBJ=CLIENTTABLE
table_name not containing OBJ=CLIENTLOGTABLEHope this helps
Regards
Edited by: OrionNet on Jan 17, 2009 11:48 AM -
How to do substring with Expression Builder
Hi,
I only execute a substring with Expression Builder, this is possible?
thanxHi!
With Expression Builder it is not possible as the EL by default does not have such function.
But you may:
1. Use JSTL 1.2 functions like "${fn:trim(' MYSTRING '}"
2. Write your own function and TagLib - see on net
Also, you may write a custom Map implementation and expose it in some backing bean to make it available in EL without need to create TagLib (as #{mybean.trim[' some string ']"). But this way is much complex if you need more than singe parameter for your function...
Regards,
PaKo -
IIF with InStr and LEFT -1 Causes #Error in SSRS 2008R2
Hello,
I'm using IIF with InStr to test for a "/" in a field on a report. The left function works fine unless I try to subtract 1 from it. This code works fine:
=IIF(InStr(Fields!WellCompName.Value,"/")=0, Fields!WellCompName.Value, left(Fields!WellCompName.Value,InStr(Fields!WellCompName.Value,"/")))
But this code causes the True condition to yield #Error in the report when I add the -1 to the end of the left function:
=IIF(InStr(Fields!WellCompName.Value,"/")=0, Fields!WellCompName.Value, left(Fields!WellCompName.Value,InStr(Fields!WellCompName.Value,"/")-1))
I do need -1 to remove the "/" but it doesn't work with IFF and LEFT.
ThanksHi SomeDBGuyOutThere,
I have tested on my local environment and can reproduce the issue, your issue caused by when the value in the field WellCompName don't contains "/". the function "left(Fields!WellCompName.Value,InStr(Fields!WellCompName.Value,"/")-1)"
in the expression is invalid and will caused the error.
In your scenario, please modify the second expression as below to avoid the error when there is no "/" in the string:
=IIF(InStr(Fields!WellCompName.Value ,"/")=0,
Fields!WellCompName.Value,
left(Fields!WellCompName.Value,InStr(IIF(InStr(Fields!WellCompName.Value,"/")=0,"Test1/Test2",Fields!WellCompName.Value),"/")-1))
Note: when WellCompName don't include "/" we given an test string "Test1/Test2" in the expression to avoid the error.
If you still have any problem, please feel free to ask.
Regards,
Vicky Liu
Vicky Liu
TechNet Community Support -
Another EQL question. Is there an equivalent to substr or instr in EQL?
Edited by: bewise on Jun 28, 2012 5:39 PMNot at this time. Check out the v2.3 EQL language reference guide here for more details.
http://docs.oracle.com/cd/E29805_01/QueryLangRef.pdf -
I am trying use INSTR and SUBSTR function to parse a variable without breaking up the variable. As you can see the problem arises negotiating the blank space,
DECLARE
blank_space NUMBER(2);
full_name VARCHAR2(30) := 'Robert P. Simmons');
first_name VARCHAR2(30);
last_name VARCHAR2(30);
BEGIN
blank_space := INSTR(full_name, ' ');
first_name := SUBSTR(full_name, 1, (blank_space -1));
DBMS_OUTPUT.PUT_LINE( 'Your first name is ' || first_name);
last_name := SUBSTR(full_name, (blank_space + 1),
(LENGTH(full_name) - blank_space));
DBMS_OUTPUT.PUT_LINE( 'You have ' ||
LENGTH(last_name) || ' characters in your last name!');
END; How can I list the number of characters in the last_name only? It just list everything to the right side of the 1st blank_space.
ThanksSQL> DECLARE
2 blank_space NUMBER(2);
3 full_name VARCHAR2(30) := 'Robert P. Simmons';
4 first_name VARCHAR2(30);
5 middle_initial VARCHAR2(30);
6 last_name VARCHAR2(30);
7
8 BEGIN
9 blank_space := INSTR(full_name, ' ');
10 first_name := SUBSTR(full_name, 1, (blank_space -1));
11 DBMS_OUTPUT.PUT_LINE( 'Your first name is ' || first_name);
12 middle_initial := SUBSTR(full_name, (blank_space +1), INSTR(full_name, ' ',1,2)-blank_space-1);
13 DBMS_OUTPUT.PUT_LINE( 'Your middle initial is ' || middle_initial);
14 last_name := SUBSTR(full_name, INSTR(full_name, ' ',1,2)+1);
15 DBMS_OUTPUT.PUT_LINE( 'You have ' ||
16 LENGTH(last_name) || ' characters in your last name!');
17
18 END;
19 /
Your first name is Robert
Your middle initial is P.
You have 7 characters in your last name!
Procedura PL/SQL completata correttamente.Max
http://oracleitalia.wordpress.com -
DBMS_LOB.SUBSTR with NCLOB data type
Hi ,
When I am trying to extract part of the string from Comments column(NCLOB datatype) am facing issue.
ORA-06502:PL/SQL Numeric or value error :Character string buffer too small
select dbms_lob.substr(a.COMMENTS, 4000, 1),
from VW_DETAILS a
where a.id = 6210872
DBMS_LOB.SUBSTR with NCLOB data type
Table structure :
Column_name Data_type
Comments NCLOB
ID NUMBER
Regards,
VenkatDBMS_LOB.SUBSTR parameter amount for CLOB/NCLOB indicates number of characters to substring, not bytes. And 4000 multi-byte characters (since you are using NCLOB) is greater than 4000 bytes which is absolute limit for VARCHAR2 in SQL.
SY. -
Convert varchar to date in BO Universe with Substring and instring function
to_date(substr(xxxx_v.e_details,instr(xxxx_v.e_details,'|',1,2)+1,9),'DD-MM-YYYY') In the universe while defining the object as date i was facing probs can any body help me out. the column xxxx_e_details is having the datatype varchar in database and the third string is date while i was creating the date object in the universe with the above syntax it was getting the error
The data in this obect is like this xxxx_v.e_details -> wwww|eeee|MM-DD-YY|
Edited by: mohammed kashif on Mar 31, 2011 11:47 AMi am getting the data but it is in the format 01-03-0201. The year format for 2010 is populating as 0201. i am not able to think whether it is due to instring function which is reading data like this. Need suggestion from experts.............
-
Substr and instr for long column
Plesae need support ,how can use instr and substr function for column with long datatype
select substr(rec,1,(instr(rec,'?',1))) from F_DE_O_HISTORY_QUEUE_PRE_TST2
rec column is long,When execute this select message displayed as ORA-00932: inconsistent datatypes: expected NUMBER got LONGTry to create a global temporary table and work on this table using DBMS_LOB.INSTR and DBMS_LOB.SUBSTR:
SQL> desc t;
Name Null? Type
X NUMBER(38)
Y LONG
SQL> create global temporary table tmp on commit preserve rows as select x, to_lob(y) as y from t ;
Table created.
SQL> desc tmp;
Name Null? Type
X NUMBER(38)
Y CLOBEdited by: P. Forstmann on 19 janv. 2010 12:42
Maybe you are looking for
-
755p - How to sync only Exchange email but not calendar or contacts?
I successfully set up my new 755p to sync with our Exchange server at work, but I noticed that ALL of my work contacts were now on my Treo, and vice-versa. When I go to the settings for email by using Options -> Preferences -> Auto Sync there are 3 c
-
ok i got my ipod back from a friend recently after i let her borrow it and it worked fine i plugged it in that night and added songs it told me i ran outta space for songs so i took all my pictures off so i had more space it asked me if i wanted to a
-
Hi, We are using CJIC in background mode to assign distribution rules to line items of WBS elements but are getting errors related to no batch input data though all the required data available. Have anyone used CJIC in background mode and faced simil
-
I updated my phone last night with the new iOS7.1 my phone worked fine before updating. Since updating, I have no sound from music or videos, but I do have sound when my phone rings. anyone know how to fix this? I have already done a restore that
-
I really like using CSS to layout a page or add to an existing page. I want to line up three equal size columns using CSS instead of having a table. See this page for an example of the first column. I tried to position the second column #test3 in css