PL / SQL使用EXEC_SQL获取下一个和上一个记录Oracle形成6i

时间:2013-05-27 19:15:41

标签: oracle plsql plsqldeveloper oracleforms

我正在使用oracle表单6i,我使用EXEC_SQL创建了一个动态sql。我正在使用单个块记录但是当我说next_record我没有移动时,我无法在记录之间导航。没有错误只是记录没有进入下一个记录;

每次用户点击工具栏上的'first','previous','next'和'last'按钮时,都会触发此代码。查询返回的记录我只是在单个记录块中通过导航按钮访问它时遇到问题。

代码

BEGIN   
    cursor_number := Exec_SQL.Open_cursor;  
    recordcount_cursor_number := Exec_SQL.Open_cursor;

  --build SQL
  Sql_Stmt := 'SELECT .......   FROM table WHERE 1 = 1 '||where_clause ||' order by surname';--dynamic where

    --cannot use the dynamic where since this changes based on rowid                                
    Sql_CountStmt := 'SELECT COUNT(DISTINCT(ins_reg_no))FROM table WHERE 1 = 1 '||:global.ins_last_where_clause;--dynamic where

--  Show_Message(where_clause);                                                         
    --Parse SQL statement
    EXEC_SQL.PARSE(cursor_number, Sql_Stmt);
    EXEC_SQL.PARSE(recordcount_cursor_number, Sql_CountStmt);

    --Define the cloums for the data to be returned
    EXEC_SQL.DEFINE_COLUMN(cursor_number,1, ins_reg_no);
    ......
    ......
    ......

    EXEC_SQL.DEFINE_COLUMN(recordcount_cursor_number,1,totalRecords);

    --Execute the cursor
    Count := EXEC_SQL.EXECUTE(cursor_number);

    CountRec := EXEC_SQL.EXECUTE(recordcount_cursor_number);    

        WHILE EXEC_SQL.FETCH_ROWS(recordcount_cursor_number)> 0 LOOP    
            --SET_ITEM_PROPERTY(CURSOR_STYLE,'BUSY');               
                EXEC_SQL.COLUMN_VALUE(recordcount_cursor_number,1,totalRecords);            
                :global.ins_last_record_click := totalRecords;
        END LOOP;

    EXEC_SQL.CLOSE_CURSOR(recordcount_cursor_number);--very important to close cursor since system can freeze when navigating records

    IF(to_number(:global.ins_last_record_click) != 0)THEN
        :global.ins_last_record_click := totalRecords;

    WHILE EXEC_SQL.FETCH_ROWS(cursor_number)> 0 LOOP


            EXEC_SQL.COLUMN_VALUE(cursor_number,1,ins_reg_no);
            .......
            .......
            ........

            --For each operation here that request data to get to the record

                IF(request = 'GET_ALL')THEN
                    --LAST_RECORD;  
                    FIRST_RECORD;       
                    --EXIT WHEN :SYSTEM.LAST_RECORD = 'TRUE';                                           
                ELSIF(request = 'NEXT') THEN
                    --LAST_RECORD;
                    NEXT_RECORD;                
                ELSIF(request = 'PREVIOUS')THEN
                --LAST_RECORD;
                PREVIOUS_RECORD;
                ELSIF(request = 'FIRST')THEN
                    FIRST_RECORD;               
                END IF;

            END LOOP;       


            EXEC_SQL.CLOSE_CURSOR(cursor_number);--very important to close cursor since system can freeze when navigating records   
            --set form fields qual to the cursor data
            :ins_reg_no             := ins_reg_no;
            :ins_mar_stat           := ins_mar_stat;
            :ins_oth_name           := ins_oth_name ;
            :ins_sex                := ins_sex;
            :ins_dob                := ins_dob;
            :ins_pob                := ins_pob;
            ...............
            ...............

      GO_BLOCK('TOOLBAR-BLK');  
    ELSE
        Message('Query Caused No Records To Be Retrived',NO_ACKNOWLEDGE);
    END IF;

END;

1 个答案:

答案 0 :(得分:1)

我建议您将块(表单)中的查询数据源名称属性修改为您的查询,在括号中(select ... from ... where ...)并将查询数据源类型属性更改为“来自条款“。

您还可以使用set_block_property内置包更改代码中的查询文本。

比将表单打包在包中容易得多。

检查出来:https://sites.google.com/site/craigsoraclestuff/oracle-forms---how-to-s/forms-how-to---base-a-block-on-a-from-clause-query

对于“单记录块”,我建议您尝试使用多记录块,但将显示的记录数属性设置为1。

希望它有所帮助。