[英]What is rowID & rowNum (ROWID vs ROWNUM)
I'd like to know difference between rowID
and rowNUM
我想知道rowID
和rowNUM
之间的rowNUM
And how to see both of these in our table. 以及如何在我们的表中看到这两个。
when I execute this: 当我执行这个:
SELECT * FROM emp WHERE rownum=1
It returns one query but when I do the same for rowid it says 它返回一个查询,但是当我对rowid执行相同操作时,它说
inconsistent datatypes: expected ROWID got NUMBER 不一致的数据类型:预期ROWID获得NUMBER
And even in some of the tables, rownum returns null . 甚至在某些表中,rownum返回null。 Why so? 为什么这样?
Please clarify this: rowid vs rownum?(Demo query) 请澄清一下:rowid vs rownum?(演示查询)
Thank you 谢谢
EDIT: Require to use alias to display ROWID
and ROWNUM
(as they're pseudocolumn) like: 编辑:需要使用别名来显示ROWID
和ROWNUM
(因为它们是伪列),如:
SELECT rownum r1, rowid r2 FROM emp
Both, rownum and rowed are pseudo columns. rownum和rowed都是伪列。
Rowid ROWID
For each row in the database, the ROWID pseudocolumn returns the address of the row. 对于数据库中的每一行,ROWID伪列返回行的地址。
An example query would be: 一个示例查询将是:
SELECT ROWID, last_name
FROM employees
WHERE department_id = 20;
More info on rowid here: https://docs.oracle.com/cd/B19306_01/server.102/b14200/pseudocolumns008.htm 有关rowid的更多信息,请访问: https : //docs.oracle.com/cd/B19306_01/server.102/b14200/pseudocolumns008.htm
Rownum ROWNUM
For each row returned by a query, the ROWNUM pseudocolumn returns a number indicating the order in which Oracle selects the row from a table or set of joined rows. 对于查询返回的每一行,ROWNUM伪列返回一个数字,表示Oracle从一个表或一组连接行中选择行的顺序。 The first row selected has a ROWNUM of 1, the second has 2, and so on. 选择的第一行的ROWNUM为1,第二行的数量为2,依此类推。
You can limit the amount of results with rownum like this: 您可以使用rownum限制结果量,如下所示:
SELECT * FROM employees WHERE ROWNUM < 10;
More info on rownum here: https://docs.oracle.com/cd/B19306_01/server.102/b14200/pseudocolumns009.htm 关于rownum的更多信息: https : //docs.oracle.com/cd/B19306_01/server.102/b14200/pseudocolumns009.htm
Difference 区别
The actual difference between rowid
and rownum
is, that rowid is a permanent unique identifier for that row. rowid
和rownum
之间的实际区别在于,rowid是该行的永久唯一标识符。 However, the rownum is temporary. 然而,rownum是暂时的。 If you change your query, the rownum number will refer to another row, the rowid won't. 如果更改查询,则rownum编号将引用另一行,而rowid则不会。
So the ROWNUM is a consecutive number which applicable for a specific SQL statement only. 因此ROWNUM是一个连续的数字,仅适用于特定的SQL语句。 In contrary the ROWID, which is a unique ID for a row. 相反,ROWID是一行的唯一ID。
Rownum (numeric) = Generated Sequence Number of your output. Rownum(数字) =输出的生成序列号。
Rowid (hexadecimal) = Generated automatically at the time of insertion of row. Rowid(十六进制) =在插入行时自动生成。
SELECT rowid,rownum fROM EMP
ROWID ROWNUM
----- ----------------------
AAAR4AAAFAAGzg7AAA, 1
AAAR4AAAFAAGzg7AAB, 2
AAAR4AAAFAAGzg7AAC, 3
AAAR4AAAFAAGzg7AAD, 4
AAAR4AAAFAAGzg7AAE, 5
row id shows the unique identification
for row rownum
shows the unique default series of numbers. 行ID显示行rownum
的唯一identification
显示唯一的默认数字系列。
select * from emp
where rownum<=5; (it will execute correctly and gives output first 5 rows in your table )
select * from emp
where rowid<=5; (wrong because rowid helpful to identify the unique value)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.