从给定模式 Oracle 构造模式
我想根据存储在视图中的给定模式构建该系列。生成未来 1 年的模式。我尝试使用 row_number
和 connect by
和 Lead
,但无法构建。 模式 ID 可以是任意随机数,并且不按顺序排列。 每个循环都会跳过接下来的两个 id。
换句话说,从视图中出现的模式,我必须查看哪两个模式 id 丢失或没有日期,然后在下一次迭代中,这些模式 id 将具有日期,而接下来的两个模式将没有日期。并且很快.. 我不需要显示日期为 NULL 的日期,这也完全没问题。 我只是为了让它易于理解。
我目前使用 Oracle 12.1
预期输出
等等...
I want to construct the series from a given pattern stored in a view.Generate the pattern for next 1 year. I tried to userow_number
and connect by
and Lead
,but was not able to construct.
The pattern id can be any random number and not in sequence.
Every cycle skip the next two ids.
In other words,from the pattern coming in the view,I have to see which two pattern id's are missing or do not have date and then in next iteration, those pattern id's will have date and the next two in sequence will not have.And so on..
I do not need to show the ones with NULL dates,that's perfectly fine too.
I just put to make it understandable.
I am currently using Oracle 12.1
Expected output
and so on...
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
对于这个表(表名是“pattern”):
这个 plsql 代码:
给出这个结果:
它仍然适用于这种模式:
这是结果:
结果从表 patern 的 min(date) 到结尾那一年。
该代码仅适用于模式中的 2 个空值。
在 dbms_output.put_line() 过程所在的地方,您可以插入另一个表。
For this table (table name is "patern"):
This plsql code:
Gives this result:
And it still works for this kind of pattern:
Here is the result:
The result goes from min(date) from table patern to the end of that year.
The code works only for 2 nulls in pattern.
Where the dbms_output.put_line() procedure is u can make an insert into another table.
这是我针对同一问题的sql解决方案,
这很复杂,但我不知道更好:)
结果:
PS。它不像我发布的 plsql 代码那样灵活,对于每个 patern_id 超过 2 个空值,它不起作用,有时它会稍微超出 31.12。模式年份(如果超过 31.12,我标记了调节日期的代码行。只需减少一点数字)
Here is my sql solution for the same problem,
it is very complicated but i don t know better :)
Result:
PS. it is not flexible like plsql code I posted, it won t work for more then 2 nulls per patern_id and sometimes it will go little bit beyond 31.12. of the pattern year (I marked the line of code that regulates date if it goes beyond 31.12. just reduce the number little bit)