I need to Update my row with english version - sql

I have a column which includes rows like this : MER.Fiyatlandırma Müdür Yardımcısı.
SELECT name, SUBSTR(
name,
INSTR(name, '.', 1, 1),
INSTR(name, '.', 1, 2) + 1 - INSTR(name, '.', 1, 1)
) AS deneme
FROM HR_ALL_POSITIONS_F;
I used this code and my rows looks like .Fiyatlandırma Müdür Yardımcısı.
Also ı have an excel file which includes .Fiyatlandırma Müdür Yardımcısı. this row and english version.
I need to change .Fiyatlandırma Müdür Yardımcısı. this to Price Vice Manager.
How can ı do that.
UPDATE denememusa123
SET denememusa123.eklenecekkolon = (SELECT ENGLISHPOSITION FROM pozisyontanimlama)
WHERE (SELECT SUBSTR (name,
INSTR (name,
'.',
1,
1),
INSTR (name,
'.',
1,
2)
+ 1
- INSTR (name,
'.',
1,
1))
FROM HR_ALL_POSITIONS_F) = (Select TURKISHPOSITION FROM pozisyontanimlama);
(I tired this but it is not working.
ora-01427:single-row subquery returns more than one row )
Help Please.

You can use a MERGE statement:
MERGE INTO denememusa123 dst
USING (
WITH split_denememusa123 (rid, prefix, position, suffix) AS (
SELECT rowid AS rid,
SUBSTR(
eklenecekkolon,
1,
INSTR(eklenecekkolon, '.', 1, 1)
) AS prefix,
SUBSTR(
eklenecekkolon,
INSTR(eklenecekkolon, '.', 1, 1) + 1,
INSTR(eklenecekkolon, '.', 1, 2) - INSTR(eklenecekkolon, '.', 1, 1) - 1
) AS position,
SUBSTR(
eklenecekkolon,
INSTR(eklenecekkolon, '.', 1, 2)
) AS suffix
FROM denememusa123
WHERE INSTR(eklenecekkolon, '.', 1, 2) > 0
)
SELECT s.rid, s.prefix || p.englishposition || s.suffix AS position
FROM split_denememusa123 s
INNER JOIN pozisyontanimlama p
ON (p.turkishposition = s.position)
) src
ON (src.rid = dst.ROWID)
WHEN MATCHED THEN
UPDATE SET dst.eklenecekkolon = src.position;
Which, for the sample data:
CREATE TABLE denememusa123 (eklenecekkolon) AS
SELECT 'MER.Fiyatlandırma Müdür Yardımcısı.XYZ' FROM DUAL;
CREATE TABLE pozisyontanimlama (turkishposition, englishposition) AS
SELECT 'Fiyatlandırma Müdür Yardımcısı', 'Price Vice Manager' FROM DUAL
Then after the MERGE the table contains:
EKLENECEKKOLON
MER.Price Vice Manager.XYZ
fiddle

Related

extract data sql

