oracle - 我需要以下输入数据的 Sql 查询
问题描述
输入
NAME ID STR_DT END_DT
P 10 01-APR-17 04-APR-17
S 20 05-APR-17 07-APR-17
M 30 08-APR-17 10-APR-17
```
输出
NAME ID DATA
P 10 01-APR-17
P 10 02-APR-17
P 10 03-APR-17
P 10 04-APR-17
S 20 05-APR-17
S 20 06-APR-17
S 20 07-APR-17
M 30 08-APR-17
M 30 09-APR-17
M 30 10-APR-17
解决方案
干得好:
SQL> alter session set nls_date_format = 'dd.mm.yyyy';
Session altered.
SQL> with test (name, id, str_dt, end_dt) as
2 (select 'P', 10, date '2017-04-01', date '2017-04-04' from dual union all
3 select 'S', 20, date '2017-04-05', date '2017-04-07' from dual union all
4 select 'M', 30, date '2017-04-08', date '2017-04-10' from dual
5 )
6 select name, id, (str_dt + column_value - 1) data
7 from test cross join table(cast(multiset(select level from dual
8 connect by level <= end_dt - str_dt + 1
9 ) as sys.odcinumberlist))
10 order by id, data;
N ID DATA
- ---------- ----------
P 10 01.04.2017
P 10 02.04.2017
P 10 03.04.2017
P 10 04.04.2017
S 20 05.04.2017
S 20 06.04.2017
S 20 07.04.2017
M 30 08.04.2017
M 30 09.04.2017
M 30 10.04.2017
10 rows selected.
SQL>
推荐阅读
- google-sheets - 自动将 Google 表单响应中的单个行数据检索到另一个工作表中,同时忽略空白单元格
- command - 想要使用 Octave/Matlab 从终端激活虚拟环境
- excel - VBA宏过滤多个字段
- cmd - CMD 中的 ISDeploymentWizard.exe 命令(SSIS 部署)不打印任何状态指示
- ssl - 权限问题和 SSL cloudflare 问题
- python-3.x - ModuleNotFoundError:.exe 中没有名为“控制台”的模块
- oauth-2.0 - OIDC 广义范围
- java - 正确注释 RsponseDto 的字段描述
- c# - 如何在 ASP.NET Core Razor 页面中重用 _ViewImports.cshtml?
- java - Keycloak AuthenticationFlowContext 上下文 - 会话值