Skip to Main Content

Breadcrumb

Question and Answer

Connor McDonald

Thanks for the question, hubab.

Asked: November 15, 2016 - 8:17 am UTC

Last updated: November 16, 2016 - 5:31 am UTC

Version: 10g

Viewed 1000+ times

You Asked

Hello tom,

I have a comprhensively large data in pl/sql for which i created a view for report purposes
I am using oracle form builder for the first time.
I wanted to show user data from my view based on the date range he/she selects

Can you help me how to do that?

and Connor said...

You could use a parameterised view. This example simply returns what you set, but it can just easily be a predicate in a where clause

if you want more than on sys_context value, you would use an application context:


SQL> create or replace context my_ctx using my_proc
  2  /

Context created.

SQL> create or replace procedure my_proc( p_a in number, p_b in date, p_c in varchar2 )
  2  as
  3  begin
  4          dbms_session.set_context( 'my_ctx', 'a', to_char(p_a) );
  5          dbms_session.set_context( 'my_ctx', 'b', to_char(p_b,'yyyymmddhh24miss') );
  6          dbms_session.set_context( 'my_ctx', 'c', p_c );
  7  end;
  8  /

Procedure created.

SQL> create or replace view my_view
  2  as
  3  select sys_context( 'my_ctx', 'a' ) a,
  4         sys_context( 'my_ctx', 'b' ) b,
  5         sys_context( 'my_ctx', 'c' ) c
  6    from dual;

View created.

SQL> exec my_proc( 42, sysdate, 'hello world' );

PL/SQL procedure successfully completed.

SQL> select * from my_view;

A          B               C
---------- --------------- ---------------
42         20060503131617  hello world




Also, Forms supports blocks based on stored procedures returning a ref cursor. That might be easier for you .

Rating

  (4 ratings)

Is this answer out of date? If it is, please let us know via a Comment

Comments

Dynamic Where Clause

Marcus, November 16, 2016 - 8:05 am UTC

You can set the where clause in a Forms block at runtime.
Let's assume you have a control block with two items :ctrl.from and :ctrl.to that define the range and a database block for your view. Then build the where string you need like
new_where := 'date_col_in_your_view BETWEEN TO_DATE('''|| TO_CHAR(:ctrl.from,'dd.mm.yyyy') ||''',''dd.mm.yyyy'') AND TO_DATE('''|| TO_CHAR(:ctrl.to,'dd.mm.yyyy') ||''',''dd.mm.yyyy'')';
SET_BLOCK_PROPERTY(<view_block>,DEFAULT_WHERE,new_where);
Then requery the block.

reply

hubab, November 17, 2016 - 4:58 am UTC

thanks alot for your prompt reply. Im amazed and grateful.

Thankyou once again

reply

hubab, November 17, 2016 - 5:13 am UTC

Marcus what do u mean by requery?

Requery

Marcus, November 17, 2016 - 8:59 am UTC

When you set the default where the database block is not updated automatically. Therefore you have to
go_block ('xy');
execute_query();
to refresh the rows.

More to Explore

PL/SQL demos

Check out more PL/SQL tutorials on our LiveSQL tool.

PL/SQL docs

PL/SQL reference manual from the Oracle documentation library