Example: Below is the string(sentence) in field and I want to extract the specific data from the below patterns using select query in different fields:
i )
Input :
/a03/infor/current/server/infa_sh/ScriptFil/infa_common/adap_main 'FI_RE_PRJ' 'wf_RE_ACC_TIE_HIS_MNT_EN_AM'
Output :
Select query to fetch FI_RE_PRJ and wf_RE_ACC_TIE_HIS_MNT_EN_AM
Other pattern I have is :
Input :
$SCRIPTS/run_in.ksh -f FI_FLE_PRJ -wait wf_FI_SV_CNCL_RP_BAS_KF
Output :
Select query to fetch FI_FLE_PRJ and wf_FI_SV_CNCL_RP_BAS_KF from input
We can try using REGEXP_SUBSTR with a capture group:
SELECT
REGEXP_SUBSTR(col, '''(.*?)''', 1, 1, NULL, 1) AS first,
REGEXP_SUBSTR(col, '''(.*?)''', 1, 2, NULL, 1) AS second
FROM yourTable;
You can use simple string functions (which are much faster than regular expressions):
SELECT SUBSTR( value, pos1 + 1, pos2 - pos1 - 1 ) AS quote1,
SUBSTR( value, pos3 + 1, pos4 - pos3 - 1 ) AS quote2
FROM (
SELECT value,
INSTR(value, '''', 1, 1) AS pos1,
INSTR(value, '''', 1, 2) AS pos2,
INSTR(value, '''', 1, 3) AS pos3,
INSTR(value, '''', 1, 4) AS pos4
FROM table_name
)
Which, for the sample data:
CREATE TABLE table_name (value) AS
SELECT '/a03/infor/current/server/infa_sh/ScriptFil/infa_common/adap_main ''FI_RE_PRJ'' ''wf_RE_ACC_TIE_HIS_MNT_EN_AM''' FROM DUAL;
Outputs:
QUOTE1
QUOTE2
FI_RE_PRJ
wf_RE_ACC_TIE_HIS_MNT_EN_AM
fiddle

how can I get the specified content by the string

QUESTION DESCRIPTION:
My oracle query SQL result have a column, the column value is a string description like as follow.
How can I get the special substring that I want, such as I only want the pilot's name.
{"flightRiskValue":{"airportDifficulty":0.00,"airportExp":0.00,"airportExp_captain":0.00,"airportTechNos":0.20,"airportTechNos_captain":0.40,"flightCrewNum":0.00,"flightExp":0.00,"flightExp_captain":0.00,"groupExp":0.70,"ilsWorkStatus":0.00,"pilotCrewLimit":0.00,"pilotCrewLimit_captain":0.00,"pilotDutyLevel":0.05,"pilotDutyLevel_captain":0.05,"pilotFindAnyFemale":0.00,"pilotScheduleTechLevel":0.00,"pilotScheduleTechLevel_captain":0.00,"pilotWorkTimeMonth":0.00,"pilotWorkTimeMonth_captain":0.00,"pilotWorkTimeWeek":0.15,"pilotWorkTimeWeek_captain":0.10,"pilotsIsDeptTeam":0.00,"rain":0.00,"rainAndSnow":0.00,"seeing":0.00,"snow":0.00,"wind":0.00},"pilotDTOList":["副驾驶:5-2|杜佳佳|F3;","副驾驶:5-1|凯尔|F4;","第二机长/巡航机长:5-1|贺云|A1;","机长:5-2|张磊3|A1;"],"riskValue":1.95,"version":"1"}
EXPECTED:
How can I get the special substring such as follow I want substring:
|杜佳佳|,|凯尔|,|贺云|,|张三|
and I want a column become more columns according to this column
first pilot name
second pilot name
....
杜佳佳
凯尔
贺云...
You can extract each of the items in the JSON array directly into different columns (eliminating the need to PIVOT) and then find the substrings (without needing to use [slow] regular expressions):
SELECT SUBSTR(
pilot1,
INSTR(pilot1, '|', 1, 1) + 1,
INSTR(pilot1, '|', 1, 2) - INSTR(pilot1, '|', 1, 1) - 1
) AS first_pilot_name,
SUBSTR(
pilot2,
INSTR(pilot2, '|', 1, 1) + 1,
INSTR(pilot2, '|', 1, 2) - INSTR(pilot2, '|', 1, 1) - 1
) AS second_pilot_name,
SUBSTR(
pilot3,
INSTR(pilot3, '|', 1, 1) + 1,
INSTR(pilot3, '|', 1, 2) - INSTR(pilot3, '|', 1, 1) - 1
) AS third_pilot_name,
SUBSTR(
pilot4,
INSTR(pilot4, '|', 1, 1) + 1,
INSTR(pilot4, '|', 1, 2) - INSTR(pilot4, '|', 1, 1) - 1
) AS fourth_pilot_name
FROM table_name t
CROSS APPLY JSON_TABLE(
t.value,
'$'
COLUMNS (
pilot1 NVARCHAR2(200) PATH '$.pilotDTOList[0]',
pilot2 NVARCHAR2(200) PATH '$.pilotDTOList[1]',
pilot3 NVARCHAR2(200) PATH '$.pilotDTOList[2]',
pilot4 NVARCHAR2(200) PATH '$.pilotDTOList[3]'
)
) j
Which, for the sample data, outputs:
FIRST_PILOT_NAME
SECOND_PILOT_NAME
THIRD_PILOT_NAME
FOURTH_PILOT_NAME
杜佳佳
凯尔
贺云
张磊3
db<>fiddlle here

variable within a case expression oracle

I have the following:
SELECT name,
listagg(
CASE length(TRIM(regexp_substr(lower(docs),
'process\s+explanation\s*:\s*(.*?)(\.\s*final activity|$)',
1, 1, 'i', 1)))
WHEN 0 THEN
lower(docs)
ELSE
regexp_substr(lower(docs),
'process\s+explanation\s*:\s*(.*?)(\.\s*final activity|$)',
1, 1, 'i', 1)
END, '. '
) AS final_doc
FROM my_table
GROUP BY
name
I don't want to repeat the regular expression: 'process\s+explanation\s*:\s*(.*?)(\.\s*final activity|$)'. I just want to define it once and use it. Or preferrably, I don't want this entire line duplicated: regexp_substr(lower(docs), 'process\s+explanation\s*:\s*(.*?)(\.\s*final activity|$)', 1, 1, 'i', 1). How can I do that? Version is 19c
You can use Common Table expression(WITH..AS) in such a way that
WITH t AS
(
SELECT m.*,
REGEXP_SUBSTR(docs,
'process\s+explanation\s*:\s*(.*?)(\.\s*final activity|$)',
1,
1,
'i',
1) AS rgs
FROM my_table m
)
SELECT name,
LISTAGG(CASE length(TRIM(rgs))
WHEN 0 THEN
lower(docs)
ELSE
rgs
END,
'. ') AS final_doc
FROM t
GROUP BY name

Msg 240, Types don't match between the anchor and the recursive part in column

I am trying to split a row when the ';' character appears. I have a list with projects, where one of the columns states which district the project belongs to. However some projects appears in multiple districts and is therefore written like "1;2;3" (District 1, 2 and 3). I want to create three rows form this and split on the ';'.
The error message says:
Msg 240, Level 16, State 1, Line 13
Types don't match between the anchor and the recursive part in column "DataItem" of recursive query "tmp".
I tried the split_string, but discovered my server is 2014 and lacks compatibility.
WITH tmp(Oppdragsnr, Kommune, DataItem, Kommunenr) AS
(
SELECT
Oppdragsnr,
Kommune,
LEFT(Kommunenr, CHARINDEX(';', Kommunenr + ';') - 1),
STUFF(Kommunenr, 1, CHARINDEX(';', Kommunenr + ';'), '')
FROM
oppdragene
UNION all
SELECT
Oppdragsnr,
Kommune,
LEFT(Kommunenr, CHARINDEX(';', Kommunenr + ';') - 1),
STUFF(Kommunenr, 1, CHARINDEX(';', Kommunenr + ';'), '')
FROM
tmp
WHERE
Kommunenr > ''
)
SELECT
Oppdragsnr,
Kommune,
DataItem
FROM
tmp
ORDER BY
Oppdragsnr
I would like the output to be a new table with new rows for every project that appears in multiple districts.
You should probably CAST to INT the DataItem column in the base and recursive part of the query, the following query should work for you
;WITH tmp(Oppdragsnr, Kommune, DataItem, Kommunenr) AS
(
SELECT
Oppdragsnr,
Kommune,
CAST(LEFT(Kommunenr, CHARINDEX(';', Kommunenr + ';') - 1) AS INT),
STUFF(Kommunenr, 1, CHARINDEX(';', Kommunenr + ';'), '')
FROM
oppdragene
UNION all
SELECT
Oppdragsnr,
Kommune,
CAST(LEFT(Kommunenr, CHARINDEX(';', Kommunenr + ';') - 1) AS INT),
STUFF(Kommunenr, 1, CHARINDEX(';', Kommunenr + ';'), '')
FROM
tmp
WHERE
Kommunenr > ''
)
SELECT
Oppdragsnr,
Kommune,
DataItem
FROM
tmp
ORDER BY
Oppdragsnr

Substring between characters in Oracle 9i

In later versions I can use this regexp_substr:
SELECT
ID,
regexp_substr(ID, '[^.]+', 1, 2) DATA 1,
regexp_substr(ID, '[^.]+', 1, 3) DATA 2
FROM employees
Table: Employees
ID
--------------------------
2017.1.3001-ABC.01.01
2017.2.3002-ABCD.02.02
2017.303.3003-ABC.03.03
2017.404.3004-ABCD.04.04
Expected output:
ID DATA 1 DATA 2
------------------------ ------ ---------
2017.1.3001-ABC.01.01 1 3001-ABC
2017.2.3002-ABCD.02.02 2 3002-ABCD
2017.303.3003-ABC.03.03 303 3003-ABC
2017.404.3004-ABCD.04.04 404 3004-ABCD
Please help me to get the sub-string between . characters in ID column in SQL Oracle 9i.
You don't need regular expressions - just use SUBSTR and INSTR:
SELECT id,
SUBSTR( id, dot1 + 1, dot2 - dot1 - 1) AS data1,
SUBSTR( id, dot2 + 1, dot3 - dot2 - 1) AS data2
FROM (
SELECT id,
INSTR( id, '.', 1, 1 ) AS dot1,
INSTR( id, '.', 1, 2 ) AS dot2,
INSTR( id, '.', 1, 3 ) AS dot3
FROM employees
);