Building a block based on query

Hi,
I've to build a block containing empnumbers from emp table for the emp names entered by the user.
EX: If emp enters SMITH,KING in a text item ,I've to build a mutlirecord block containing emp numbers of these emp names.
I know I've to use EXEC_SQL package to achieve this.
Ex is below:
PROCEDURE getData1 IS
connection_id EXEC_SQL.CONNTYPE;
cursorID EXEC_SQL.CURSTYPE;
sqlstr VARCHAR2(1000);
loc_ename VARCHAR2(30);
loc_eno NUMBER;               
loc_hiredate DATE;
nIgn PLS_INTEGER;
nRows PLS_INTEGER := 0; -- used for counting the actual number of rows returned
i integer:=0;
type l_emp is table of emp%rowtype index by binary_integer;
l_empvar l_emp;
BEGIN
connection_id := EXEC_SQL.OPEN_CONNECTION('scott/tiger@afresrtm');
cursorID := EXEC_SQL.OPEN_CURSOR(connection_id);
sqlstr := 'select empno from emp where ename in :text_item' ;
EXEC_SQL.PARSE(connection_id, cursorID, sqlstr, exec_sql.V7);
--EXEC_SQL.BIND_VARIABLE(connection_id, cursorID, ':bn', input_empno);
EXEC_SQL.DEFINE_COLUMN(connection_id, cursorID, 1, loc_ename, 30);
EXEC_SQL.DEFINE_COLUMN(connection_id, cursorID, 2, loc_eno);     
EXEC_SQL.DEFINE_COLUMN(connection_id, cursorID, 3, loc_hiredate);
nIgn := EXEC_SQL.EXECUTE(connection_id, cursorID);
-- call FETCH_ROWS to obtain a row. When a row is returned, obtain the values,
-- and increment the count.
WHILE (EXEC_SQL.FETCH_ROWS(connection_id, cursorID) > 0 ) LOOP     
nRows := nRows + 1;
EXEC_SQL.COLUMN_VALUE(connection_id, cursorID, 1, loc_ename);
EXEC_SQL.COLUMN_VALUE(connection_id, cursorID, 2, loc_eno);     
EXEC_SQL.COLUMN_VALUE(connection_id, cursorID, 3, loc_hiredate);
l_empvar(i).ename:=loc_ename;
l_empvar(i).empno:=loc_eno;
l_empvar(i).hiredate:=loc_hiredate;
i:=i+1;
END LOOP;
IF (nRows <= 0) THEN
TEXT_IO.PUT_LINE ('Warning: query returned no rows');     
END IF;
for i in 1..l_empvar.last loop
:emp.ename:=l_empvar(i).ename;
:emp.empno:=l_empvar(i).empno;
:emp.hiredate:=l_empvar(i).hiredate;
create_record;
next_record;
end loop;
END;
Here is a pbm in SQL query:
How can I prepare a sql stmt for the input given by user bcoz it has to be varchar.
Pls give me a sol..
Adios..
Prashanth Deshmukh

Hi,
I've not tried this and can't say for sure if it is possible or not.
But, have a look at this link Re: Automatic  Number  of record displayed .
I'd thought of a solution but never tried myself. Try if it works for you.
If it doesn't, i think it will not be possible in oracle forms.
Navnit

