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

  • Home
  • SEARCH
  • 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 9100591
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T00:54:19+00:00 2026-06-17T00:54:19+00:00

I am new with these oracle dynamic queries, I am just trying to build

  • 0

I am new with these oracle dynamic queries, I am just trying to build a dynamic query, so I could get records according to it.

Here is my PL/ SQL statement:

declare
sql_query varchar2(5000) := 'select FKOM_OFFICE_ID,FKBAM_BUDGET_ID ';
begin
for x in (select distinct PFS_SOURCE_ID,PFS_SOURCE_ENG from PBS_FC_SOURCE WHERE PFS_UPPER_SOURCE_ID!=0 ORDER BY PFS_SOURCE_ID ASC )
loop
    sql_query := sql_query ||
        ' , nvl(sum(case when FKBAB_SOURCE_ID = '||x.PFS_SOURCE_ID||' then FKOD_AMOUNT ELSE 0 end),0) as source_'||x.PFS_SOURCE_ID;
        dbms_output.put_line(sql_query);
end loop;
sql_query := sql_query || ' FROM FMS_K_OFFICEWISE_DTL
JOIN FMS_K_OFFICEWISE_MST ON FMS_K_OFFICEWISE_MST.FKOM_OFFICE_MST_ID=FMS_K_OFFICEWISE_DTL.FKOD_OFFICE_MST_ID
JOIN FMS_K_BUDGET_ALLOCATION_DTL ON FMS_K_BUDGET_ALLOCATION_DTL.FKBAD_BUDGET_ALLOC_DTL_ID=FMS_K_OFFICEWISE_DTL.FKOD_BUDGET_ALLOC_AD_ID
JOIN FMS_K_BUDGET_ALLOCATION_MST ON FMS_K_BUDGET_ALLOCATION_MST.FKBAM_BUDGET_ALLOC_ID=FMS_K_BUDGET_ALLOCATION_DTL.FKBAB_BUDGET_ALLOC_ID
JOIN PBS_FC_BUDGET ON PBS_FC_BUDGET.PFB_BUDGET_ID=FMS_K_BUDGET_ALLOCATION_MST.FKBAM_BUDGET_ID    
WHERE PFB_LEVEL_ID=2 GROUP BY FKOM_OFFICE_ID,FKBAM_BUDGET_ID ';
dbms_output.put_line(sql_query);
end;

How to get records from this above statement since I hope the query seems fine ?

  • 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-17T00:54:20+00:00Added an answer on June 17, 2026 at 12:54 am

    One possibility is using a ref cursor – you build your SQL statement and open the ref cursor for this statement afterwards.

    Simplified:

    declare
      l_cursor sys_refcursor;
      sql_query varchar2(4000);
    begin
      sql_query := 'select 1 as value from dual';
      open l_cursor for sql_query;
    end;
    

    Depending on your IDE / host language, you can then iterate over the cursor etc.

    For example, to print a ref cursor in SQL Plus:

    variable x refcursor
    set autoprint on
    declare
      sql_query varchar2(4000);
    begin
      sql_query := 'select 1 as value from dual';
      open :x for sql_query;
    end;
    

    This concept is even more powerful in 11g, because you can

    • use a CLOB for the SQL statement (thus allowing you to dynamically generate queries of arbitrary length)
    • convert a ref cursor to a DBMS_SQL cursor (and vice versa), which gives you much more flexibility if you need to get the column count and column types at runtime
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm rather new to these could someone explain the significance (of the following code)
I am trying to figure out exactly what these new fangled data stores such
Excuse me but I am very new at learning to use oracle and sql.
I am trying to execute a query against oracle with the where clause including
i'm trying to make a TRIGGER in ORACLE using ORACLE SQL DEVELOPER, I would
I'm new to autom4te, and I'm trying to use autoconf/automake to build and link
I am new to Oracle SQL Developer. What are the connection statements for Oracle
I'm very new to Oracle and was wondering if there's a way either through
I'm kind of new to these things. I do not know what command line
First of all sorry for my bad english and Im pretty new in these

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.