Stored procedure vs anonymouse block

Hi all,
I had an interesting problem and don't know why.
My procedure takes the files from a directory and process them. using vx_xmltype.toobject(vo_object,..) I load xml files into sql object.
create type in_obj as object (types varchar2(100));
create type in_obj_nt as varray(1000) as in_obj;
create type final as object (name varchar2(100),objects in_obj_nt);
And my code was something like this:
for i in ( all file_names) loop
   vx_xml := ....;
   declare
      obj final;
   begin
      xml.toobject(vo_obj,...); 
      ---process obj--
   end;
end loop;Starting with second file in the loop the in_obj from vo_obj was initialized with null values(not the ones from the file).
But when I changed the code with this one:
for i in ( all file_names) loop
   vx_xml := ....;
   xml_to_obj(vx_xml,obj);
/*   declare
      obj final;
   begin
      xml.toobject(obj,...);
   end;*/
      ---process obj--
end loop;I replaced the declare..begin..end block with a stored procedure that does the same thing...the objects were correctly initialized.
What is the difference between these two examples?
there is a difference in how the memory is assigned for objects? can you provide me some documentation in this direction?
thanks
Message was edited by:
alinux

I think it is a scope problem, although you haven't included enough code to be certain...
you are declaring obj within the anonymous block. It will be out of scope after the termination of that block, which is when you try to process it.
When you changed to a function you would have had to declare obj earlier, and it would still be in scope when you got to the processing part.

