Does Sybase ASE 12.5 support Common Table Expressions?

久未见 提交于 2019-11-29 08:01:17

Sybase ASE 12.5 (and also 15.0) doesn't support CTE.


You can use a inner query to solve your problem.

A simple CTE like this:

WITH Sales_CTE (Folders_Id)
AS
-- Define the CTE query.
(
    SELECT Folders_Id FROM Folders
)
SELECT Folders_Id FROM Sales_CTE

is the same as this:

SELECT aux.Folders_Id
FROM (SELECT Folders_Id FROM Folders) aux

For a litle more info, check this!

PerformanceDBA
  1. Since 1984, the Standard, and Sybase, allowed for full recursion. We generally perform recursion in a stored proc, so that depth is controlled, infinite loops are avoided, and execution is faster than uncompiled SQL, etc.

    Stored procs have no limits to recursion, result set construction etc. Of course, defining the content of the brackets as a View would make it faster again (it is after all a real View, not one that we have to Materialise every time we need it).

    Point being, if you were used to this method (recursion in the server, a proc coded for recursion), as I am, there is no need for CTEs, with its new syntax; uncompiled speeds; temp tables; work tables; a cursor "walking" the hierarchy; all resulting in horrendous performance.

    A recursive proc reads only the data, and nothing but the data, and reads only those rows that qualify at each level of the recursion. It does not use a cursor. It does not "walk", it builds the hierarchy.

  2. A second option is to use Dynamic SQL. Simply construct the SELECTs, one per level of the hierarchy, and keep adding the UNIONs until you run out of levels; then execute.

You can use a function to provide the facility of a CTE, but do not do so. A function is intended for a different, column-oriented purpose, the code is subject to those constraints. It is scalar, good for constructing a column value. Stored procs and CTEs are row-oriented.

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