Skip to Main Content

APEX

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Generate Order Id and insert data in to two different tables : apex oracle 5.0

Pranav.shahJun 1 2015 — edited Jun 1 2015

i have three tables. name of the tables: PRODUCT,ORDER_HEADER,ORDER_DETAIL. i have taken INTER-ACTIVE REPORT in which VALUES are coming from TABLE Product . i need to use trigger here there is one TEXT ITEM called ORDER ID: it will generate via trigger. so each time new order placed order id must be unique. there is one button on click of that button REPORT VALUES must be inserted in to ORDER_HEADER,ORDER_DETAIL(Actually i am in confusion is it even possible).

I tried to create Trigger: Not Working Though


CREATE OR REPLACE TRIGGER  "EMP_TRG1"  

before insert on order_header

  for each row 

begin

    if :new.Order_ID is null

then    

    select lpad(demo_seq.nextval,8,'0') into :new.Order_ID from order_header;   

end if;

end;

SQL:

select

       apex_item.text(1,p.PRODUCT_ID) PID,

       pn.product_name,

       apex_item.text(2,p.PRODUCT_QTY) qt,

       apex_item.text(3,p.unit_price) up,

       apex_item.text(4,p.TOTAL_AMOUNT) am

             

  from OMS_SHIP_CART_DETAIL p, OMS_PRODUCT pn

  where p.product_id=pn.product_id

DA:

var arr_f01 = []; 

var arr_f02 = []; 

var arr_f03 = []; 

var arr_f04 = []; 

var arr_f05 = [];

var product_id;

var unit_price;

var qty;

var total_1;

$("input[name='f01']").each( 

function() { 

product_id = $(this).closest('tr').children('td[headers="PID"]').text() ;

unit_price = $(this).closest('tr').children('td[headers="Uprice"]').text() ;

qty = $(this).closest('tr').children('td[headers="Qty"]').text() ;

  total_1=$(this).closest('tr').children('td[headers="total"]').text() ;

arr_f01.push($(this).val()); 

arr_f02.push(product_id);

arr_f03.push(total_1); 

arr_f04.push(unit_price);

arr_f05.push(qty);

}  ); 

apex.server.process ( 

  "insert order" 

, {  f01: arr_f01, f02: arr_f02, f03: arr_f03, f04: arr_f04, f05: arr_f05

  } 

, { dataType: 'text',success: function(pData){alert('Product Added'); } 

);

Ajax CallBack:

declare

l_count number;

begin

--insert into OMS_ORDER_HEADER(USER_ID,TOTAL_AMOUNT,STATUS_ID,ORDER_DATE)values(:P1_USER_ID,:P42_TOTAL,'PENDING',SYSDATE);

for i in 1..apex_application.g_f01.count loop

insert into OMS_ORDER_DETAIL(PRODUCT_ID,UNIT_QTY,UNIT_PRICE,TOTAL_AMOUNT)

values(APEX_APPLICATION.G_F01(i),APEX_APPLICATION.G_F03(i),APEX_APPLICATION.G_F04(i),APEX_APPLICATION.G_F05(i));

commit;

end loop;

end;

This post has been answered by Jitendra on Jun 1 2015
Jump to Answer
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Jun 29 2015
Added on Jun 1 2015
6 comments
478 views