Analog of “select level from dual connect by level < 10” for Sybase?

左心房为你撑大大i 提交于 2019-12-08 05:57:22

问题


By select level from dual connect by level < 10 in Oracle I can generate sub-query of integer and transform it to another sequence.

Is this possible with Sybase?

PS I want to find dates where are no data in table (missing days). In Oracle I do this as:

select to_date('2012-01-01', 'yyyy-mm-dd')+level-1 from dual
    connect by level < to_date('2013-01-01', 'yyyy-mm-dd') - to_date('2012-01-01', 'yyyy-mm-dd')
  MINUS
select distinct date from TBL
    where date between to_date('2012-01-01', 'yyyy-mm-dd')
                   and to_date('2013-01-01', 'yyyy-mm-dd')

In Sybase analog for MINUS is:

select whatever from table1 T1
  where not exists
  ( select 1 from table2 where id = T1.id )

but I don't know analog for connect by level...

UPDATE Is there any way to create temporary table in Sybase without actually storing data to disk?


回答1:


The Oracle syntax you use is a hierarchical query used as a row generator. Sybase has the sa_rowgenerator system procedure can be used to generate a set of integers between a start and end value.

The following will produce a column of integers between 1 and 255.

SELECT row_num FROM sa_rowgenerator( 1, 255 );



回答2:


sa_rowgenerator system procedure required DBA authority . Users without DBA authority must be granted EXECUTE permission to run the stored procedure.



来源:https://stackoverflow.com/questions/16624620/analog-of-select-level-from-dual-connect-by-level-10-for-sybase

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!