Substr, replace
I have an Etiquettemois (varchar2) column, and the data is stored as
SUN | MY | MAR | SEA | GAME | FRI | SAM |
SUN |
SUN | MY |
New requirement is to display the day of the week in application is as
Sun, Mon, Mar, sea, game, sat, Sam
Sun
Sun, Mon
I tried different ways, but could not succeed. Any help would be great.
Select S UBSTR (REPLACE (Etiquettemois ' |' )) , ','), 0, LENGTH(Week_day) -1 ) AS WeekDay
de table1:
Thank you
SQL > with t1 as (select ' SUN |) MY | MAR | SEA | GAME | FRI | SAM |' The double Etiquettemois
2 union all select ' SUN |' double
3 union all select them ' SUN | MY: ' double
4 Select initcap (replace (substr (week_day, 1, length (week_day)-1),'|)) ((',', ')) as the day of the week of t1;
DAY OF THE WEEK
--------------------------------------------------------
Sun, Mon, Mar, sea, game, sat, Sam
Sun
Sun, Mon
Tags: Database
Similar Questions
-
Hello, looking for basic using regex.
I can do the sharing by using the CASE statements, but how can I use it with regex.
How can I separate the below address in separate columns and regex substr, replace S by SOUTH, with NORTH etc and orientation N (N, S, E, W) may appear anywhere.
1850 S LAKEWOOD RD NW
PATTON 300 CL SO
Results as
SUFDIR, SUFTYPE, STRID, VECTOR, STREET
1850, LAKEWOOD, RD, TO THE SOUTH, NW
300, PATTON, CL, WEST, SOUTHWEST
Any help would be appreciated. Apologies if this isn't the right forum.
Thank you.
Any help would be appreciated. Apologies if this isn't the right forum.
OK - you have the wrong forum.
This forum is ONLY for Sql Developer questions.
Please mark the thread ANSWERED and repost it in Sql and Pl/Sql forum
-
To_Number fails because the number not valid
I have a value which is unfortunately in a field of varchar (50) free form text and I'm updating a table which is a numeric field. The data could be anything. From my research, it sounds like its values as 18000, or $20,000, $23 000,00, $28 000,00 or or $35,000.0000.
I tried the command To_Number and it failed.
I made a function replace and stripped dollar signs and commas and the still empty spaces and as a last resort even stripped periods just to try to put incorrect data, perhaps thinking that the free text field has had two periods in it.
I have an IS_NUMBER function and when I run the field through here, he said they are all numbers, but when I update it does not say that it is an invalid number.
I have a long msft sql dba, but Oracle is all new to me.
BEGIN
merge into wh_cust_act_brand t
a_l'_aide_de)
Select cust_no, activ_no, ss. SETTING_VALUE
OF GMSTG. STG_service_settings ss
WHERE ss.setting_id = 'lifeline_qualifying_income. '
and ss.setting_value is not null
and not exists (select 1
of wh_cust_act_brand c
where c.cust_no = ss.cust_no
and c.activ_no = ss.activ_no
and c.lifeline_qualifying_income = ss.setting_value
(q))
WE (t.cust_no = q.cust_no and t.activ_no = q.activ_no)
When matched then
game update
t.update_date = sysdate,
I tried these:
-t.lifeline_qualifying_income = q.setting_value
-t.lifeline_qualifying_income = replace (replace (replace (replace (q.setting_value, ' $', "),",","), '-', "), ' ',");
-t.lifeline_qualifying_income = TO_NUMBER (replace (replace (replace (replace (q.setting_value, ' $', "),",","), '-', "), ' ',"), ' $9,999,999.99999999 ' ");
-t.lifeline_qualifying_income = cast (regexp_replace (q.setting_value, "[^ 0-9.]")) +', ") under the number);
-t.lifeline_qualifying_income = regexp_replace (q.setting_value, "[^ 0-9] +'," ");
t.lifeline_qualifying_income =
(CASE
WHEN substr (q.setting_value, 1, 1) = "$" then to_number (substr (replace (q.setting_value, ',', "), length (q.setting_value)-1, 2)," 9999999.99999999' ")
WHEN substr (q.setting_value, 1, 1) <>' $' then to_number (replace (q.setting_value, ',' ")," 999999.9999' ")
-ANOTHER '0'
(END);
EXCEPTION
WHILE OTHERS THEN
raise_application_error (-20001,' an error has occurred - ' |) SQLCODE |' - ERROR - ' | SQLERRM);
END;
OK, I finally got to work:
I think that the problem was way up above in code at line 3 and 11, I compared a number in a field of type varchar field, once I fixed that Oracle was much happier.
merge into wh_cust_act_brand t
a_l'_aide_de)
Select cust_no, activ_no, to_number (replace (replace (trim (setting_value), ' $', "),",",")) setting_value
OF GMSTG. STG_service_settings ss
WHERE ss.setting_id = 'lifeline_qualifying_income. '
and ss.setting_value is not null
and not exists (select 1
of wh_cust_act_brand c
where c.cust_no = ss.cust_no
and c.activ_no = ss.activ_no
and c.lifeline_qualifying_income = to_number (replace (replace (trim (setting_value), ' $', "),",","))
(q))
WE (t.cust_no = q.cust_no and t.activ_no = q.activ_no)
When matched then
game update
t.update_date = sysdate,
t.lifeline_qualifying_income = to_number (replace (replace (trim (setting_value), ' $', "),",","));
-
Looking to update historical data
Hello
I have a table which records the details of customers including their phone numbers depending on the type.
Further, all data will be posted in the correct format, but I want to run some update instructions that will
- all clients with the type of 'Mobile' phone number have the formatted number of 999 9999999 follows
Any help much appreciated.
Thank you
Mark
Mark
Try this for size:
DROP TABLE PERSON_PHONE_DETAILS;
CREATE TABLE PERSON_PHONE_DETAILS (PERSON_ID TANK (10 BYTES) NOT NULL, PHONE_TYPE TANK (12 BYTES) NOT NULL, PHONE_NUMBER VARCHAR2 (24-BYTE) NOT NULL);
INSERT INTO PERSON_PHONE_DETAILS VALUES ('3911546020', 'BUSINESS', '0180 45837');
INSERT INTO PERSON_PHONE_DETAILS VALUES ('9747965797', 'BUSINESS', '0186 65454');
INSERT INTO PERSON_PHONE_DETAILS VALUES ('2098300000', 'BUSINESS', '061 442100');
INSERT INTO PERSON_PHONE_DETAILS VALUES ('3846066020', 'HOME', '018 886454');
INSERT INTO PERSON_PHONE_DETAILS VALUES ('6775653404', 'HOME', '01 8407618');
INSERT INTO PERSON_PHONE_DETAILS VALUES ('3034746020', 'HOME','051 8 51480');
INSERT INTO PERSON_PHONE_DETAILS VALUES ('9836469027', 'MOBILE', '76569159 08');
INSERT INTO PERSON_PHONE_DETAILS VALUES('8007122020','MOBILE','0876937724');
INSERT INTO PERSON_PHONE_DETAILS VALUES ('3034746020', 'MOBILE','087 214 2020 ');
INSERT INTO PERSON_PHONE_DETAILS VALUES ('4311695718', 'FAX', '087 1330415');
INSERT INTO PERSON_PHONE_DETAILS VALUES ('7604812864', 'FAX', '089 4845182');
INSERT INTO PERSON_PHONE_DETAILS VALUES ('6776901999', 'FAX', '01 2886149');
COMMIT;
UPDATE PERSON_PHONE_DETAILS
SET = PHONE_NUMBER
CASE
WHEN PHONE_TYPE = 'MOBILE' THEN
-remove all spaces, then divided into XXX | » '|| XXXXX...
SUBSTR (REPLACE (PHONE_NUMBER,' ', "), 1.3). » '|| SUBSTR (REPLACE (PHONE_NUMBER,' ', "), 4, LENGTH (REPLACE (PHONE_NUMBER,' ',")))
WHEN PHONE_TYPE = "HOME" THEN
-remove all spaces, then divided into XXXX | » '|| XXXXX...
SUBSTR (REPLACE (PHONE_NUMBER,' ', "), 1.4). » '|| SUBSTR (REPLACE (PHONE_NUMBER,' ', "), 5, LENGTH (REPLACE (PHONE_NUMBER,' ',")))
WHEN PHONE_TYPE = 'BUSINESS' THEN
-remove all spaces, then divided into XXXX | » '|| XXXXX...
SUBSTR (REPLACE (PHONE_NUMBER,' ', "), 1.2). » '|| SUBSTR (REPLACE (PHONE_NUMBER,' ', "), 3, LENGTH (REPLACE (PHONE_NUMBER,' ',")))
WHEN PHONE_TYPE = 'FAX' AND THEN
-remove all spaces, no separation
REPLACE (PHONE_NUMBER,' ', ")
ON THE OTHER
-How else do not reformat
PHONE_NUMBER
END
WHEN - where statement to prevent the update of phone numbers already in desired format
PHONE_NUMBER<>
(CASE
WHEN PHONE_TYPE = 'MOBILE' THEN
-remove all spaces, then divided into XXX | » '|| XXXXX...
SUBSTR (REPLACE (PHONE_NUMBER,' ', "), 1.3). » '|| SUBSTR (REPLACE (PHONE_NUMBER,' ', "), 4, LENGTH (REPLACE (PHONE_NUMBER,' ',")))
WHEN PHONE_TYPE = "HOME" THEN
-remove all spaces, then divided into XXXX | » '|| XXXXX...
SUBSTR (REPLACE (PHONE_NUMBER,' ', "), 1.4). » '|| SUBSTR (REPLACE (PHONE_NUMBER,' ', "), 5, LENGTH (REPLACE (PHONE_NUMBER,' ',")))
WHEN PHONE_TYPE = 'BUSINESS' THEN
-remove all spaces, then divided into XXXX | » '|| XXXXX...
SUBSTR (REPLACE (PHONE_NUMBER,' ', "), 1.2). » '|| SUBSTR (REPLACE (PHONE_NUMBER,' ', "), 3, LENGTH (REPLACE (PHONE_NUMBER,' ',")))
WHEN PHONE_TYPE = 'FAX' AND THEN
-remove all spaces, no separation
REPLACE (PHONE_NUMBER,' ', ")
ON THE OTHER
-How else do not reformat
PHONE_NUMBER
(END);
COMMIT;
Alan
-
Concatenate the nested XML tags
Hello
I am looking for a solution concatenate duplicate in an xml tags.
I need only the tags 'tag' 'type = keyword' in a field in a table.
The sql statement that I use, I get six records and I just need a registration.
Hope that my written English is not hard to understand what I mean.
It is a part of the XML data.
<? XML version = "1.0" encoding = "UTF - 8"? >
< list >
< article id = "25230245" title = "st" publish = "true" sender =">
< categories >
< naam category = "Staking" externalid = "Economy/staking" / >
< / categories >
< geoinfo latitude =' 52,3936' longitude' 6,142065 =' zoom = "15" / >
< tags >
< tag name = 'Overijssel, Raalte, Raalte' type = 'rental' / >
< tag name = 'Overijssel, Deventer, Deventer' type = 'rental' / >
< tag name = 'Overijssel Olst-Wijhe Wijhe' type = 'rental' / >
< tag name = "CAD" type = "keyword" / >
< name of tag = "vleeswarensector" type = "keyword" / >
< name of tag = "seniorenregeling" type = "keyword" / >
< tag name = "fnv bondgenoten" type = "Keyword" / >
< name of tag = "werkonderbreking" type = "keyword" / >
< tag name = 'Zwanenburg' type = "Keyword" / >
< tag name = "staking" type = "Keyword" / >
< tag name = "Scott" type = "Keyword" / >
< name of tag = "La¼pack" type = "keyword" / >
< tag name = "cnv vakmensen" type = "Keyword" / >
< / tags >
< publicatiedatum datum = '1400663902374' datumstr ='2014 - 05-21T 11: 18:00 + 0200 "/ >"
< wijzigingsdatum datum = '1400663902374' datumstr ='2014 - 05-21T 11: 18:00 + 0200 "/ >"
< printdatum datumstr = May 22, 2014 "/ >"
< bestemming >
< bestemming channel = 'web' site = 'ST' page =' Regio/Deventer /' primary = "false" / >
< bestemming channel = 'web' site = 'ST' page =' Regio/Olst-Wijhe /' primary = "false" / >
< bestemming channel = 'web' site = 'ST' page =' Regio/Raalte /' primary = "true" / >
< / bestemming >
< bron naam = "Benny Koerhuis" / >
< figurines / >
< / product >
< / list >
And it's my sql (part of a plsql procedure) statement.
SELECT decode (upper (t1.publish), 'TRUE', 'Y', 'n')
, trunc (to_date (substr (replace (t1.pdate, 't',' '), 1, 19), "YYYY-MM-DD HH24:MI:SS")) update
, to_date (substr (replace (t1.flitstijd, 't',' '), 1, 19), "YYYY-MM-DD HH24:MI:SS") flitstijd
t1.naam_flitser
t1.sectie
t1.titel
t1.soort
t2.trefwoorden
OF flits_berichten_clob t1
, XMLTABLE ("' / / test/artikel")
By the WAY of XMLTYPE (t1.xml_file)
COLUMNS publish VARCHAR2 (10) path '@publish '.
update the PATH in VARCHAR2 (25) "publicatiedatum/@datumstr".
, flitstijd PATH VARCHAR2 (25) "wijzigingsdatum/@datumstr".
, naam_flitser PATH VARCHAR2 (25) "bron/@naam".
, books VARCHAR2 (255) PATH 'bestemmingen/bestemming[@primary="true"]/@page '.
, titel VARCHAR2 (10) path 'bestemmingen/bestemming[@primary="true"]/@site '.
, soort PATH VARCHAR2 (10) 'bestemmingen/bestemming[@primary="true"]/@channel '.
tags XMLTYPE PATH 'tags') t1
, XMLTABLE ('/ tags/tag [@type = "keyword"] ")
PASSAGE t1.tags
T2 of COLUMNS trefwoorden VARCHAR2 (255) PATH "@name")
ID WHERE = 15;
This is the result.
THERE 21/05/2014 21/05/2014-11:18 Benny Koerhuis Regio/Raalte. ST Web werkonderbreking THERE 21/05/2014 21/05/2014-11:18 Benny Koerhuis Regio/Raalte. ST Web Zwanenburg THERE 21/05/2014 21/05/2014-11:18 Benny Koerhuis Regio/Raalte. ST Web staking THERE 21/05/2014 21/05/2014-11:18 Benny Koerhuis Regio/Raalte. ST Web Stegeman THERE 21/05/2014 21/05/2014-11:18 Benny Koerhuis Regio/Raalte. ST Web La¼Pack THERE 21/05/2014 21/05/2014-11:18 Benny Koerhuis Regio/Raalte. ST Web CNV vakmensen Is it possible to concatenate the results of the last column?
It should be "werkonderbreking, Zwanenburg, staking, Stegeman, la¼pack, cnv vakmensen" so, I get a recording instead of six.
Thanks in advance.
Is it possible to concatenate the results of the last column?
Yes, use string-join function:
...
titel PATH of VARCHAR2 (10) 'bestemmingen/bestemming[@primary="true"]/@site '. soort PATH of VARCHAR2 (10) 'bestemmingen/bestemming[@primary="true"]/@channel '. trefwoorden PATH of VARCHAR2 (4000) 'string-join(tags/tag[@type="keyword"]/@name, ","). ) t1
In this way, that you need more of the second XMLTABLE.
-
Hi gurus,
I'm using ODI 11 g.
How will you do the map below in odi
Take the value before lengh and insert 0 and decimal is 12 for 0 before and after decimal length is 6.
Source Target
99,20 + 000000000099200000
100,20 + 000000000100200000
-2520.365 - 000000002520360000The source value is: DECIMAL (11.2)
Target value is: + 9 (12) V9 (6)Example:
Value source: 456.78
Target value: + 000000000456780000Thank you
Hi Marc,
I agree with the code you posted but dynamically, it won't hold.
Hello
I corrected the code and tested, please find below the code change and it will support dynamically based on values - (negative) + (positive) according to the prefix next to the source
Select decode (substr('-2520.365',1,1), '-','-', '+').
LPAD (substr (Replace('-2520.365','-',''), 1, InStr (Replace('-2520.365','-',''),'. ', 1)-1), 12, 0)
|| RPAD (substr (Replace('-2520.365','-',''), InStr (Replace('-2520.365','-',''),'. ', 1) + 1), 6, 0) twice;-->-000000002520365000 (exit)
Select decode (substr ('2520.365', 1, 1), '-','-', '+').
LPAD (substr (Replace('2520.365','-',''), 1, InStr (Replace('2520.365','-',''),'. ', 1)-1), 12, 0)
|| RPAD (substr (Replace('2520.365','-',''), InStr (Replace('2520.365','-',''),'. ', 1) + 1), 6, 0) twice;+ 000000002520365000 (exit)
Hope this can help you
Kind regards
Phanikanth
-
convert the string to required format
Hi gurus of the Oracle
Source string:-90-27-e4-4c-12-ff
Required string:-9027.e44c.12ff
I am capable of a result with the query below
SQL > SELECT SUBSTR(REPLACE('90-27-e4-4c-12-ff','-'),1,4) |'. ' || SUBSTR(replace('90-27-E4-4C-12-ff','-'),5,4) |'. ' || SUBSTR(replace('90-27-E4-4C-12-ff','-'),9,4) double MYSTRING;
MYSTRING
--------------
9027.e44c.12ff
can you please suggest any other alternative of queries to get the same requirement?
Thank you
Hitgon
SQL > select replace(regexp_replace('90-27-e4-4c-12-ff','(\d+)-([[:alnum:]]+)','\1\2'),'-','.') twice;
REPLACE (REGEXP
--------------
9027.e44c.12ff
-
Configure the context to return similar words
Dear experts,
We have Oracle 11.2.0.4 and we use context indexes.
What needs to be done to turn the search for the term 'Centre' Centre as well as centre automatically unless the user pertaining to the search soundex.
Thank you.
Looks like you're talking about custom synonyms. If so, you can create your own dictionary of synonyms with synonyms and use it in a function that you can use in your application, as shown below.
Scott@orcl12c > test_tab CREATE TABLE
2 (test_col CLOB)
3.
Table created.
Scott@orcl12c > INSERT ALL
2 INTO test_tab VALUES ('data center')
3 INTO test_tab VALUES ('data center')
4 INTO test_tab VALUES ('Center')
5 INTO test_tab VALUES ('other data')
6 INTO test_tab VALUES ('SUN')
7 INTO test_tab VALUES ('ORACLE')
8 SELECT * FROM DUAL
9.
6 rows created.
Scott@orcl12c > CREATE INDEX test_idx ON test_tab (test_col)
2 INDEXTYPE IS CTXSYS. FRAMEWORK
3.
The index is created.
Scott@orcl12c > START
2 CTX_THES. CREATE_THESAURUS ("test_thes");
3 CTX_THES. CREATE_RELATION ("test_thes", "center", "SYN", "Center");
4 CTX_THES. CREATE_RELATION ('test_thes', 'SUN', 'SYN', 'ORACLE');
5 END;
6.
PL/SQL procedure successfully completed.
Scott@orcl12c > CREATE or REPLACE FUNCTION synonyms
2 (p_terms IN VARCHAR2)
3 RETURN VARCHAR2
4 AS
5 v_terms VARCHAR2 (4000): = LTRIM (p_terms) | ' ';
6 v_result VARCHAR2 (4000);
7. START
8 while INSTR (v_terms, ' ') > 0 LOOP
9 v_terms: = REPLACE (v_terms, '',' ');
10 END OF LOOP;
11 while INSTR (v_terms, ' ') > 0 LOOP
12 v_result: = v_result
13 || « ET (' || CTX_THES. SYN (SUBSTR (v_terms, 1, INSTR (v_terms, ' ')-1), "test_thes"). ')';
14 v_terms: = LTRIM (SUBSTR (v_terms, INSTR (v_terms, ' ')));
15 END LOOP;
16 RETURN SUBSTR (REPLACE (REPLACE (v_result, ' {', "}) {, '}',"), 6);
Synonyms for END 17;
18.
The function is created.
Scott@orcl12c > SHOW ERRORS
No errors.
Scott@orcl12c > search_terms VARIABLE VARCHAR2 (100)
Scott@orcl12c > EXEC: search_terms: = "data center".
PL/SQL procedure successfully completed.
Scott@orcl12c > SELECT synonyms (: search_terms) FROM DUAL
2.
SYNONYMS(:SEARCH_TERMS)
--------------------------------------------------------------------------------
(DATA) AND (CENTER |) CENTER)
1 selected line.
Scott@orcl12c > SELECT * FROM test_tab
2 WHERE CONTAINS (test_col, synonyms (: search_terms)) > 0
3.
TEST_COL
--------------------------------------------------------------------------------
Data Center
Data Center
2 selected lines.
Scott@orcl12c > EXEC: search_terms: = 'ORACLE '.
PL/SQL procedure successfully completed.
Scott@orcl12c > SELECT synonyms (: search_terms) FROM DUAL
2.
SYNONYMS(:SEARCH_TERMS)
--------------------------------------------------------------------------------
(ORACLE |) SUN)
1 selected line.
Scott@orcl12c > SELECT * FROM test_tab
2 WHERE CONTAINS (test_col, synonyms (: search_terms)) > 0
3.
TEST_COL
--------------------------------------------------------------------------------
SUN
ORACLE
2 selected lines.
Post edited by: BarbaraBoehmer (corrected function)
-
SQL query to get the first four characters of an address
Hi gurus,
Can you please help me with the below quries on how to achieve this. Could be really helpful if you could provide a sample sql on your side.
Req:
I have a requriement where I should display the first four characters other than a space to address, for example: becomes R, DISH etc. F. in passing in a ROOM address a DISH 1 FLORIAN AVENUE would therefore "RAF1", while a CORNER, 23 STREET address would be "23CO".
Words such as c/o, co, rear should be ignored, if any.
Thanks in advance.
Kind regards
Peoples
Hi John,.
Here is an implementation of a pl/sql function that suggested a franc. It uses two lists, one with the words which are replaced with the first character and a second with words to ignore.
create or replace function first_four (p_input in varchar2) return varchar2 is
type t_words is table of the varchar2 (100);
p_replace t_words: = t_words ('ROOM', 'FIELD', 'FLAT', 'FLT', 'BLOCK', 'UNIT', 'STUDIOS', 'CARAVAN', 'APARTMENT');
p_ignore t_words: = t_words ("C/o ', 'CO', 'BACK TO'");
v_input varchar2 (100);
Start
-Put the entry in a local-variable he
v_input: = upper (p_input);
-delete the words contained in the ignore list
because me in 1.p_ignore.count
loop
v_input: = replace (v_input, p_ignore (i));
end loop;
-Replace the words by first character in the replacement list
for r in 1.p_replace.count
loop
v_input: = replace (v_input, p_replace (r), substr (p_replace (r), 1, 1));
end loop;
-remove the spaces and return only the first 4 characters
Return substr (replace (v_input, ' '), 1, 4);
end;
/
It returns the expected results for the four examples you gave:
SQL > with t as)
2 select address 'FLAT 3 a 12 LILLYHAM ROAD' of all the double union
3 select ' GREE LANE GLOSONTH 45' across Union double
4 Select "FLAT 3 221 b Baker Street," of all the double union
5. Select "C/o CARAVAN 32 STREET BLOK 6 RICHMOOND' of the double)
6. Select ff first_four (address) of t;
FF
--------------------------------------------------------------------------------
F3A1
45GR
F322
C32B
-
Generation of a random not as - string for example
Oracle Database 11 g Enterprise Edition Release 11.2.0.1.0 - 64 bit Production
Hello
I want to generate randomly, a string of tank that is not like a tank.
Select str of (select DBMS_RANDOM. String('U',1) double str) where str! = « A » ;
a few times I get NULL. How can I get a tank all the time? I want to create a function using this logic. can someone help me reach this goal?
Thank you
SG
Yet another way!
SUBSTR (REPLACE ('ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'X'), SELECT
DBMS_RANDOM. VALUE (1: 25),
(1) str
FROM DUAL;
See you soon,.
Manik.
-
need to get the result of vertically
Hello
declare
string_to_parse varchar2 (2000): = 'abcdefg, hiklmnopqrst;
l_count number;
l_value varchar2 (2000);
Start
string_to_parse: = string_to_parse | «, » ;
l_count: = length (string_to_parse) - length (replace (string_to_parse, ',', "));
-In oracle 11g, use regexp_count to determine l_count
because me in 1... l_count loop
Select regexp_substr(string_to_parse,'[^,]+',1,i) in the double l_value;
dbms_output.put_line (l_value);
end loop;
end;
If I run this I get years like
ABCDEFG
hiklmnopqrst
but I need the answer as
one
b
c
could someone help me to get like thisI think that's what you want:
WITH t AS (SELECT 'abcdefg,hiklmnopqrst' string_to_parse FROM dual) SELECT SUBSTR(REPLACE(string_to_parse, ','), level, 1) FROM t CONNECT BY level <= LENGTH(REPLACE(string_to_parse, ','))
-
How can I convert under query timestamp? Is the difficult part a 't' in the string.
SELECT '20080101T07:32:39.785', to_timestamp(SUBSTR('20080101T07:32:39.785',0,17),'YYYY-MM-DD HH24:MI:SS,FF') FROM DUAL;
Maybe not the best, but here's a way... first step is make your format string to match your string input and using the right index for SUBSTR. Second step is to detach the T via REPLACE()
SELECT '20080101T07:32:39.785', to_timestamp(SUBSTR(replace('20080101T07:32:39.785','T',''),1,16),'YYYYMMDDHH24:MI:SS,FF') FROM DUAL; '20080101T07:32:39.785' TO_TIMESTAMP(SUBSTR(REPLACE('2 -------------------------------- ------------------------- 20080101T07:32:39.785 01-JAN-2008 07.32.39.000000000 AM
-
Dear all,
Yesterday, I posted about general SQL ignoring the weekend of the County of the query, but all solutions failed. I'm now paste here real SQL. This SQL returns delay_days which also includes weekends. I want it must ignore weekend DAYS and counting only the DAYS WORKING (WORKING days). For example, if necessary, shipment is sent on Tuesday and if it reaches the Monday instead of 7 days, it should return 5 days as delay_days while ignoring the two weekend days.
Your help on this would be much appreciated.
SELECT ROWNUM,batchname,statusdate,nrofshipments,CITYNAME,CITY_CODE,delay_days,NULL Courier_Delivery_Time FROM ( SELECT ( REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(batchname, '46', 'F'), '33', '#'), '3', NULL), '#', '3'), '4D', 'M'), '2D', '-'))batchid,a.statusdate,(TRUNC(SYSDATE)-TRUNC(a.statusdate)) delay_days, a.nrofshipments,(c.CITYNAME) CITYNAME,c.citycode city_code FROM batch a , cities c WHERE TRUNC(a.statusdate) <=TRUNC(SYSDATE-3) AND a.status=1200 AND SUBSTR(( REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(a.batchname, '33', '#'), '3', NULL), '#', '3'), '4D', 'M'), '2D', '-')),1,4)=c.citycode ORDER BY citycode,statusdate
GQ says:
ORA-01846 : not a valid day of the week
As I indicated in my original answer my solution is dependent on NLS. It seems that your NLS_DATE_LANGUAGE is not English, that's why it does not recognize day names:
SQL> select next_day(sysdate,'SUNDAY') from dual 2 / NEXT_DAY( --------- 03-JUL-11 SQL> alter session set nls_date_language = hindi 2 / Session altered. SQL> select next_day(sysdate,'SUNDAY') from dual 2 / select next_day(sysdate,'SUNDAY') from dual * ERROR at line 1: ORA-01846: not a valid day of the week SQL>
Relevant day you either appoints or make independent NLS changing SATURDAY to TO_CHAR (TRUNC (sysdate, 'IW') - 2, "fmDAY") and SUNDAY with TO_CHAR (TRUNC (sysdate, 'IW') - 1, "fmDAY"):
SQL> alter session set nls_date_language = hindi 2 / Session altered. SQL> select next_day(sysdate,'SUNDAY') from dual 2 / select next_day(sysdate,'SUNDAY') from dual * ERROR at line 1: ORA-01846: not a valid day of the week SQL> select next_day(sysdate,TO_CHAR(TRUNC(sysdate,'IW') - 1,'fmDAY')) from dual 2 / NEXT_DAY(SYSD ------------- 03-¿¿¿¿¿ -11 SQL>
SY.
-
Linux compared to Windows XP issue - ORA-07445 10 g 10g: exception encountered
I did a full database export using exp in a base of Linux 10 g:
Linux version:Oracle Database 10g Enterprise Edition Release 10.2.0.2.0 - Prod PL/SQL Release 10.2.0.2.0 - Production "CORE 10.2.0.2.0 Production" TNS for Linux: Version 10.2.0.2.0 - Production NLSRTL Version 10.2.0.2.0 - Production
I have installed Oracle 10 g on Windows XP:Red Hat Enterprise Linux ES release 4 (Nahant Update 5)
The version of Windows XP is:Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Prod PL/SQL Release 10.2.0.1.0 - Production "CORE 10.2.0.1.0 Production" TNS for 32-bit Windows: Version 10.2.0.1.0 - Production NLSRTL Version 10.2.0.1.0 - Production
I did an import complete database after you create storage space required database 10g on Linux to Windows.System: Microsoft Windows XP Professional Version 2002 Service Pack 3 Intel(R) Core(TM)2 CPU 6300 @ 1.86GHz 1.86 GHz, 3.25 GM or RAM
On the database 10g for Windows, I put maximum SGA size to 1300 MB and the size of the Total SGA to 1000 MB. I put the overall target of PGA at 500 MB.
This Windows box will be used by more than 2 developers for a change to our application that isn't backward compatible (with respect to the database) with earlier versions of the application that uses the database. Asked me to create this so we could develop this branch without affecting the rest of the development team working on further improvements on the Linux machine.
I then ran a few packages that update data to a set of tables. It passes through a code that has a lot of data, so I have discovered all of the problems.
At a specific time in the execution of these packages, I get the following error:
I have read the trace file and isolated to a single, somewhat complex query. I tore the request into smaller requests, trying to isolate what was causing the problem. Whenever the memory image occurred, I could get simply by closing the connection and open a new connection. In my tests, I found the specific query that triggers the exception and a less effective version of this query that does not cause the exception. Please note that this exception has never happened on the Linux machine (or if it is produced on the basis of data of production or beta), and the code has been implemented for nearly 2 years.ORA-07445: exception encountered: core dump [ACCESS_VIOLATION] [_qkkIsOJKey+299] [PC:0x1E58F73] [ADDR:0x80] [UNABLE_TO_READ] []
The code that causes the problem:
The code that returns the same data, only slower and does not raise the exception:SELECT UNIQUE oc.ogc_case_id AS oc_ogc_case_id, ogc.ogc_number AS ogc_number FROM (SELECT SUBSTR (REPLACE (afd.field_text, '-', '' ), 1, 6 ) AS ogc_number FROM ewoc_hw_snap.activity_field_data afd WHERE afd.afdcd_activity_field_data_key = (SELECT afdc.activity_field_data_key FROM ewoc_hw_snap.activity_field_data_codes afdc WHERE afdc.name = 'Case Number' ) ) ogc LEFT OUTER JOIN lct_snap.ogc_cases oc ON oc.ogc_number = ogc.ogc_number
I ran both queries with SQL Developer 3.0.04 version. Developer SQL gives the error message: no more data to read from socketSELECT UNIQUE (SELECT oc.ogc_case_id FROM lct_snap.ogc_cases oc WHERE oc.ogc_number = ogc.ogc_number ) AS oc_ogc_case_id, ogc.ogc_number AS ogc_number FROM (SELECT SUBSTR (REPLACE (afd.field_text, '-', '' ), 1, 6 ) AS ogc_number FROM ewoc_hw_snap.activity_field_data afd WHERE afd.afdcd_activity_field_data_key = (SELECT afdc.activity_field_data_key FROM ewoc_hw_snap.activity_field_data_codes afdc WHERE afdc.name = 'Case Number' ) ) ogc
Any ideas?
The above query is simple I could pare to raise and then solve the problem. The patch package is not as simple as the second query above since there is more than one column of data that I must return from the lct_snap.ogc_cases table. In any case, I wouldn't have to give up using the LEFT OUTER JOIN. There must be something wrong with the database of Windows. I didn't patch the Windows database without checking first on this forum to see if anyone had less intensive alternatives.
I searched and found so many messages with the ORA-07445: exception encountered: core dump [ACCESS_VIOLATION] error, that I realize this is a somewhat generic error message.
Published by: Starlight Rider on June 2, 2011 10:01Check this metalink note: 452951.1
Concerning
REDA
-
I have a requirement with comma-separated string, I'll try to explain by example
Basically what I want is a complete string to be converted to lowercase and then underscore should be deleted and then after each _ the first character must be lowercase. I tried like below'COULUMN_NAME1,COLUMN_NAME1_NAME2,COLUMN_NAME1' output required as below 'columnName1,columnName1Name2,columnName1'
My only requirement now is to get the first character of each word after the comma to be lowercase.SQL> select replace(initcap('COULUMN_NAME1,COLUMN_NAME1_NAME2,COLUMN_NAME1'),'_',null) output_col fr om dual; OUTPUT_COL ----------------------------------------- CoulumnName1,ColumnName1Name2,ColumnName1
Thanks in advance
Published by: QWERTY on February 25, 2011 19:48Try this
with t as ( select 'COULUMN_NAME1,COLUMN_NAME1_NAME2,COLUMN_NAME1'str from dual ), t1 as ( select level rno, lower(substr(replace(initcap(regexp_substr(str, '[^,]+', 1, level)),'_'),1,1)) || substr(replace(initcap(regexp_substr(str, '[^,]+', 1, level)),'_'),2) str from t connect by level <= length(str) - length(replace(str,','))+1 ) select ltrim(sys_connect_by_path(str,','),',') str from t1 where connect_by_isleaf = 1 start with rno = 1 connect by rno = prior rno+1
Maybe you are looking for
-
I recently struggled and reinstalled my operating system to windows 7.I now have on my hard drive C:, which is the main. D: data recovery. and g: System Recovery. I never had this before that the C: & D: I want to know if I can remove it somehow.
-
EliteBook 2540p: driver missing
Hallo! I just installed Windows on Elitebook 2540p 10. All right, but a device is not recognized. ACPI\HPQ0004\3 & 21436425 & 0 Hardware IDs: ACPI\VEN_HPQ & DEV_0004 ACPI\HPQ0004 * HPQ0004 Name of the BIOS \_SB. PCI0. ACEL Please suggest me what this
-
Check if a VI runs as a Subvi or stand-alone
I have a set of measurement screws that I use as a stand-alone screws and buried deep inside the other screw that perform many different measures. Because I turn the screw, sometimes they have to initialization, VISA Open and Close VISA within struct
-
How to reinstall LaserJet P1102w USB wireless?
I use Windows XP and have a LaserJet P1102w, who was installed with a USB connection. I have a wireless connection. What I need to first uninstall the USB and then reinstall wireless using the installation disc? If this isn't the case, reinstallat
-
Dell R510 4 4 TB drives - who need to upgrade raid wired controller with S100
Hello Help a customer trying to get out of their inherited R510 servers installation to manage their backups off site. It's a R510 with S100 controller and (4) cables currently drives (all 4 to). All readers more in sheets sata directly on the mother