Instr or substr
Hi Can any one help me with this:
TESTDATA
JUSTAJOKEFROM
I want all the letter exclude the 3 last one so it must look like this
TESTD
JUSTAJOKEF
It should automatically exclude the three last letter.
regards
SQL> SELECT SUBSTR('123444',1,LENGTH('123444')-3) FROM DUAL;
SQL>
SQL> 123
Similar Messages
-
PL-SQL Solve: Using INSTR and SUBSTR
I am trying to work on this and cannot get a solution. Please help
You have to use INSTR and SUBSTR to solve
Question:
You have the following acceptable value
Numberic: 0-34
80-100
or Non Numberic X S U D- D D+
Im have to use INSTR and SUBSTR functions to test that the value is a valid (as above) number before TO_NUMBER is called:
SELECT TO_NUMBER('?? ') //HERE ?? and a space (for 100 etc) is for the values as above
FROM DUAL
WHERE ....INSTR(......)<=;
(Hence if the number is true then number comes back or it says no rows)
and also id non numberic it should also be tested.
I am completely unsure about it but tried this
SELECT TO_NUMBER('34 ')
FROM DUAL
WHERE INSTR('0123456789',1,1)<=9 (looking at first number ?)
AND
INSTR('0123456789',2,2)<=9
AND
INSTR('0123456789',3,3)=0;
Please helpWe have the following value that we can use:
Numeric: 0-34 and 80-100 only
or Non Numberic X S U D- D D+
Have to use INSTR and SUBSTR functions to test that the value is a valid
(for now only trying to create a function which can later be put into a procedure.)
SELECT TO_NUMBER('12 ') //e.g HERE 12 and a space for the values as above
FROM DUAL
the where clause looks at all three spaces to make sure values are correct (given number or non-numberic values only)
(Hence if the number is true then number comes back (meaning true)
or it says NO rows)
If value is non numeric, test it to allow non numberic also.
I am completely unsure about it but tried this
SELECT TO_NUMBER('34 ')
FROM DUAL
WHERE INSTR('0123456789',1,1)<=9 (looking at first number ?)
AND
INSTR('0123456789',2,2)<=9
AND
INSTR('0123456789',3,3)=0;
Something like this has to be done.....subst (instr, x,x,) i think mite help. -
Some instr and substr fundamental
Hi,
In a procedure, my input parameter would be 123,345,456,567......I will put this in a loop..
My requirement is like first it will take 123 and i will do some calculation end loop,
then 345 and i will do some calculation end loop,
then 456 and i will do some calculation end loop,
then 567 and i will do some calculation end loop, and so on...
i think there is some instr and substr fundamental..
Will be great if i get some suggestion to solve the issue...
Thanks,
HPNot quite.
Dbms_utilty.comma_to_table will do the job quite nicely.
http://www.java2s.com/Code/Oracle/System-Packages/demonstratestheuseofDBMSUTILITYTABLETOCOMMAandDBMSUTILITYCOMMATOTABLE.htm
Sybrand Bakker
Senior Oracle DBA -
Instr and substr function in oracle issues
hi all
I have an issue to split my filename
Filename is as below:
ABCD01_123456789_samplename_13062012_10062012-12-12-12-1.PDF
my output as below
Col1 Col2 col3 col4 col5 col6
ABCD01 123456789 samplename 13062012 10062012 10062012-12-12-12-1.PDFcan you please help me to split this using any simple method
thanks ain advance
Edited by: A on Jun 12, 2012 8:25 PM
Edited by: A on Jun 12, 2012 8:25 PM>
can you please help me to split this using any simple method
>
You can split the string into rows using the same technique used in this example
http://nuijten.blogspot.com/2009/07/splitting-comma-delimited-string-regexp.html
Just replace the ',' with an underscore.
Then you can convert the rows to columns using LISTAGG like this example
http://www.oracle-base.com/articles/misc/string-aggregation-techniques.php
Search the forum for 'rows to columns' and you will find plenty of other alternatives. -
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 -
Please help solve this question i am stuck on
We have the following value that we can use:
Numeric: 0-34 and 80-100 only
or Non Numberic X S U D- D D+
Have to use INSTR and SUBSTR functions to test that the value is a valid
(for now only trying to create a function which can later be put into a procedure.)
SELECT TO_NUMBER('12 ') //e.g HERE 12 and a space for the values as above
FROM DUAL
the where clause looks at all three spaces to make sure values are correct (given number or non-numberic values only)
(Hence if the number is true then number comes back (meaning true)
or it says NO rows)
If value is non numeric, test it to allow non numberic also.
I am completely unsure about it but tried this
SELECT TO_NUMBER('34 ')
FROM DUAL
WHERE INSTR('0123456789',1,1)<=9 (looking at first number ?)
AND
INSTR('0123456789',2,2)<=9
AND
INSTR('0123456789',3,3)=0;
Something like this has to be done.....subst (instr, x,x,) i think mite help.Why not use regular expressions? The below thread gives you an example and instructions on how to use.
alphanumeric validation -
Xsl fo doubt for instr function
Can anyone please advice if I can use instr and substring functions in xsl fo?
my issue is that i have a lon email address which needs to be wrapped up in 2 lines
Always my email ends with 'v'
So I tried to do this
<xsl:value-of select="substring(BUYER_CONTACT_EMAIL,1,instr(BUYER_CONTACT_EMAIL,'@'))"/>
<xsl:value-of select="substring(BUYER_CONTACT_EMAIL,instr(BUYER_CONTACT_EMAIL,'@')+1,instr(BUYER_CONTACT_EMAIL,'v',-1))"/>
It throwed me error
Any idea
KPInstead of
<xsl:value-of select="substring(BUYER_CONTACT_EMAIL,1,instr(BUYER_CONTACT_EMAIL,'@'))"/>
use
<xsl:value-of select="substring-before(BUYER_CONTACT_EMAIL,'@')"/> <xsl:value-of select="substring-after(BUYER_CONTACT_EMAIL,'@')"/> -
I will give a great thanks for help with this. I have a table with a number field called "lotnum". Each rows "lotnum" has a value of 1000, 1001, 1002, 1003....2000, 2001, 2003, ..etc.) The parent row is always the one ending in zero (i.e.: 1000, 2000, 12000, etc....are all the parents). The children all end in 1,2,3,4...etc.. My problem is that another field (let's call it "x_dev") should have a value for not only the parent but also the child, but they do not. I need a query that will help me compare the parent's "x_dev" value with the value of all of the childrens "x_dev" values to determine if they are the same or not.
Sample Data:
Lotnum x_dev
1000 20
1001 Null
1002 Null
2000 20
2001 Null
(i.e: compare 1000 (parent) with the children (1001 & 1002) to determine if the "x_dev" value is the same and if not set it equal to the parent. I know I will have to probably use instr or substr going from right to left since the only constant is that the last three digits represent the children. The remaining digits are the parent (1, 10, 100, 1000), so the value could range from 1000 - 1000000)
Thanks alot
Edited by: kirkladb on Jul 14, 2012 12:09 PMselect t1.lotnum,
t2.lotnum parent_lotnum,
t1.dev_x,
t2.dev_x parent_dev_x
from tbl t1,
tbl t2
where mod(t1.lotnum,1000) != 0
and t2.lotnum = trunc(t1.lotnum / 1000) * 1000
and lnnvl(t2.dev_x = t1.dev_x)
LOTNUM PARENT_LOTNUM DEV_X PARENT_DEV_X
1002 1000 20
1001 1000 20
2001 2000 20
SQL> Or if this will be more readable to you:
select t1.lotnum,
t2.lotnum parent_lotnum,
t1.dev_x,
t2.dev_x parent_dev_x
from tbl t1,
tbl t2
where mod(t1.lotnum,1000) != 0
and t2.lotnum = trunc(t1.lotnum / 1000) * 1000
and (t2.dev_x != t1.dev_x or t1.dev_x is null)
LOTNUM PARENT_LOTNUM DEV_X PARENT_DEV_X
1002 1000 20
1001 1000 20
2001 2000 20
SQL> SY. -
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 -
Query substring and not numeric
Using Oracle 10g.
I need help with a query.. I need to get all the values where the first character is not a number. I know how to get the first character but other than that I'm lost.
SELECT * FROM my_table where substr(EMP_ID, 1,1) is not numeric?Hi,
user9179751 wrote:
Using Oracle 10g.
I need help with a query.. I need to get all the values where the first character is not a number. I know how to get the first character but other than that I'm lost.
SELECT * FROM my_table where substr(EMP_ID, 1,1) is not numeric?Here's one way:
SELECT *
FROM my_table
WHERE INSTR ( '0123456789'
, SUBSTR (emp_id, 1, 1)
) = 0
;Regular expressions and the LIKE operator can also do the job, perhaps with a little less coding, but they'll probably be less efficient. They can be very powerful tools, but you don't want to pay for that power when you're not using it. -
Hi PL/SQL experts,
I'm going a bit loopy here, so could someone please point out what I'm doing wrong with this case statement:
Test procedure is:
CREATE OR REPLACE procedure SCOTT.postcode_validate_2 (input_post_code VARCHAR2) as
alphabet_string VARCHAR2(52) := 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvxwyz';
number_string VARCHAR2(10) := '012345789';
last_part_postcode VARCHAR2(3) := NULL;
BEGIN
IF INSTR(input_post_code,' ') = 0
THEN
DBMS_OUTPUT.PUT_LINE('We need a space in the postcode please');
GOTO exit;
ELSIF LENGTH(SUBSTR(input_post_code,instr(input_post_code,' ')+1)) > 3
THEN
DBMS_OUTPUT.PUT_LINE('Last part of postcode can only be 3 characters');
GOTO exit;
ELSE
last_part_postcode := SUBSTR(input_post_code,instr(input_post_code,' ')+1);
END IF;
CASE input_post_code
WHEN (length(substr(input_post_code,1,instr(input_post_code,' ')-1)) = 2
AND instr(alphabet_string,substr(input_post_code,1,1)) != 0
AND instr(number_string,substr(input_post_code,2,1)) != 0)
THEN
DBMS_OUTPUT.PUT_LINE('We have a valid postcode in the format A9')
-- ELSE
-- DBMS_OUTPUT.PUT_LINE('Sorry but that is an incorrect postcode! Format A9');
-- GOTO exit;
-- END IF;
WHEN (length(substr(input_post_code,1,instr(input_post_code,' ')-1)) = 3
AND instr(alphabet_string,substr(input_post_code,1,1)) != 0
AND instr(alphabet_string,substr(input_post_code,2,1)) != 0
AND instr(number_string,substr(input_post_code,3,1)) != 0)
THEN
DBMS_OUTPUT.PUT_LINE('We have a valid postcode in the format AA9')
-- ELSE
-- DBMS_OUTPUT.PUT_LINE('Sorry but that is an incorrect postcode! Format AA9');
-- GOTO exit;
-- END IF;
WHEN (length(substr(input_post_code,1,instr(input_post_code,' ')-1)) = 3
AND instr(alphabet_string,substr(input_post_code,1,1)) != 0
AND instr(number_string,substr(input_post_code,2,1)) != 0
AND instr(number_string,substr(input_post_code,3,1)) != 0)
THEN
DBMS_OUTPUT.PUT_LINE('We have a valid postcode in the format A99')
-- ELSE
-- DBMS_OUTPUT.PUT_LINE('Sorry but that is an incorrect postcode! Format A99');
-- GOTO exit;
-- END IF;
WHEN (length(substr(input_post_code,1,instr(input_post_code,' ')-1)) = 3
AND instr(alphabet_string,substr(input_post_code,1,1)) != 0
AND instr(number_string,substr(input_post_code,2,1)) != 0
AND instr(alphabet_string,substr(input_post_code,3,1)) != 0)
THEN
DBMS_OUTPUT.PUT_LINE('We have a valid postcode in the format A9A')
-- ELSE
-- DBMS_OUTPUT.PUT_LINE('Sorry but that is an incorrect postcode! Format A9A');
-- GOTO exit;
-- END IF;
WHEN (length(substr(input_post_code,1,instr(input_post_code,' ')-1)) = 4
AND instr(alphabet_string,substr(input_post_code,1,1)) != 0
AND instr(alphabet_string,substr(input_post_code,2,1)) != 0
AND instr(number_string,substr(input_post_code,3,1)) != 0
AND instr(number_string,substr(input_post_code,4,1)) != 0)
THEN
DBMS_OUTPUT.PUT_LINE('We have a valid postcode in the format AA99')
-- ELSE
-- DBMS_OUTPUT.PUT_LINE('Sorry but that is an incorrect postcode! Format AA99');
-- GOTO exit;
-- END IF;
WHEN (length(substr(input_post_code,1,instr(input_post_code,' ')-1)) = 4
AND instr(alphabet_string,substr(input_post_code,1,1)) != 0
AND instr(alphabet_string,substr(input_post_code,2,1)) != 0
AND instr(number_string,substr(input_post_code,3,1)) != 0
AND instr(alphabet_string,substr(input_post_code,4,1)) != 0)
THEN
DBMS_OUTPUT.PUT_LINE('We have a valid postcode in the format AA9A')
-- ELSE
-- DBMS_OUTPUT.PUT_LINE('Sorry but that is an incorrect postcode! Format AA9A');
-- GOTO exit;
-- END IF;
END;
-- Check last part of format, should be AA9
IF (instr(number_string,substr(input_post_code,1,1)) != 0
AND instr(alphabet_string,substr(input_post_code,2,1)) != 0
AND instr(alphabet_string,substr(input_post_code,3,1)) != 0)
THEN
DBMS_OUTPUT.PUT_LINE('End part of the postcode is in the correct format, 9AA');
ELSE
DBMS_OUTPUT.PUT_LINE('End part of the postcode is in the wrong format!');
END IF;
<<exit>>
DBMS_OUTPUT.PUT_LINE('Please try again');
END;
However, I'm getting the following error:
LINE/COL ERROR
37/6 PLS-00103: Encountered the symbol "WHEN" when expecting one of
the following:
:= . ( % ;
On a second note, can I not have the ELSE structure embedded within the case (currently commented out)?
Thanks very much in advance.
DevFixed code:
CREATE OR REPLACE procedure postcode_validate_2 (input_post_code VARCHAR2) as
alphabet_string VARCHAR2(52) := 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvxwyz';
number_string VARCHAR2(10) := '012345789';
last_part_postcode VARCHAR2(3) := NULL;
BEGIN
IF INSTR(input_post_code,' ') = 0
THEN
DBMS_OUTPUT.PUT_LINE('We need a space in the postcode please');
GOTO exit;
ELSIF LENGTH(SUBSTR(input_post_code,instr(input_post_code,' ')+1)) > 3
THEN
DBMS_OUTPUT.PUT_LINE('Last part of postcode can only be 3 characters');
GOTO exit;
ELSE
last_part_postcode := SUBSTR(input_post_code,instr(input_post_code,' ')+1);
END IF;
CASE
WHEN (length(substr(input_post_code,1,instr(input_post_code,' ')-1)) = 2
AND instr(alphabet_string,substr(input_post_code,1,1)) != 0
AND instr(number_string,substr(input_post_code,2,1)) != 0)
THEN
DBMS_OUTPUT.PUT_LINE('We have a valid postcode in the format A9');
-- ELSE
-- DBMS_OUTPUT.PUT_LINE('Sorry but that is an incorrect postcode! Format A9');
-- GOTO exit;
-- END IF;
WHEN (length(substr(input_post_code,1,instr(input_post_code,' ')-1)) = 3
AND instr(alphabet_string,substr(input_post_code,1,1)) != 0
AND instr(alphabet_string,substr(input_post_code,2,1)) != 0
AND instr(number_string,substr(input_post_code,3,1)) != 0)
THEN
DBMS_OUTPUT.PUT_LINE('We have a valid postcode in the format AA9');
-- ELSE
-- DBMS_OUTPUT.PUT_LINE('Sorry but that is an incorrect postcode! Format AA9');
-- GOTO exit;
-- END IF;
WHEN (length(substr(input_post_code,1,instr(input_post_code,' ')-1)) = 3
AND instr(alphabet_string,substr(input_post_code,1,1)) != 0
AND instr(number_string,substr(input_post_code,2,1)) != 0
AND instr(number_string,substr(input_post_code,3,1)) != 0)
THEN
DBMS_OUTPUT.PUT_LINE('We have a valid postcode in the format A99');
-- ELSE
-- DBMS_OUTPUT.PUT_LINE('Sorry but that is an incorrect postcode! Format A99');
-- GOTO exit;
-- END IF;
WHEN (length(substr(input_post_code,1,instr(input_post_code,' ')-1)) = 3
AND instr(alphabet_string,substr(input_post_code,1,1)) != 0
AND instr(number_string,substr(input_post_code,2,1)) != 0
AND instr(alphabet_string,substr(input_post_code,3,1)) != 0)
THEN
DBMS_OUTPUT.PUT_LINE('We have a valid postcode in the format A9A');
-- ELSE
-- DBMS_OUTPUT.PUT_LINE('Sorry but that is an incorrect postcode! Format A9A');
-- GOTO exit;
-- END IF;
WHEN (length(substr(input_post_code,1,instr(input_post_code,' ')-1)) = 4
AND instr(alphabet_string,substr(input_post_code,1,1)) != 0
AND instr(alphabet_string,substr(input_post_code,2,1)) != 0
AND instr(number_string,substr(input_post_code,3,1)) != 0
AND instr(number_string,substr(input_post_code,4,1)) != 0)
THEN
DBMS_OUTPUT.PUT_LINE('We have a valid postcode in the format AA99');
-- ELSE
-- DBMS_OUTPUT.PUT_LINE('Sorry but that is an incorrect postcode! Format AA99');
-- GOTO exit;
-- END IF;
WHEN (length(substr(input_post_code,1,instr(input_post_code,' ')-1)) = 4
AND instr(alphabet_string,substr(input_post_code,1,1)) != 0
AND instr(alphabet_string,substr(input_post_code,2,1)) != 0
AND instr(number_string,substr(input_post_code,3,1)) != 0
AND instr(alphabet_string,substr(input_post_code,4,1)) != 0)
THEN
DBMS_OUTPUT.PUT_LINE('We have a valid postcode in the format AA9A');
-- ELSE
-- DBMS_OUTPUT.PUT_LINE('Sorry but that is an incorrect postcode! Format AA9A');
-- GOTO exit;
-- END IF;
END CASE;
-- Check last part of format, should be AA9
IF (instr(number_string,substr(input_post_code,1,1)) != 0
AND instr(alphabet_string,substr(input_post_code,2,1)) != 0
AND instr(alphabet_string,substr(input_post_code,3,1)) != 0)
THEN
DBMS_OUTPUT.PUT_LINE('End part of the postcode is in the correct format, 9AA');
ELSE
DBMS_OUTPUT.PUT_LINE('End part of the postcode is in the wrong format!');
END IF;
<<exit>>
DBMS_OUTPUT.PUT_LINE('Please try again');
END;
/As VG2 pointed out you were missing some semicolons.
Also, CASE input_post_code was replaced with just CASE since you are doing a searched case.
Also, END at the end of the case statement was replaced with END CASE. -
Help with RTF and special characters
Hi,
I'm curently working on apex 4.1 and i want to generate an .rtf file which i fill with the information coming from a form.
I am doing so without any problems when it comes to normal Americam letters.
I face a problem when i wan't to dynamicly change my subsctitution phrases in the .rtf template with czech characters (á,é...), because i can't just replace the word with these characters in the rtf because it expects to receive some escape formats and not the letter itself.
Can anybody help me figure this one out?
I've tried creating a library of the symbols and their asci code and replacing them in the file but they don't always work. I even saved a .doc file in .rtf and copied the code from that one in my .rtf and it doesn\t work. In the original file i have some characters in my file i have other characters eventhough the code is the same...
I'm puzzled by this one and i don't know what to do.
Thank you,
Alex.Hi,
Yes i wan't to remove information from the clob.
I have an .xml template and if i don't have any updates on some chapters i wan't to remove them.
Until now i have tried to replace the strings that i don't need using the replace function, but sometimes the string that i wan't to replace is longer than 32726 chars.
I have comented the xml clob with tags like "<!-- [[$$1.0]] start -->" and "<!-- [[$$1.0]] end -->" and using the instring and substring functions i get the piece of information i wan't to remove.
"select substr(r.template_content,instr(r.template_content,'<!-- [[$$1.0]] start -->') , instr(r.template_content,'<!-- [[$$1.0]] end -->')-instr(r.template_content,'<!-- [[$$1.0]] start -->'))
from rtf_templates r
where r.template_id=3"
and then i use " clob := replace(clob,get_substr)"
usualy it works but sometimes the length of the subtr is larger than 32767 chars and that's when i have problems.
Any ideeas on how to remove the chunks of info from the clob?
Thank you.
Alex.
I have changed the get_substr select because i wrote it wrong :) now it's ok
Edited by: Banu Alexandru on 06.06.2012 08:44 -
How to get a subset of text from a varchar2 field
Hello. I am trying to select a subset of text from a varchar2 field. This is login information from dba_audit_trail view. Here's an example of the field (comment_text from dba_audit_trail):
Authenticated by: DIRECTORY PASSWORD;EXTERNAL NAME: cn=orcladmin,cn=Users,dc=idacorp,dc=local; Client address: (ADDRESS=(PROTOCOL=tcp)(HOST=555.555.555.555)(PORT=99999))
I am trying to just select the "orcladmin" text - i.e. everything after the first "=" up to the first ","
I can get everything after the first "=" with this:
select substr(comment_text, instr(comment_text, '=') + 1) from dba_audit_trail
... but I don't know how to stop at the first ","
Any help would be greatly appreciated.
Thanks!
Message was edited by: DRCHi,
Here's one way to do it:
WITH got_pos AS
SELECT comment_text -- and whatever other columns you need
, INSTR (cooment_text, '=') AS equal_pos
, INSTR (cooment_text, ',') AS comma_pos
FROM dba_auit_trail
WHERE ... -- any filtering goes here
SELECT SUBSTR ( comment_text
, equal_pos + 1
, comma_pos - (equal_pos + 1)
) AS first_cn
FROM got_pos
You could do it without a sub-query; you'd just have to do the exact same INSTR 2 times, where I used equal_pos 2 times.
You could also get the results you want using regular expressions, such as:
SELECT REGEXP_SUBSTR ( comment_text
, '=([^,]*),'
, 1
, 1
, NULL
, 1
) AS first_cn
FROM dba_audit_trail
Although this uses less code, it's slower than using INSTR and SUBSTR . -
How to read a CSV file and Insert data into an Oracle Table
Hi All,
I have a Clob file as a in parameter in my PROC. . File is comma separated.need procedure that would parse this CLOB variable and populate in oracle table .
Please let me some suggestions on this.
Thanks,
Chandra Rjeneesh wrote:
And, please don't "hijack" 5 year old thread..Better start a new one..I've just split it off to a thread of it's own. ;)
@OP,
I have a Clob file as a in parameter in my PROC. . File is comma separated.need procedure that would parse this CLOB variable and populate in oracle table .You don't have a "clob file" as there's no such thing. CLOB is a datatype for storing large character based objects. A file is something on the operating system's filesystem.
So, why have you stored comma seperated data in a CLOB?
Where did this data come from? If it came from a file, why didn't you use SQL*Loader or, even better, External Tables to read and parse the data into structured format when populating the database with it?
If you really do have to parse a CLOB of data to pull out the comma seperated values, then you're going to have to write something yourself to do that, reading "lines" by looking for the newline character(s), and then breaking up the "lines" into the component data by looking for commas within it, using normal string functions such as INSTR and SUBSTR or, if necessary, REGEXP_INSTR and REGEXP_SUBSTR. If you have string data that contains commas but uses double quotes around the string, then you'll also have the added complexity of ignoring commas within such string data.
Like I say... it's much easier with SQL*Loader of External Tables as these are designed to parse such CSV type data. -
How to display last name first and then first name last from one name column?
I am trying to write a code which will display the last Name first then second name at last. For example;
If the value of table column is: "John Decker Revora"
I want to display "Revora, John Decker".
I think I will first look for the gap in between the name and from last gap i will pick up the value and then concathenate with rest of the name.
If u have any advice please reply ASAP with some examples.
ThanksYou need to do this in the query, using the instr and substr functions. Search the documentation for info on these functions. As a startpoint, I'll copy here an example from Kevin Loney's Oracle 8i The Complete Reference that does the opposite... you can adjust this to your needs:
select Author, SUBSTR(Author, INSTR(Author,',')+2) | |' '| | SUBSTR(Author, INSTR(Author,',')-1) ByFirstName
from Magazine
Maybe you are looking for
-
Time Capsule with multiple computers
Everyone in our office uses macs, and we use time capsules for backing up. It seems that only one person can back up at any given time, so when one user is trying to do a backup, all of the other users have failed backup attempts because the disk is
-
PI 7.0 default client Implications
Hi all, We have installed my production server PI 7.0 earlier and it is currently operating for some projects. But the problem is the client on which the production system working now is 001 (i.e default client). This we have just noticed that it is
-
Not a question but hopefully an answer to what seems to be a common problem. I have just taken delivery of a shiny new imac running Mountain Lion. I migrated software and files form my old imac without problem and reconnected all devices. I found th
-
I have restored my ipod and now the songs in my library wont sync onto it:)).. !! please help!!
-
Firefox requires administrative rights on each start (Win7)
I have disabled all plugins, all extensions. The latest version of Firefox is installed (3.6.12 - 29 oct). On each start of Firefox Windows 7 asks me if I allow Firefox to modify my computer.