We are using SQL Anywhere for our tablet users and Oracle 10g for our desktop users. The application is .Net application. We tried to have much common code as possible for the application against SQL Anywhere and application against Oracle. Is there a way to create a SQL Anywhere special value rownum to be equivalent to Oracle rownum? In SQL Anywhere, identity(#) can be used, but it is a function. My thought is to create a special value rownum, the inside of logic for rownum is to call identity(#). Any suggestion or input will be very helpful.

asked 08 Dec '11, 10:39

Rose%20Cao's gravatar image

Rose Cao
accept rate: 0%

edited 08 Dec '11, 11:36

Mark%20Culp's gravatar image

Mark Culp

What is your requirement to use a ROWNUM()? Is it tied to build something like a primary key value?

Or do you just need to somewhat "number" the rows of a query's result set?

(09 Dec '11, 10:30) Volker Barth

Thank you Chris, Glenn and Volker. Our application is in .Net C#, which calls lots of SQL statements saved in tables of database. The SQL statements were originally only in Oracle. The history solution for tablet users was using Microsoft Access. Two years ago, we decided to use Sybase SQL Anywhere. We became Sybase SQL Anywhere OEM parter two years ago since ASA is a real database not like Access. We tried to use same sets of SQL statements in Oracle for ASA without major modification and put lots of effort to them to make same sets of SQL statements work against Oracle and ASA. Of course we encourter lots of troubles, one of them is rownum in Oracle SQL statements. We are dreaming to use same SQL statements which use rownum in select statement or in where clause etc in ASA if we can develop some kind of special global value in ASA named rownum. F.Y.I, we developed some Oracle equivalent functions in ASA already except ROWNUM and TO_CHAR (ASA has its own TO_CHAR, but the feature is different from Oracle's TO_CHAR, don't know how to overwrite ASA's TO_CHAR with our own TO_CHAR function yet) etc.

(09 Dec '11, 10:47) Rose Cao
Replies hidden

I'm not familiar with ROWNUM(), so from your answer, I guess my last assumption is correct? In other words, you are just dealing with "numbered" result sets, not with PK generation and the like?

(09 Dec '11, 10:50) Volker Barth

Yes, that is right. We don't need PK generation or such. We need a solution to deal with Oracle "numbered" result sets to see if same set of SQL code can be used in ASA as in Oracle.

(09 Dec '11, 10:52) Rose Cao

As Chris stated, ROWNUM in Oracle is a pseudocolumn, not a function. The closes function in SQL Anywhere that matches the semantics of ROWNUM is the ROWID() function:


which returns the row identifer of the row. Caution should be used when using ROWID(), however, because its value is not immutable and a row's identifier can be reused if a row is deleted or moved (in the latter case, for example, through a REORGANIZE statement). Consequently, we do not recommend the use of ROWID() in production situations, but only its use as a diagnostic tool.

SQL Anywhere 11.0.1 supports AUTOINCREMENT columns that can be used in a way similar to what ROWNUM gives you, the major difference is that an AUTOINCREMENT column is a real column making up the schema of the table, whereas in Oracle the ROWNUM pseudocolumn is not part of the table's schema.

In version 12, SQL Anywhere introduced support for SEQUENCEs (which are also supported by Oracle) as a more flexible method to create numeric surrogate keys. A SEQUENCE column, like an AUTOINCREMENT one, is also a real column and not a pseudocolumn.

permanent link

answered 09 Dec '11, 10:27

Glenn%20Paulley's gravatar image

Glenn Paulley
accept rate: 43%

The equivalent to rownum is the NUMBER function (or the equivalent IDENTITY function) or the ROW_NUMBER function.

See http://dcx.sybase.com/index.html#1101/en/dbreference_en11/number.html for information about the NUMBER function.

See http://dcx.sybase.com/index.html#1101/en/dbusage_en11/ug-olap-s-51258147.html*d5e25328 for info about ROW_NUMBER function.

permanent link

answered 08 Dec '11, 11:31

Chris%20Keating's gravatar image

Chris Keating
accept rate: 23%

edited 08 Dec '11, 11:34

Thank you, Chris. That clears my confusing on IDENTITY function. Is there a way to use function ROW_NUMBER to create a Sybase special value to be equavilent to Oracle's ROWNUM?

(08 Dec '11, 11:44) Rose Cao

For example, I have created Microsoft Assess equavilent InStr function in Sybase for our application to keep using InStr function with expected result like in Access.

CREATE FUNCTION asp.InStr( / FUN: asp.InStr PKG: ASPEN_SYS_PKG This function maps the MS-Access INSTR() to SQL Anywhere LOCATE()
*/ in inStringToSearch long varchar, in inStringToSearchFor long varchar, in inStringToPosition integer default 0 ) returns integer not deterministic begin return LOCATE(inStringToSearch,inStringToSearchFor,inStringToPosition) end

I need a special value ROWNUM in Sybase to have same functionality of Oracle in order for application code staying same.

(08 Dec '11, 11:52) Rose Cao

I can only think of wrapping the statement in a view and aliasing the ASA function used as ROWNUM. Unlike your Access example, the ROWNUM in Oracle is a psuedocolumn not a function.

(08 Dec '11, 13:25) Chris Keating
Your answer
toggle preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here



Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported

Question tags:


question asked: 08 Dec '11, 10:39

question was seen: 6,128 times

last updated: 09 Dec '11, 10:52