Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Sybase ASE connect by level equivalent

I want to generate numbers from 0 to 9000000. In Oracle, I can use the below code. How do I do this in Sybase ASE?

This is in Oracle:

SELECT level  Num
FROM DUAL
CONNECT BY LEVEL  <= 9000000
ORDER BY Num;

How to do this in Sybase ASE?

I cannot create a table and add an identity, because I need the numbers from 1 to 9000000, so a table will be complex. Is there a query to do this?

like image 547
Moudiz Avatar asked May 17 '17 15:05

Moudiz


People also ask

How do I connect to Sybase ASE?

To connect to Sybase ASEOn the File menu, select Connect to Sybase. If you previously connected to Sybase, the command name will be Reconnect to Sybase. In the Provider box, select any of the installed providers on the machine to connect to Sybase server.

How do I connect to a database in Sybase?

Use the Connect to Sybase dialog box to connect to the Sybase Adaptive Server Enterprise (ASE) instance that you want to migrate. To access this dialog box, on the File menu, select Connect to Sybase. If you have previously connected, the command is Reconnect to Sybase.

How is Sybase different from SQL Server?

Microsoft® SQL Server is a database management and analysis system for e-commerce, line-of-business, and data warehousing solutions. What is Sybase? Drive faster, more reliable online transaction processing (OLTP) for less. Modernize and accelerate your transaction-based applications on premise and in the cloud.

What is difference between Sybase and Oracle?

A key difference is that the Sybase data engine can have multiple databases within one engine. Oracle, on the other hand, has one database for the entire data engine. This can cause customers to believe they need to create an Oracle database server for each Sybase database.


1 Answers

In Sybase IQ, there's a system procedure that can be used to generate numbers: sa_rowgenerator

You could have done :

 SELECT row_num FROM sa_rowgenerator( 1, 9000000);

I don't know Sybase ASE at all, so I googled it and have found that this procedure isn't available in ASE, but that an alternative exists :

The SQL Anywhere system procedures sa_rowgenerator, sa_split_list, and sa_conn_info are not supported by ASE. An ASE master database contains a table, spt_values, that can be used to SELECT integer values in a way similar to that of the sa_rowgenerator procedure, or SQL Anywhere’s dbo.row_generator system table.

Source : Migrating SQL Anywhere database applications to ASE

This table spt_values containing integer numbers is incredibly NOT documented. It's like a ghost table.

I suggest that you give this a try :

select number 
FROM master.dbo.spt_values
WHERE number BETWEEN 0 AND 9000000

But I am not responsible if your database system explodes ;-)

like image 120
Thomas G Avatar answered Sep 30 '22 16:09

Thomas G