Similar Messages

  • Question: Are there any advantages for stored procedure for data block?

    There are two ways to create data block:
    1. query table or view or
    2. stored procedure.
    After 9i, AS has a PL/SQL compiler. Do we still see the advantage of using stored procedure, as claimed that it is faster due to the stored procedure always compiled?
    Thank you in advance.
    Jimmy

    Jimmy,
    The "fast" side is not the only one benefit of stored procedures.
    Of course, you can use the BULK COLLECT functionality which is not available into Forms.
    But stored procedure is a good way to perform the following actions:
    complex handeling of datas (insert, update or delete that generate severals actions on other tables).
    externalization/centralisation of business rules.(separate the design and functionnal work).
    more secutity, because you can prohibit manipulation of datas outside of the procedures.
    You can change the rules without modify the forms.
    etc.
    Francois

  • How to use Stored Procedures in form 6i Blocks

    Dear Friends,
    I would like to know how to use Stored Procedures while creating blocks in Data Block Wizard in forms 6i application.
    Please send me sample code of stored procedure.
    Regards,
    Khader.

    The Data Block Wizard is not for creating stored procedures. It will allow you to use a stored procedure in your form. See the help documentation for how to use the wizard.
    Here's an example of a simple procedure. If you search the database forum or the web, you will find many examples.
    CREATE OR REPLACE PROCEDURE procedure_name (value OUT NUMBER ) AS
    BEGIN
    SELECT COUNT(*) INTO value
    FROM your_table;
    END;
    Message was edited by:
    Mark Roberts

  • Dynamic sql and block based on a stored procedure

    Hi!
    I'm triying to generate a block based on a stored procedure. I want the stored procedure to execute a dynamic sql, but I'm having getting the error "PLS-00455 cursor 'AULOCASLATE' cannot be used in dynamic SQL OPEN statement".
    I have the following code:
    CREATE OR REPLACE package pkg_f0015 is
    type rClieInstSlate is record
    (clie_id CMS_CLIENTS.ID%type
    ,client_nm varchar2(1000)
    ,cs_no CMS_CLIENTS.CS_NO%type
    ,dob CMS_CLIENT_NAMES.BIRTH_DT%type);
    type tClieInstSlate is table of rClieInstSlate;
    type uClieInstSlate is ref cursor return rClieInstSlate;
    procedure prLocationSlateQry(
    auLocaSlate in out uClieInstSlate,                anCsNo in CMS_CLIENTS.CS_NO%type,
    avClieNm in varchar2,
    avSearchType in varchar2,
    avLotyCd in CMS_LOCATION_TYPES.CD%type);
    end pkg_f0015;
    CREATE OR REPLACE PACKAGE BODY pkg_cms_f0015 is
    procedure PRLocationSlateQry( auLocaSlate in out uClieInstSlate,
    anCsNo in CMS_CLIENTS.CS_NO%type,
    avClieNm in varchar2,
    avSearchType in varchar2,
    avLotyCd in CMS_LOCATION_TYPES.CD%type) IS
    vSelect varchar2(5000);
    vAddCond varchar2(1000);
    vSupLevel varchar2(50);
    begin
    vSelect := 'select clie.ID,'||
    ' CLIENT_NAME,'||
    ' clie.CS_NO,'||
    ' clna.BIRTH_DT dob'
    ' from CMS_CLIENT_NAMES clna,'||
    'CMS_CLIENTS clie'||
    ' where clna.CLIE_ID = clie.ID';
    if avSearchType= 'C' then
    vAddCond := ' and clie.CS_NO = nvl('||anCsNo||',clie.CS_NO)';
    vSelect := vSelect || vAddCond;
    open auLocaSlate for vSelect;
    end if;
    end PRLocationSlateQry;
    end;
    I wonder if what I want is possible

    OK,
    Now it works. Previously we had the parameter p_guid declared as RAW, which obviously is not any good. :)
    Radovan
    Edited by: biciste on Apr 28, 2009 4:57 PM

  • How to simulate a dml error in order to test try-catch code block inside a stored procedure

    Hi,
    What would be the easiest way to simulate a dml error in order to test a try catch block.
    I would like to do it with a simple command from outside the stored procedure if possible.
    I tried dropping the table that was updated but it hangs
    Thanks,
    Dani

    Dropping the table that is the target of the procedure will give you an unpleasant surprise: the CATCH block will not fire. To wit, errors like missing tables can only be caught in outer scopes, but not in the procedure where the error occurs.
    But you would add a fake constraint to a table which causes the update to fail. You need to do this in advance, not while running the procedure.
    Erland Sommarskog, SQL Server MVP, [email protected]

  • Stored Procedure Vs PL-SQL Block

    Hi,
    I came across an interesting problem last week. Fortunately, I was able to solve it or find an acceptable workaround for myself. But wanted to get some clarification from the experts. So posting it here.
    Also, I am new to Orcle, so please excuse any shortcomings in the post.
    My data model has following tables-
    TABLE_PARENT (ID, other columns)
    TABLE_CHILD (ID, other columns, PARENT_ID_FK)
    Here, ID is the primary key column for the respective tables; PARENT_ID_FK is the foreign key referencing the ID column from the TABLE_PARENT.
    I created a stored procedure programmatically (using MS Excel) to insert records in the two tables. The stored procedure has insert statements for an indefinite number of records in the parent table and for every such record, there's a corresponding record inserted in the child table. Here's the sample code.
    BEGIN
    /*first record*/
    parent_id := MY_SEQUENCE_GENERATOR.NEXTVAL;
    INSERT INTO TABLE_PARENT(ID, other columns) VALUES (parent_id, other values);
    INSERT INTO TABLE_CHILD(ID, other values,parent_id );
    /*second record*/
    parent_id := MY_SEQUENCE_GENERATOR.NEXTVAL;
    INSERT INTO TABLE_PARENT(ID, other columns) VALUES (parent_id, other values);
    INSERT INTO TABLE_CHILD(ID, other values,parent_id );
    /*third record*/
    parent_id := MY_SEQUENCE_GENERATOR.NEXTVAL;
    INSERT INTO TABLE_PARENT(ID, other columns) VALUES (parent_id, other values);
    INSERT INTO TABLE_CHILD(ID, other values,parent_id );
    /*and so on*/
    END
    When I run this stored procedure, I keep getting following exception intermittently-
    ORA-02291: integrity constraint violated-parent key not found tips.
    My thinking is that it comes because the insert statements are executing ahead of turn of the parent_id assignment statement. And this is happening possibly because of some parallelism that is taking place during the execution of the stored procedure, or, some sort of optmization that the DB server does (though erroneously) when it compiles the stored procedure.
    I tried out everything that I could think of but it didn't go away. Finally, when I executed the same set of statements as a PL-SQL block, it worked fine.
    To understand it better, I am looking for clarification on the following questions.
    1) Why does the exception come with stored procedure but not with PL-SQL block? Is my reasoning given above correct (parallelism or some sort of optimization coming into play)?
    2) If it is due to parallelism, how to run a Oracle stored procedure with defree of prallelism set to 1?
    3) If it is due to optimization done by the compiler, how to instruct the compiler to not do any such optimization. Also, in any case, isn't it an error to optimize but lose program semantics?
    4) Another question related to the same piece of work I have is to use transactions in the PL-SQL block, I had to explicitly COMMIT/ROLLBACK it in the code. In whatever references I had read, it was said that by default the transaction begins with BEGIN statement and commits with END. Also, it seems to work with a Stored Proedure though. So is it that a PL_SQL block needs explicity call to COMMIT/ROLLBACK to achive transactions but stored procedures do not?
    Any inputs/clarifications will be much appreciated.
    Thank you
    Neelesh

    Ok, your last couple of paragraphs were helpful. Here're the details that were missing in my earlier post.
    - I am on Oracle 10.2.0.
    - Table definitions-
    CREATE TABLE "MYUSER"."TABLE_PARENT"
    *(     "ID" NUMBER(19,0) NOT NULL ENABLE,*
    *     "NAME" VARCHAR2(30),*
    *     "DESCRIPTION" VARCHAR2(80),*
    *     "RULETYPE" NUMBER(10,0) NOT NULL ENABLE,*
    *     "OPERATOR" NUMBER(10,0),*
    *     "MININTERCEPT" FLOAT(126),*
    *     "PRIORITY" NUMBER(10,0),*
    *     "PENALTY" NUMBER(10,0),*
    *     "STATUS" NUMBER(10,0),*
    *     PRIMARY KEY ("ID")*
    USING INDEX PCTFREE 10 INITRANS 2 MAXTRANS 255 COMPUTE STATISTICS
    STORAGE(INITIAL 131072 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645
    PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1 BUFFER_POOL DEFAULT)
    TABLESPACE "USERS"  ENABLE,
    *) PCTFREE 10 PCTUSED 40 INITRANS 1 MAXTRANS 255 NOCOMPRESS LOGGING*
    STORAGE(INITIAL 131072 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645
    PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1 BUFFER_POOL DEFAULT)
    TABLESPACE "USERS"
    CREATE TABLE "MYUSER"."TABLE_CHILD"
    *(     "ID" NUMBER(19,0) NOT NULL ENABLE,*
    *     "WEIGHT" NUMBER(19,0),*
    *     "PARENTID_FK" NUMBER(19,0),*
    *     PRIMARY KEY ("ID")*
    USING INDEX PCTFREE 10 INITRANS 2 MAXTRANS 255 COMPUTE STATISTICS
    STORAGE(INITIAL 131072 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645
    PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1 BUFFER_POOL DEFAULT)
    TABLESPACE "USERS"  ENABLE,
    *     CONSTRAINT "FK3A78BF1E6A9DCE51" FOREIGN KEY ("PARENTID_FK")*
    *     REFERENCES "MYUSER"."TABLE_PARENT" ("ID") ENABLE*
    *) PCTFREE 10 PCTUSED 40 INITRANS 1 MAXTRANS 255 NOCOMPRESS LOGGING*
    STORAGE(INITIAL 131072 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645
    PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1 BUFFER_POOL DEFAULT)
    TABLESPACE "USERS"
    - The Stored procedure definition is-
    CREATE OR REPLACE PROCEDURE LOAD_RULES_SP AS
    ruleid NUMBER(19,0);
    tempid NUMBER(19,0);
    BEGIN
    */* First parent record */*
    SELECT IDGENERATOR.NEXTVAL INTO ruleid FROM dual;
    INSERT INTO TABLE_PARENT (ID, NAME, DESCRIPTION, RULETYPE, OPERATOR, MININTERCEPT, PRIORITY, penalty, STATUS) VALUES (ruleid, 'Rule 1',null,3,0,0,null,null,1);
    */* Corresponding child records */*
    SELECT IDGENERATOR.NEXTVAL INTO tempid FROM dual;
    INSERT INTO TABLE_CHILD (id, weight, PARENTID_FK)
    VALUES (tempid, 0.2, ruleid);
    SELECT IDGENERATOR.NEXTVAL INTO tempid FROM dual;
    INSERT INTO TABLE_CHILD (id, weight, PARENTID_FK)
    VALUES (tempid, 0.5, ruleid);
    SELECT IDGENERATOR.NEXTVAL INTO tempid FROM dual;
    INSERT INTO TABLE_CHILD (id, weight, PARENTID_FK)
    VALUES (tempid, 0.3, ruleid);
    */* First parent record */*
    SELECT IDGENERATOR.NEXTVAL INTO ruleid FROM dual;
    INSERT INTO TABLE_PARENT (ID, NAME, DESCRIPTION, RULETYPE, OPERATOR, MININTERCEPT, PRIORITY, penalty, STATUS) VALUES (ruleid, 'Rule 1',null,3,0,0,null,null,1);
    */* Corresponding child records */*
    SELECT IDGENERATOR.NEXTVAL INTO tempid FROM dual;
    INSERT INTO TABLE_CHILD (id, weight, PARENTID_FK)
    VALUES (tempid, 0.2, ruleid);
    SELECT IDGENERATOR.NEXTVAL INTO tempid FROM dual;
    INSERT INTO TABLE_CHILD (id, weight, PARENTID_FK)
    VALUES (tempid, 0.5, ruleid);
    SELECT IDGENERATOR.NEXTVAL INTO tempid FROM dual;
    INSERT INTO TABLE_CHILD (id, weight, PARENTID_FK)
    VALUES (tempid, 0.3, ruleid);
    */* And so on for a few parent records more */*
    END;
    Can you throw some light on the exception I was seeing now? Note that when I changed from stored procedure to an anonymous block, it worked fine.
    One correction in my earlier post is that as the code snippet shows, there are multiple inserts in the child table for every record inserted in the parent one.

  • Master-Detail with 2 blocks based in stored procedure doesn't work.

    Hi. I'm Oscar and I'm new for here.
    I have a problem that i can't find the correct answer to solve it.
    Well. I've created a form with 2 blocks. Both of them have the Query Data Source Type Property to "Procedure", and both procedures on database returns one ref cursor of a record type each one.
    BLOCK BL_COMPETICIONES --> query data source: p_get_competiciones (p_Cursor is cursor of record (CODIGO NUMBER,
    NOMBRE VARCHAR2(50),
    SETCRICKETSN VARCHAR2(1),
    SET01SN VARCHAR2(1),
    FECHAINICIO DATE,
    FECHAFIN DATE).
    On triggers (on-lock, on-insert, on-delete and on-update) I have the call to the corresponding stored procedure to lock, insert, delete or update.
    Well, when i've only this block in form, the form works correctly.
    But when I added a second block (which is suppossed to be a detailed data from the first one), and after I've assigned the query procedure and created the relation between both blocks, then run the form and try to execute query on first block, returning records correctly, but then, when execution goes to the program unit "query_master_details", the sentence "execute query" doesn't do anything (and the cursor is in the detailed block), so detailed block continues to be without records.
    I don't know how to solve this. Someone can help me, please?. Thanks.
    Edited by: user5067020 on 09-abr-2009 16:38

    It could be that there is something screwy with LV, but given that it uses standard interfaces for comm with the DBMS, I would not expect that. A much more realistic possibility is that the toolkit is mucking things up. (A fairly common occurrence.)
    Try bypassing the toolbox -- which you don't really need anyway -- an talk directly to the ActiveX or .net interface.
    Also, what DBMS? What drivers are you using?
    Mike...
    Certified Professional Instructor
    Certified LabVIEW Architect
    LabVIEW Champion
    "... after all, He's not a tame lion..."
    Be thinking ahead and mark your dance card for NI Week 2015 now: TS 6139 - Object Oriented First Steps

  • Stored Procedure for Batch Number Format and Block Duplicate Batch Number

    Hi Experts !
    I am new one in forum asking question.. I want Stored procedure for Batch Number Format. I want fix one Batch number format in Stored Procedure.
    Example :
    My Batch number format Like  BATCH00001 - It should be first five digit is text format and next five is Numeric.
    IF create Goods receipt PO or Goods receipt stage I create batch number like BATCH 00001 or any other number means don't add that document and also duplicated batch number also does not allowed. please give me the solutions. I am sorry for my bad english .

    Dear Nagarajan K.
                         Thanks for your replay ..
    IF @transaction_type IN ('A','U') AND (@object_type = '106' )
    BEGIN
    set @item = LEFT( @list_of_cols_val_tab_del, CHARINDEX(CHAR(9),  @list_of_cols_val_tab_del,1) - 1)
    set @batch = substring(@list_of_cols_val_tab_del, len(@item)+1, (CHARINDEX(CHAR(9),  @list_of_cols_val_tab_del,len(@item)+2)) - (len(@item)+1))
    --set @base =( select basetype from ibt1 where batchnum = ltrim(rtrim(replace(@batch,char(9),''))))
    set @count = (select count(*) from oibt quantity > 0 and where  batchnum = ltrim(rtrim(replace(@batch,char(9),''))))
    if @count > 1
    begin
    set @error = 1
    set @error_message = 'Please enter different Batch Code for batch ''' + @batch + ''' for item ' + @item 
    select @error, @error_message
    END
    END
                  I used above Stored Procedure. here we can use one batch number for different item but  i want to block one batch we should use one item and one time only after than we never use that batch number for same item and another item.
             After that I want format for Batch, we should follow unique Batch number for all items.

  • How to use order by in stored procedure base block?

    How to use order by in stored procedure base block? I need to change order by dynamically

    Use SET_BLOCK_PROPERTY('BLOCK_NAME',ORDER_BY,'COLUMN_NAME1, COLUMN_NAME2');

  • Can select resource content in anonymous block, but not in stored procedure

    I know the problem relates to the ACLs but am curious about the following behaviour:
    Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Prod
    PL/SQL Release 10.2.0.1.0 - Production
    CORE 10.2.0.1.0 Production
    TNS for 32-bit Windows: Version 10.2.0.1.0 - Production
    NLSRTL Version 10.2.0.1.0 - Production
    running on Windows XP sp2
    Trying to access an existing resource '/home/test/test.dtd'
    /home is owned by SYS
    /home/test is owned by me
    /home/test.test.dtd is owned by me
    The following SQL and anonymous block retrieve the content of the resource:
    select extract(p.res,'/*').getClobVal()
    from resource_view p
    where p.any_path = '/home/test/test.dtd'
    declare
    alldata clob;
    begin
    select extract(p.res,'/*').getClobVal()
    into alldata
    from resource_view p
    where p.any_path = '/home/test/test.dtd'
    dbms_output.put_line(substr(alldata, 1, 255));
    end;
    BUT when I encapsulate the anonymous block in a stored procedure, I am told that the folder '/home/test/' does not exist.
    As said, the problem related to the ACL on the folders, what I cannot understand, and caused me considerable confusion, is why I was unable to get the content from a stored procedure when I was able to do so from an anonymous block.
    regards
    Richard

    Use equals_path(res,'/home/test/test.dtd') = 1OK, OK, but how do you use wildcards (if you want to) since any_path like '/home/test%' works?
    Who was the stored procedure owned by. Was it a stand-alone stored procedure or a
    method on a package. If it was a method on a package is it AUTHID creator or AUTHID
    definer.Everything apart from the '/home' folder is owned by the current user.
    The PL/SQL was in a packaged procedure, a stand-alone stored procedure, and an anonymous block. It exhibited the same behaviour in each. All were defined with default AUTHID which is definers rights which is the same as the current user in this case.

  • Block based on stored procedure

    I need to create a matrix-like form. I think one option is to base the block on a stored procedure. The idea is to create a PL/SQL Table based on a PL/SQL record of (x)number of colums. My problem is to access each column without using the (.)notation as i use loops to populate these columns. Also once i've manage to create the table, how can i use it to populate the block?? Do i have to use REF Cursors?? I know that REF cursors point to the result set of a query. Can i use them to point to a PL/SQL table as well and if so HOW??
    I've already had a look at the demo but it uses a REF Cursor with a query to populate the block...not a PL/SQL table
    Please help...i'm going bananas with this!!!!!
    Nicola Mereu

    The Stored Prodedures that can be used to populate a block can either return a refcursor as you've noted - or a PL/SQL table of records.
    It sounds like that is the type you need to use.
    Note 66887.1 on metalink is a good place to start

  • Blocks based on stored procedure in Forms6

    I've successfully based a form on stored procedures. It's a master/detail form, so each block has its own procedure to query.
    It works fine until a procedure return no rows in pl/sql table parameter. When this happens, the PLSQL_TABLE.POPULATE_BLOCK built-in, used automatically by forms to populate the block, fails.
    How can I deal with queries that returns no rows?
    Marco Nicolazzo
    NIVA Informatica snc

    <BLOCKQUOTE><font size="1" face="Verdana, Arial">quote:</font><HR>Originally posted by marco.n ():
    I've successfully based a form on stored procedures. It's a master/detail form, so each block has its own procedure to query.
    It works fine until a procedure return no rows in pl/sql table parameter. When this happens, the PLSQL_TABLE.POPULATE_BLOCK built-in, used automatically by forms to populate the block, fails.
    How can I deal with queries that returns no rows?
    Marco Nicolazzo
    NIVA Informatica snc<HR></BLOCKQUOTE>
    I've found a workaround.
    I raise an application error in the package on server-side where there's no
    data to query with RAISE_APPLICATION_ERROR(-20XXX,'ERROR DESCRIPTION').
    Then I use ON-ERROR trigger on the block to ignore the error.
    And so it's worked.
    Different solutions are welcome!
    Marco Nicolazzo
    NIVA Informatica snc
    null

  • Forms Data-Block based on stored procedures - REF CURSOR feature NOT FUNCTIONING

    This topic is related to another topic in this forum titled "FORMS HOW TO SET QUERY SOURCE ARGUMENTS??" I posted my message there as well. I am posting as a NEW TOPIC so that it catches the attention of Oracle Support.
    I built a data form based on a stored procedure and REF CURSOR IN OUT parameter.
    My procedure takes a IN parameter to fill in the criteria for the OPEN <cursor_variable> select ... where ... statement.
    In the Value setting of the Query source Arguments , I set the VALUE to ":BLOCK_NAME.ITEM_NAME" at design time to supply the input value to the procedure. this works to the extent of making available the form item value to the stored procedure parameter. I verified this by doing an insert into some debug table , of the incoming parameter value inside my stored procedure.
    The cursor gets opened properly into the REF cursor variable. I verified this by fetching a record into a local variable and inserting the value into a debug table again in the stored procedure.
    (I took care to close and re-open the REF cursor variable again - so that the front-end can continue to fetch it from the first record. )
    ***** PROBLEM **************
    But the front end forms runtime is giving me a FRM-40301 - query returned no records even though the REF cursor is returned properly opened.
    Did anybody else face the same problem ??
    Please post what you found.
    Thanks,
    Shankaran
    null

    This topic is discussed at length in another thread "How Set Value For Query DataSource Arguments?"
    But I am posting the findings here as well.
    THIS TOPIC IS CLOSED.
    My Bad. The problem Cause : I did not include all columns in the
    cursor rowtype in the Data-block. In the wizard for the data block , I selected ONLY the columns that I needed. But I was doing a Select * from <my_table> in my open cursor <Cursor-Variable> .... The <Cursor Variable>
    itself was declared <my_table>%rowtype
    FIX : The Data Block structure (columns included as items) should match the cursor record Structure. One may or may not
    display all the columns in the LAYOUT though.
    But I don't understand why it gives such a misleading message like FRM-40301 Query retrieved no records. Oracle Team fix it.
    Hope this helps people who face the same problem.
    Thanks,

  • Block based on Stored Procedures & Locking_Mode

    Hello,
    I'm creating a block in Forms 6.0.8 based on Stored Procedures. I'm using the example given in Metalink doc 52778.1. Updates to data work fine if locking_mode = 'Immediate'. If I set locking_mode to 'Delayed' and run the form, when I try to update and commit something, then the IF condition in lock-procedure (grp_lock) always returns TRUE and I run into the exception trapped there. It appears that Forms is passing NEW values in p_grp_data if locking_mode is Delayed and this is causing the problem. Is there any thing I could do in the form or procedure (preferably in the procedure) to solve this problem ? I'm trying to write procedures that will work with both Immediate and Delayed locking_modes
    thanks in advance..
    -- Table and package source:
    -- GRP
    create sequence grp_s
    create table grp
    id number constraint grp_pk primary key,
    name varchar2(10) not null constraint grp_uk unique,
    description varchar2(30) not null,
    active varchar2(1) default 'Y'
    create or replace trigger grp_bri before insert on grp for each row
    begin
    select grp_s.nextval
    into :new.id
    from dual ;
    end ;
    CREATE OR REPLACE PACKAGE grp_pkg AS
    TYPE grpidrec IS RECORD( id grp.id%TYPE ) ;
    TYPE grprec IS RECORD ( id grp.id%type, name grp.name%type, description grp.description%type, active grp.active%type ) ;
    TYPE grp_cursor IS REF CURSOR RETURN grp%rowtype ;
    TYPE grp_tab IS TABLE OF grp%rowtype INDEX BY BINARY_INTEGER ;
    TYPE grp_id_tab IS TABLE OF grpidrec INDEX BY BINARY_INTEGER ;
    PROCEDURE grp_refcur( p_grp_data IN OUT grp_cursor,
    p_group_name IN grp.name%type ) ; -- use if a ref cursor is required
    PROCEDURE grp_query( p_grp_data IN OUT grp_tab, p_group_name IN grp.name%TYPE ) ;
    PROCEDURE grp_insert( p_grp_data IN grp_tab ) ;
    PROCEDURE grp_update( p_grp_data IN grp_tab ) ;
    PROCEDURE grp_delete( p_grp_data IN grp_id_tab ) ;
    PROCEDURE grp_lock( p_grp_data IN grp_tab ) ;
    END grp_pkg ;
    sho err
    create or replace package body grp_pkg as
    -- ================================================================================
    PROCEDURE grp_refcur( p_grp_data IN OUT grp_cursor, p_group_name IN grp.name%type ) AS
    begin
    open p_grp_data FOR select id, name, description, active
    from grp
    where name = nvl( p_group_name, name ) ;
    end ;
    -- ================================================================================
    PROCEDURE grp_query( p_grp_data IN OUT grp_tab, p_group_name IN grp.name%TYPE ) AS
    i number ;
    CURSOR grp_select IS
    SELECT id, name, description, active
    FROM grp
    WHERE name = nvl( p_group_name, name ) ;
    begin
    OPEN grp_select ;
    i := 1 ;
    LOOP
    FETCH grp_select INTO p_grp_data(i).id, p_grp_data(i).name, p_grp_data(i).description, p_grp_data(i).active ;
    EXIT WHEN grp_select%NOTFOUND ;
    i := i + 1 ;
    END LOOP ;
    end ;
    -- ================================================================================
    PROCEDURE grp_insert( p_grp_data IN grp_tab ) AS
    i NUMBER ;
    begin
    FOR i in p_grp_data.FIRST .. p_grp_data.LAST
    LOOP
    INSERT INTO grp( name, description, active )
    VALUES ( p_grp_data(i).name, p_grp_data(i).description, p_grp_data(i).active ) ;
    END LOOP ;
    end ;
    -- ================================================================================
    PROCEDURE grp_update( p_grp_data in grp_tab ) AS
    i binary_integer ;
    rec_modified exception ;
    BEGIN
    FOR i in p_grp_data.first .. p_grp_data.last LOOP
    UPDATE grp
    SET name = p_grp_data(i).name,
    description = p_grp_data(i).description,
    active = p_grp_data(i).active
    WHERE id = p_grp_data(i).id ;
    if sql%rowcount = 0 then
    raise rec_modified ;
    else
    -- success
    null ;
    end if ;
    END LOOP ;
    exception
    when rec_modified then
    raise_application_error(-20006, 'Record already modified' ) ;
    when others then
    raise_application_error(-20007, 'Other error : ' || sqlerrm ) ;
    END ;
    -- ================================================================================
    PROCEDURE grp_delete( p_grp_data IN grp_id_tab ) AS
    i BINARY_INTEGER ;
    begin
    FOR i IN p_grp_data.FIRST .. p_grp_data.LAST LOOP
    DELETE FROM grp
    WHERE name = p_grp_data(i).id ;
    END LOOP ;
    end grp_delete ;
    -- ================================================================================
    PROCEDURE grp_lock( p_grp_data IN grp_tab ) AS
    i BINARY_INTEGER ;
    grec grprec ;
    err varchar2(255) ;
    errcd number ;
    rec_modified exception ;
    begin
    FOR i in p_grp_data.FIRST .. p_grp_data.LAST LOOP
    begin
    SELECT id, name, description, active
    INTO grec
    FROM grp
    WHERE id = p_grp_data(i).id
    FOR UPDATE OF description NOWAIT ;
    -- this part returns true
    -- if locking_mode = 'Delayed'
    -- Forms is passing NEW values in p_grp_data if mode is Delayed
    -- and OLD values if mode is Immediate
    if ( grec.name != p_grp_data(i).name
    OR grec.description != p_grp_data(i).description
    OR grec.active != p_grp_data(i).active ) THEN
    raise rec_modified ;
    end if ;
    exception
    when no_data_found then
    raise_application_error( -20007, 'Record deleted by another user' ) ;
    when rec_modified then
    raise_application_error(-20006, 'Record modified by another user' ) ;
    when others then
    raise_application_error(-20009, 'Others' ) ;
    end ;
    END LOOP ;
    end ;
    -- ================================================================================
    end grp_pkg ;
    show error package body grp_pkg

    Yes, I was hoping to use these procedures to map the collection type returned to the database to the block data. I guess I was wrong. Except for the initial query and reading some other information from the database, I don't have to use these procedures as I do not write anything to it.
    Thank you for your help, I will go on from there.
    So, it means that I will have to iterate through my collection inside Forms and manipulate my data row by row. Or, is there a way to pass an Oracle collection type between the database and the Forms client and have it displayed without having to iterate through the rows and mapping each field?
    adsm

  • Data Blocks Based on Stored Procedures

    Is it possible to to create a data block based on a stored procedure, and create a dynamic list as a drop down box?
    I have a form that runs successfully that has a data block based on a stored procedure. I add my trigger to create and populate the record group. Then in the Property Palette, when I change ITEM TYPE from TEXT ITEM to LIST ITEM, I receive the following runtime error:
    FRM-40350: Query caused no records to be retrived.
    Note: the tlist/list item runs successfully on a data block based on a table.

    1) go to the block property to remove the same item column, then re-add the item; Since the property may remember the old text type;
    make sure the record value for the list tiem from stored procedure is among the list elements!
    Last sort is to do:
    2) you may re-create your gui based on the table by setting the list type this time, then set the block property to be based on the stored procedure.

Maybe you are looking for