Similar Messages

  • Building a block based on the records fetched - Forms 10g

    Is there a way in forms to dynamically build the block ( I mean in a multi record block, we usally set the number of records displayed in the property pallete) Instead of setting the property is there a way that we can do it based on the records fetched by the query?
    select a.unit_id, substr(b.product_code,1,5)
    from [email protected] a,[email protected] b
    where substr(a.product_code,1,5) = b.product_code
    and substr(a.product_code,1,5) = 'E3088'
    and inv_product_type in ('PHER','LPHER','VPHER')
    and warehouse_id = 'A'
    This is the query.
    If the query for product_code fetched 5 units for product code = 'E3088' of inv_product_type as mentioned in the query, is if possible to build the multi record block? For another product E3077 it might give us 6 records.
    User wants me to see if I can do it? Is it possible?
    Thanks in advance.
    Anu

    Hi,
    I've not tried this and can't say for sure if it is possible or not.
    But, have a look at this link Re: Automatic  Number  of record displayed .
    I'd thought of a solution but never tried myself. Try if it works for you.
    If it doesn't, i think it will not be possible in oracle forms.
    Navnit

  • Autofill detail block based on query

    Hi experts/Gurus
    I have 3 tables
    1-pr_mst
    2-pr_trn
    3-hr_mst
    Em_code is a common key between theses tables.
    on my form table 1 and 2 are the base main tables, due to the relationship, when i enter em_code on table 1 and query it, it shows data on both the table. Its a normal behavior in Master Detail block in forms.
    When user enter em_code at form and there is no data found in table 2, obviously it show blank data block related to the table 2 and shows data in table 1 block, now i want an em_code details which stores in the table 3 automatically load in memory and populated in detail block.
    Is it possible ? and how can i do this. suggest me a best or anybody can give example on emp/dept
    regards
    Anwer

    I'm not sure if i understand you correctly. You want to have an additional relation between block 1 and block 3? If so, just create it, each block can have more than one relation as master.

  • Help me !!!!!! set Arguments property for block based on store procedures

    hi
    i build a block based on storeprocedures ,if i set the
    Query Data Source Arguments property in design time with a value
    my form will work,
    but i need to set this property programetically and in runtime,
    if there is any built_in or other ways ,please help me.
    thanks in advance.
    shoja.

    Sorry, but there is no way to do this.
    If you need to switch the table you're selecting from, you have to do this
    inside your stored procedure.

  • Help !!!set Arguments property for block based on store procedures

    hi
    i build a block based on storeprocedures ,if i set the
    Query Data Source Arguments property in design time with a value
    my form will work,
    but i need to set this property programetically and in runtime,
    if there is any built_in or other ways ,please help me.
    thanks in advance.
    shoja.

    Sorry, but there is no way to do this.
    If you need to switch the table you're selecting from, you have to do this
    inside your stored procedure.

  • How to query the master block based on one of the values in detail block

    Hi,
    In version 6i forms, I have a field in data block which is not set as a database item. I am using that field to store a value from detail block. If I want to query the form using that field (which represents one of the values from detail block), how do I do that? Any pointers?
    TIA,

    Do you want to query a master, which contains a specific detail? If so, here's an example how you could do it with a PRE-QUERY-trigger:
    DECLARE
      vcQuery VARCHAR2(4000);
    BEGIN
      IF :MASTERBLOCK.THE_DETAIL_SEARCH_ITEM IS NOT NULL THEN
        -- Build up an exists Sub-Query
        vcQuery:=' MASTERBLOCKID IN (SELECT FK_TO_MASTERBLOCK FROM DETAILTABLE WHERE DETAIL_COLUMN=''' || :MASTERBLOCK.THE_DETAIL_SEARCH_ITEM|| ''')';
      END IF;
      SET_BLOCK_PROPERTY('MASTERBLOCK', DEFAULT_WHERE, vcQuery);
    END;

  • Problem in block based Query

    Respected Guru's
    I have a problem eith block bassed query.i have already used this block based query and it is working too.
    But here i am facing the the problem.why becuz i have used a global variable to pass value for execute it.
    and used 'set_block_property' to execute this query ..
    go_block('block name ')
    execute_query;
    But it si showing unable to perform the query..
    How i do this?? plez help me out...

    Dear...........
    There are some possible reasons.
    1- The items that are in data block , there is some field data is not database field and you set the property of this item is
    "Data Base Item" = 'Yes' , means this field is not in table.
    2- user right problem
    3- see the block property where set the property QUERY = NO\
    THX.

  • Block based on view ,enter query

    Hi,
    I have a block based on a view.One column of the view is
    substr(f_gt_marks(tcs23.idu_nr_dossr),1,128).
    When I enter 'PAPER%' for the above column and press execute query i get:
    PAPER
    PAPER1PAPER2
    When the form is in enter query mode and when I enter 'PAPER' and press execute query I get FRM 40301 query caused no rows to be retrieved.
    I want only paper to be retrieved.The form works only if I append % to the search criteria.
    Can you please advise me.
    I am working on forms 9i.
    Thanks and Regards

    Try to debug for form, and get the SQL Statement that is being executed, see if it's doing anything out of the ordinary and try to run in SQL*Plus and see the result.
    I think your SQL is trying use the SUBSTR function on the value you enter in ENTER-QUERY mode.
    SUBSTR(f_gt_marks('PAPER'),1,128)Anyway, best for you to see what the form's SQL statement is when issuing the query.
    Tony

  • Can not build a Universe based on a SAP/BW Query:

    Hi,
    In Universe Designer I can not build a Universe based on a SAP/BW Query:
    -The Universe Items -> Sight -> Universe Window and -> Sight -> Liste Mode are greyed our
    - Its simply not possible to move Universe "Objects" = "Classes" into the Table, Join or
    Item Plane.
    I am useing:
    -BO XI 3.1
    -BO Solutions for SAP Integration
    -Universe Designer
    Universe Designer based on a Database is ok
    The Connection to the SAP System is stored in BO XI 3.1
    What's missing ?
    Any Rights/Authorizations are Misseing ?
    Thanks a lot !
    Martin

    Hi
    when working with OLAP universes (eg. universes based on SAP BW queries) it is not possible to work as you normally do when you have a universe based on a relational data source. The data madel is the one from the OLAP source (cube) so it is not possible to create your on joins, tables etc. In this case you can only add/modify the objects in the object browser (left panel).
    Regards,
    Stratos
    PS: The Data Federator will allo you to create relational universes on an SAP BW source. Still this is a product that must be licensed seperately and currently does not support SAP logon ticket-based SSO.

  • Update detail block based on FROM QUERY

    I have 2 blocks in master-detail relation. The master is based on a table, the detail on from query. The Insert works fine... but whenever i want to update any field from the detail block, the items (text, lists, whatever) don't allow any updating.
    Is there some workaround?
    Thank you for the help
    NR

    RTM on blocks based on from-query.
    If I recall well, it says that you shoud write the DML code in on-insert, on-update and on-delete triggers - and, anyway, if I do not remember well the manual, that's what I do.
    So, the on-insert trigger should have an insert into <my_dml_table>...
    The on-update trigger sould have an update <my_dml_table>... where ... And there's a thing: you may have the rowid of <my_dml_query> fetched - which would be the best - or use some primary key for that table for update (not so good performance).
    The on-delete trigger somewhat like the on-update trigger.
    Moreover, I believe it would be better to have procedures for on-insert, on-update and on-delete grouped in one package in the database - again, this is what I use to do.

  • Block based on "From clause query" and substitution variable

    Hi Folks,
    I have a "From clause query" block type, which is based on query that uses a substitution variable (:BLOCK.COLUMN) from previous block. When I run a query, then I obtain an error: ORA-01008: not all variables bound.
    My query looks like:
    select seq_no, prod_code, descr, curr_code,
           max(decode(sched_type_code,'ROLLOVER',amt,0)) OUTSTD_DRAW,
           max(decode(sched_type_code,'INTCHG',amt,decode(sched_type_code,'FEEREC',amt,0))) OUTSTD_INTEREST_FEE
    from
        select r.fac_no, r.prod_code, f.descr, r.prod_seq_no seq_no, r.curr_code, r.sched_type_code,sum(nvl(rep_amt,0)) amt
          from repay_scheds r,
               fac_prods f
         where r.fac_no = f.fac_no
           and r.prod_code = f.prd_code
           and r.prod_seq_no = f.seq_no
           and r.fac_no = :B2.FAC_NO
           and r.trans_ref_from is not null
           and r.status         <> 'P'
        group by r.fac_no, r.prod_code, f.descr, r.prod_seq_no, r.curr_code, r.sched_type_code 
    group by seq_no, prod_code, descr, curr_code
    having max(decode(sched_type_code,'ROLLOVER',amt,0)) >0 or max(decode(sched_type_code,'INTCHG',amt,decode(sched_type_code,'FEEREC',amt,0))) > 0Once I replace that substitution variable in query condition with some exact test number then it works fine.
    select seq_no, prod_code, descr, curr_code,
           max(decode(sched_type_code,'ROLLOVER',amt,0)) OUTSTD_DRAW,
           max(decode(sched_type_code,'INTCHG',amt,decode(sched_type_code,'FEEREC',amt,0))) OUTSTD_INTEREST_FEE
    from
        select r.fac_no, r.prod_code, f.descr, r.prod_seq_no seq_no, r.curr_code, r.sched_type_code,sum(nvl(rep_amt,0)) amt
          from repay_scheds r,
               fac_prods f
         where r.fac_no = f.fac_no
           and r.prod_code = f.prd_code
           and r.prod_seq_no = f.seq_no
           and r.fac_no = 2012500
           and r.trans_ref_from is not null
           and r.status         <> 'P'
        group by r.fac_no, r.prod_code, f.descr, r.prod_seq_no, r.curr_code, r.sched_type_code 
    group by seq_no, prod_code, descr, curr_code
    having max(decode(sched_type_code,'ROLLOVER',amt,0)) >0 or max(decode(sched_type_code,'INTCHG',amt,decode(sched_type_code,'FEEREC',amt,0))) > 0How can I use substitution variable within query for "From clause query" block type? Or any other way how to get the same result?
    Thanks for your reply.
    Tomas

    I have a solution:
    Before entering block I'm calling function, that populates my block:
    PROCEDURE POP_<<MY_BLOCK>>_BLOCK IS
      query_txt varchar2(2000);
    BEGIN
       query_txt := '(select seq_no, prod_code, descr, curr_code,
                            max(decode(sched_type_code,''ROLLOVER'',amt,0)) OUTSTD_DRAW,
                            max(decode(sched_type_code,''INTCHG'',amt,decode(sched_type_code,''FEEREC'',amt,0))) OUTSTD_INTEREST_FEE
                                                  from
                                                     select r.fac_no, r.prod_code, f.descr, r.prod_seq_no seq_no, r.curr_code, r.sched_type_code,sum(nvl(rep_amt,0)) amt
                                                       from repay_scheds r,
                                                            fac_prods f
                                                      where r.fac_no = f.fac_no
                                                        and r.prod_code = f.prd_code
                                                        and r.prod_seq_no = f.seq_no
                                                        and r.fac_no = '||:B2.FAC_NO||'
                                                        and r.trans_ref_from is not null
                                                        and r.status         <> ''P''
                                                     group by r.fac_no, r.prod_code, f.descr, r.prod_seq_no, r.curr_code, r.sched_type_code 
                                                 group by seq_no, prod_code, descr, curr_code
                                                 having max(decode(sched_type_code,''ROLLOVER'',amt,0)) >0 or max(decode(sched_type_code,''INTCHG'',amt,decode(sched_type_code,''FEEREC'',amt,0))) > 0)';
       Go_Block('<<MY_BLOCK>>' );
       Clear_Block ;
       Set_Block_Property( '<<MY_BLOCK>>', QUERY_DATA_SOURCE_NAME, query_txt) ;
       -- populate my  block --
       Execute_Query ;
    END;Thanks,
    Tomas

  • Block based on from clause query

    Hi all...
    I am using forms 10g .....
    When I wanted block based on from clause query...
    I used this query ( SELECT * FROM exit INNER JOIN enter ON exit.ent_num = enter.ent_num where enter.depart=1)...
    When I run form .....
    frm-40505 oracle error unable to perform query
    Thank you
    Edited by: osa3_12 on Dec 10, 2009 4:33 AM

    hi
    try something like this.
      1* select empno,ename from emp where empno=empno order by 1
    SQL> /
         EMPNO ENAME
          7000 Sarah
          7369 SMITH
          7499 ALLEN
          7521 WARD
          7566 JONES
          7654 MARTIN
          7698 BLAKE
          7782 CLARK
          7788 SCOTT
          7839 KING
          7844 TURNER
         EMPNO ENAME
          7876 ADAMS
          7900 JAMES
          7902 FORD
          7934 MILLER
          8898 Sheela
    16 rows selected.
      1* select empno,ename from emp where empno=7000
    SQL> /
         EMPNO ENAME
          7000 Sarah
    SQL> sarah

  • How to execute the query for a block based on the parameter

    Hi All,
    Good evening.
    i have requirement where i need to display the data in one block based on the selected items.
    the scenario is like this...there are 2 LOV's and one apply button and one external region on the form.
    so when u select the lov values and click on apply button the query should execute based on this 2 lov values.
    i am not getting how to achieve this..i am very new to oracle forms..
    Please Help..
    Thanks
    Bharat
    please help..it is urgent..
    thanks
    bharat
    Edited by: Bharat on Jan 31, 2012 5:19 AM

    Bharat wrote:
    Hi All,
    Good evening.
    i have requirement where i need to display the data in one block based on the selected items.
    the scenario is like this...there are 2 LOV's and one apply button and one external region on the form.
    so when u select the lov values and click on apply button the query should execute based on this 2 lov values.
    i am not getting how to achieve this..i am very new to oracle forms..Another way you can do this. Create a lov and don't assign it to any column just one return item (should be id).
    Now create a button may be your "apply button" write two trigger when-button-press and when-mouse-click.
    at When -Button-Press trigger, change the block state to 'ENTER-QUERY' and at when-mouse-click show the LOV and then write execute_query.
    Hope this will help you.
    If someone's response is helpful or correct, please mark it accordingly.

  • Query a database block based on a non-database block

    hi everybody
    can anybody help me as how to query a database block based on a non-database block, without a master-detail relationship?
    i have a block : date_input which contains a non-database item: start_date
    another database block (event_block)containing details of an event
    i have to input a date in the start_date and query the event_block
    in wich trigger should i insert the code?
    thanks

    If you are trying to query your database block (event_block) using the value from start_date in your non-database block, then you can set the Where clause in the database block using:
    SET_BLOCK_PROPERTY ('event_block', DEFAULT_WHERE, 'your where clause that includes start_date');
    Place this statement in a trigger that is executed prior to the block being queried.

  • [Block based on From Query] On-Lock Trigger

    Hi,
    I have a block based on an Emp_Dept view.
    I manage updating and inserting with the On-Update and On-Insert triggers.
    I wonder if I have to code this in the On-Lock trigger:
    message( 'Oracle locks' );
    lock table emp in share row exclusive mode;
    If I want Oracle to prevent another user from updating the same row I'm updating.
    Thanks for your help.
    JBM

    This is the code we use to lock specific records in ON-LOCK:
    CURSOR crLock IS
      RESOURCE_BUSY EXCEPTION;
      PRAGMA EXCEPTION_INIT(RESOURCE_BUSY, -54);
      SELECT ID
        FROM THE_BASE_TABLE_OF_THE_VIEW
       WHERE ID=:BLOCK.ID FOR UPDATE OF ID NOWAIT;
      nDummy NUMBER;
    BEGIN
      OPEN crLock;
      FETCH crLock INTO nDummy;
      CLOSE crLock;
    EXCEPTION
      WHEN RESOURCE_BUSY THEN
        message('record cannot be locked');
        RAISE FORM_TRIGGER_FIALURE;
    END;

Maybe you are looking for

  • TS1398 unable to get into wi-fi on my Ipod touch

    So I have tried to reset my network connection, my router is working fine and my ipod touch will not even allow me to open the wi-fi connection.....any ideas what I should do?

  • How to copy all contacts from iphone 3gs to google nexus 5 ?

    how to copy all contacts from iphone 3gs to google nexus 5 ?

  • Where Can I find a Flash 8 demo

    I have Flash FX 2004/Flash 7. I am working on a demo project and template which requires Flash 8 or later. Is there somewhere that I can download a trial version of Flash 8 so that I can try out the demo template? I have seen the trial versions of th

  • Super fast delete function

    While playing with my new phone I some how Added a feature that makes certain keys magnify like the A p keys and will also super fast delete what I type. Driving me crazy. How do I stop this from happening? Solved! Go to Solution.

  • HttpConnection in background and UI thread in front causes lockups !

    Hi , Iam running a midlet on Tre0 600 using IBM J9. (CLDC1.0/MIDP2) The design of the midlet is as follows. I have a main form with some items on it. (items are xml forms) When i select a item (form) fill it and submit, i put the data to be requested