Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Join a cursor or record set in oracle

I have good experience in sybase and have started looking into oracle in free time. Most of the sybase procedures that i have worked with have temp tables and it makes sense to join two or more temp tables get a result set.

Question: Is there a way to join two or more cursors like a logical table.

Something like:

SELECT c1.id, 
       c2.name 
  FROM cursorEmp c1, 
       CursorDept c2 
 WHERE c1.DeptId = c2.DeptId
like image 893
Shah Al Avatar asked Nov 08 '10 03:11

Shah Al


People also ask

Can we use join in cursor?

Whenever we use JOIN in a cursor on two or more tables (ORDERS and TRANSACTIONS in this case) a temporary table is generated in the virtual memory. However, since this is a temporary table we can fetch data from this table but it is not possible to update this table.

Can we join cursor and table?

You cant join a cursor to a table. cursor is a SQL work area where instruction to execute a SQL is processed. 1.

What is the difference between cursor and record in PL SQL?

A record is similar to a table row, can hold one value for each column at a time. cursors are like "tables" they may hold multiple rows (records if you will).

When should we use cursor in Oracle?

To execute a multi-row query, Oracle opens an unnamed work area that stores processing information. A cursor lets you name the work area, access the information, and process the rows individually.


1 Answers

You cannot join two cursors, no.

You could, of course, combine the two underlying queries, i.e.

SELECT c1.id,
       c2.name
  FROM (SELECT * FROM emp WHERE ename = 'KING') c1,
       (SELECT * FROM dept WHERE dname = 'ACCOUNTING') c2
 WHERE c1.DeptID = c2.DeptID

In Oracle, since readers do not block writers (and vice versa), it is very rarely necessary to use temporary tables. You would normally just query the underlying tables using views as appropriate to provide appropriate levels of abstraction.

like image 173
Justin Cave Avatar answered Sep 28 '22 06:09

Justin Cave