Mah*_*rpe 1 sql oracle number-formatting
我有一个名为department_details 的表,其中包含一个dept_id 列,其中包含类似的值
10_prod
20_r&d
80_sales
Run Code Online (Sandbox Code Playgroud)
等我想要一个查询,它会给我输出
ten_prod
twenty_r&d
eighty_sales
Run Code Online (Sandbox Code Playgroud)
等等。
这是一种选择:
SQL> with test (col) as
2 (select '10_prod' from dual union all
3 select '20_r&d' from dual union all
4 select '80_sales' from dual
5 )
6 select col,
7 regexp_substr(col, '^\d+') num,
8 to_char(to_date(substr(col, 1, instr(col, '_') - 1), 'j'), 'jsp') wrd,
9 --
10 to_char(to_date(substr(col, 1, instr(col, '_') - 1), 'j'), 'jsp') ||
11 substr(col, instr(col, '_')) result
12 from test;
COL NUM WRD RESULT
-------- -------------------------------- ---------- --------------------
10_prod 10 ten ten_prod
20_r&d 20 twenty twenty_r&d
80_sales 80 eighty eighty_sales
SQL>
Run Code Online (Sandbox Code Playgroud)
它有什么作用(一步一步,以便您可以遵循它):
substr+ instr;可能更好)。它 - 此外 - 使用“J”格式将其转换为日期,并使用 JSP 格式将其转换为字符。这是拼写数字的常用方法| 归档时间: |
|
| 查看次数: |
102 次 |
| 最近记录: |