Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8911439
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T03:56:39+00:00 2026-06-15T03:56:39+00:00

I have to fetch data from a running-time-defined table and get data based on

  • 0

I have to fetch data from a running-time-defined table and get data based on a running-time-defined column, I’m now using dynamic sql with ref cursor as below. Is there any more efficient ways to improve the performance ?

PROCEDURE check_error(p_table_name IN VARCHAR2
    ,p_keyword  IN VARCHAR2
    ,p_column_name IN VARCHAR2
    ,p_min_num IN NUMBER
    ,p_time_range IN NUMBER
    ,p_file_desc IN VARCHAR2
    )
IS  
   type t_crs is ref cursor;
   v_cur t_crs;

   v_file_name VARCHAR2(100);
   v_date_started DATE;
   v_date_completed DATE;
   v_counter NUMBER := 0;
   v_sql VARCHAR2(500);
   v_num NUMBER :=0;
BEGIN
   v_sql := 'SELECT '||p_column_name||', DATE_STARTED,DATE_COMPLETED FROM '||p_table_name
            || ' WHERE '||p_column_name||' LIKE '''||p_keyword||'%'' AND  DATE_STARTED > :TIME_LIMIT  ORDER BY '||p_column_name;

    OPEN v_cur FOR v_sql USING (sysdate - (p_time_range/1440));
    LOOP
        FETCH v_cur INTO v_file_name,v_date_started,v_date_completed;
        EXIT WHEN v_cur%NOTFOUND; 
        IF v_date_started IS NOT NULL AND v_date_completed IS NULL   
            AND (sysdate - v_date_started)*1440 > p_time_range THEN
                insert_record(co_alert_stuck,v_file_name,p_table_name,0,p_file_desc,p_time_range);               
        END IF;         
    END LOOP;
END;

BTW, will this make it better ?

v_sql := 'SELECT :COLUMN_NAME1, DATE_STARTED,DATE_COMPLETED FROM :TABLE WHERE :COLUMN_NAME2 LIKE :KEYWORD AND  DATE_STARTED > :TIME_LIMIT  ORDER BY :COLUMN_NAME3';

OPEN v_cur FOR v_sql USING p_column_name,p_table_name,p_column_name,p_keyword||'%',(sysdate - (p_time_range/1440)),p_column_name;
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T03:56:40+00:00Added an answer on June 15, 2026 at 3:56 am

    First, I’m not sure that I understand what the code is doing. In the code you posted (which you may have cut down to simplify things), the IF statement checks whether v_date_started IS NOT NULL which is redundant since there is a WHERE clause on DATE_STARTED. It checks whether (sysdate - v_date_started)*1440 > p_time_range which is just a redundant repetition of the WHERE clause on the DATE_STARTED column. And it checks whether v_date_completed IS NULL which would be more efficient as an additional WHERE clause in the dynamic SQL statement that you built. It would make sense to do all of your checks in exactly one place and the most efficient place to do them would be in the SQL statement.

    Second, how many rows should this query return and where is the time being spent? If the cursor potentially returns many rows (for some definition of many), you’ll get a bit of efficiency from doing a BULK COLLECT from the cursor into a collection and modifying the insert_record procedure to accept and process a collection. If the time is all spent executing the SQL statement and the query itself returns just a handful of rows, PL/SQL bulk operations would probably not make things appreciably more efficient. If the bottleneck is executing the SQL statement, you’d need to hope that an appropriate index existed on whatever table was passed in. If the bottleneck is the insert_record procedure, we’d need to know what that procedure is doing to comment.

    Third, if the insert_record procedure is (at least primarily) just inserting the data that you fetched into a different table, it would be more efficient to get rid of all the looping and just generate a dynamic INSERT statement.

    Fourth, with respect to your edit, you cannot use bind variables for table names or column names so the syntax you’re proposing is invalid. It won’t be more efficient because it will generate a bunch of syntax errors.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a MySQL DB and I fetch data from there via PowerPivot into
I have created my android code wherein I fetch all the data from facebook
In general, I have the following scenario: Fetch product and its related data from
I have serialize values in data base, i fetch them from database then when
I have a WCF service that accesses a SQL database to fetch data .
I have a PHP script that will generate a report using PHPExcel from data
I have this file 'gardens.php' , which pulls data from a table called 'generalinfo'
I have a document based application running with core data. The object model has
I have the following Query and i need the query to fetch data from
I have created a component to fetch data from a web service. The web

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.