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 kindly
Hi,
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}
Similar Messages
-
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 -
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 -
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 -
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 -
How can we a validate a CSV file in SSIS and log the error details in another CSV File by using Sript Task.
Please see:
http://www.bidn.com/blogs/DevinKnight/ssis/76/does-file-exist-check-in-ssis
http://social.msdn.microsoft.com/Forums/en-US/01ce7e4b-5a33-454b-8056-d48341da5eb2/vb-script-to-write-variables-to-text-file -
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 -
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} -
Dear ALL,
I m having one variable for that i need key and text in bex analyzer.
how to enable the key and text for a variable.
pls asap
regards,
JenishHi jenish kumar ,
if i under stan your requirement correctly, need to have both text and key values for variables with F4 help.
you need to chnage the properties of that infoobject at infoobjects level or at infoprovider level,
this is at infoprovider level
in RSA1-> go to change mode of infoprovider (Multiprovider/ cube) on which Query is build) then Expand Charecteristc Dimension -> select infoobject -> right -> select provider-specific properties -> select Display '0 Key and Text' . Activate infoprovider and Run Query and check the Selection screen.
hope this helps
Regards
Daya Sagar -
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 -
Ideas and Suggestions for Working with Low Res Video Files
Hi,
A client has asked me to take all of her low res videos she shot with her iPhone and put them on a DVD.
I've made her aware that the end result is not going to be a Hollywood production. I even did a test for her to show the difference between a low res clip and a HD clip. You can see these clips here:
http://designerandpublisher.com/hs/lowrestest.mp4
and
http://designerandpublisher.com/hs/hdtest.mp4
She understands and will fix her camera to shoot high-res next time. Anyway, the footage (330 minutes) I have looks like this when imported into Premiere Pro CS4:
I first just set up a 640x480 timeline and imported one of her clips. It doesn't look too bad. I'm not sure why that green bar is there:
Then I went into the timeline's properties to see if I can somehow enhance it once it goes onto a DVD via Encore:
But i'm not really sure if it's worth fiddling around with a customized timeline. I don't have my hopes up though but I'd appreciate it if anyone could tell me what they did in this type of situation. It seems like the 640x480 timeline, once brought into Encore and transcoded for the DVD, may work best.
Any ideas are appreciated. Thanks.
The Deaf GuyI don't edit video from a cell phone, and you don't mention any particular problems loading/editing... but in case you do have general problems with any of the files, some reading to keep in mind
Iphone won't edit easily because it uses a variable frame rate - A fix in message #22 http://forums.adobe.com/thread/934466 -
Best data Structor for dealing with very large CSV files
hi im writeing an object that stores data from a very large CSV file. The idea been that you initlize the object with the CSV file, then it has lots of methods to make manipulating and working with the CSV file simpler. Operations like copy colum, eliminate rows, perform some equations on all values in a certain colum, etc. Also a method for prining back to a file.
however the CSV files will probly be in the 10mb range maby larger so simply loading into an array isn't posable. as it produces a outofmemory error.
does anyone have a data structor they could recomend that can store the large amounts of data require and are easly writeable. i've currently been useing a randomaccessfile but it is aquard to write to as well as needing an external file which would need to been cleaned up after the object is removed (something very hard to guarentee occurs).
any suggestions would be greatly apprechiated.
Message was edited by:
ninjarobHow much internal storage ("RAM") is in the computer where your program should run? I think I have 640 Mb in mine, and I can't believe loading 10 Mb of data would be prohibitive, not even if the size doubles when the data comes into Java variables.
If the data size turns out to be prohibitive of loading into memory, how about a relational database?
Another thing you may want to consider is more object-oriented (in the sense of domain-oriented) analysis and design. If the data is concerned with real-life things (persons, projects, monsters, whatever), row and column operations may be fine for now, but future requirements could easily make you prefer something else (for example, a requirement to sort projects by budget or monsters by proximity to the hero). -
Search and Delete a specific record from a CSV file
Hi All,
I am new to java . I want to search for the records from CSV file and delete the row form the file.
Below is my Sample .csv
100||a100||1b100
200||b200||dc300
200||bg430||ef850
400||f344||ce888
Now I need some help in below requirements.
1.How to delete a record having value 200 and b200?
2.If record already exists how to update the existing record with new values?
Please share your ideas or give me some code snippet..
Thanks in AdvanceIn that case Do i need to write the entire contents of my file to a hash table(sumthng like this) and modify the Second row in my case with the new values..
is it possible??I would have done like this (though there maybe better methods)
1- create a class representing the record.
class Record{
String field1;
String field2;
String field3;
// and so on....
//setters
public void setFeild1(String str){
field1=str;
// and so on....
//getters
public String getFeild1(){
field1=str;
// and so on....
public String toString(){
return(field1+"||"+field2+"||"+field3);
}//end class2- then create an ArrayList meant to have objects of this class (Generics).
3- read from the file , create a new Record Object and add that to the ArrayList
4- perform operations on the ArrayList (you can add new records, and delete record, update......)
5- write the record back to file using 'toString()' method.
is there ne sample code available for thisdon't know, but you rarely get full code on forums.....outline given can be followed
Thanks!
Edit: It appears that 'r035198x' and me have the same point. This shows that this methodology is almost a standard way( if we ignore the Random access files.....)
Edited by: T.B.M on Jan 13, 2009 2:39 PM -
Searching for a data in a CSV file
i have my below code for reading a CSV file..
public static void main(String[] args)
ReadCSVFile obj = new ReadCSVFile();
try
BufferedReader in = new BufferedReader(new FileReader("RecordsNet DocType List1.csv"));
String str;
while ((str = in.readLine()) != null)
String s[] = str.split(",");
for (int i = s.length - 1; i >=0; i --)
System.out.println(s);
in.close();
catch (IOException e)
}//class main end
}// class ReadCSVFile end
i want to read my CSV file only if has some data in any column. how do i introduce this find clause while reading a CSV file
Please HelpYou could do something like this:
String[] s = str.split(",");
for (int i = (s.length - 1); i >= 0; i--)
if (s.length() > 0) // check if there is data in the column
System.out.print(s[i] + " ");
System.out.println();
Next time please paste your code between code tags exactly like this:
[code]
your code
[/code]
You may read the [url http://forum.java.sun.com/help.jspa?sec=formatting]Formatting tips for more information.
Regards -
Using multiple xdofx commands together. For eg: substr and instr
Hi,
I am working in developing an RTF where a situation is to use xdofx:sustr and xdofx:instr together.
I tried but its not working properly.
Is there any special commands to use in such a scenario.
Thanks,
Anandplz post what are you doing
works for me
as example
<?xdofx:substr(substr(COLOR,5),instr(substr(COLOR,5),’;’)+1)?>for
<ROWSET>
<ROW>
<COLOR>qwe qwe;rty</COLOR>
</ROW>
</ROWSET>gives
rty
Maybe you are looking for
-
RE:ALERT MESSAGE IS NEEDED AT TIME OF CREATION
Dear Sap experts, Please advise me that if i want to show alert message at time of po creation, if it reaches the maximum stock level (stock+order) then where we change the configuration. Thanks Mohit
-
I am looking for a device that will answer a landline phone. I have a Phonevalet, which answers, takes messages, has call block and is pluged into my Address Book, but it was discontinued, and I would like to add another line. Ovalabs made a similar
-
Missing APPLICATIONS & FILE Icons and can't find my themes
Please help. I have a 3rd party application that I downloaded as required to my computer & now I need to transfer 5 files (JAR & TAR) files to my phone. It says to follow the path: files/media card/ Blackberry/new_phones.In the instructions it says
-
Post your i3 wm screenshots.
I was looking around and saw that every other wm had a screen shot section, but nothing for i3. Thestinger recocmended i3 to me in the irc, and I must say I obsulutly love it. Its the only window manager were I was able to just jump in and start doin
-
how to restore my ipod 5g? i got a problem with my ipod 5g cann't restore , please help me fix it thank you