Home > database >  Oracle paging query, using a cursor
Oracle paging query, using a cursor

Time:09-28

Various great spirit, I ask, I want to query table M21_RECEIPT_INFO data paging query, query the first page, each page 10 records, but found that the cursor definition condition does not work, is the list of all the data are found out, why condition doesn't work?
 
The EXEC SQL DECLARE receipt_cursor CURSOR FOR
SELECT * FROM (
SELECT the M1. *, ROWNUM RN FROM (
SELECT * FROM M21_RECEIPT_INFO M WHERE TELLER_NUMBER=: teller_number1 AND
SAVE_RESULT=: save_result1 AND TRANDE_TIME & lt;=: end_time AND TRANDE_TIME & gt; M1=: begin_time)
WHERE ROWNUM & lt; M2=10)
WHERE the M2. An RN & gt; 0;

The EXEC SQL OPEN receipt_cursor;//open the cursor
for(; I<=number; I++)
{
The EXEC SQL FETCH receipt_cursor INTO: receipt_tables;
If (I==1)
Snprintf (sFhnr, sizeof (sFhnr), "% s | s | | s | | s | | s | | | % d", receipt_tables. Receipt_number, receipt_tables. Trande_type, receipt_tables. Customer_name, receipt_tables. Trande_time, receipt_tables. Save_result, receipt_tables. Reprint_number);
The else
^ sprintf (sFhnr, "% s % s | s | | s | | s | | s | | | % d", sFhnr, receipt_tables. Receipt_number, receipt_tables. Trande_type, receipt_tables. Customer_name, receipt_tables. Trande_time, receipt_tables. Save_result, receipt_tables. Reprint_number);
}
The EXEC SQL CLOSE receipt_cursor;//close the cursor

CodePudding user response:

SELECT *, ROWNUM RN FROM M21_RECEIPT_INFO M WHERE TELLER_NUMBER=: teller_number1 AND
SAVE_RESULT=: save_result1 AND TRANDE_TIME & lt;=: end_time AND TRANDE_TIME & gt; M1=: begin_time)
WHERE ROWNUM & lt;=10

?

CodePudding user response:

Agree with upstairs
SELECT *, ROWNUM RN FROM M21_RECEIPT_INFO M WHERE TELLER_NUMBER=: teller_number1 AND
SAVE_RESULT=: save_result1 AND TRANDE_TIME & lt;=: end_time AND TRANDE_TIME & gt; M1=: begin_time)
WHERE ROWNUM & lt;=10

CodePudding user response:

When directly use rownum doing conditions must contain rownum=0, for example,
Select * from a
Where rownum & lt;=10;
Need to query does not contain 0, need the rownum as solid column, such as
Select * from
(
Select a. *, rownum as an rn from a
B)
Where b.r n between 6 and 10;
  • Related