[英]Extracting data from column to a new column sql developer
我已將數據導入SQL Developer,並且需要將數據從一列分離到新列中。 例如,我有:
Temp_Title
Congo (1995)
Nadja (1993)
我需要將標題中的年份刪除到名為temp_year
的新列中。 有人告訴我可以使用“解析”,但是我不確定從哪里開始。 任何幫助是極大的贊賞。
您沒有指定要使用的數據庫。 另外,您提到了“ SQL Developer”(由Oracle設計),但是用“ plsqldeveloper”標簽標記了問題,因此-實際查詢可能取決於您未與我們共享的某些信息。
無論如何,為了讓您入門,這是一個示例(基於Oracle),它使用兩個選項:
SUBSTR
+ INSTR
組合 。
SQL> with test (temp_title) as
2 (select 'Congo (1995)' from dual union all
3 select 'Nadja (1993)' from dual union all
4 select 'Back to the future (1985)' from dual
5 )
6 select
7 substr(temp_title, 1, instr(temp_title, '(') - 1) title,
8 substr(temp_title, instr(temp_title, '(') + 1, 4) year,
9 --
10 regexp_substr(temp_title, '(\w| )+') title2,
11 rtrim(regexp_substr(temp_title, '\d+\)$'), ')') year2
12 from test;
TITLE YEAR TITLE2 YEAR2
-------------------- ---------------- -------------------- -----
Congo 1995 Congo 1995
Nadja 1993 Nadja 1993
Back to the future 1985 Back to the future 1985
SQL>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.