oracle - EXECUTE IMMEDIATE COMMAND -
i getting error ora-00900: invalid sql statement ora-06512: @ line 125 00900. 00000 - "invalid sql statement" when execute sql:
set serveroutput on; declare smartsoftversionitem varchar2(20); maxscriptlevel number; sessionno number; sqlcommand varchar2(8000); begin select max(software_version) smartsoftversionitem s1_grainsmart_dbupdate; select max(script) maxscriptlevel s1_grainsmart_dbupdate; select max(session_no) sessionno ssc_dbupdate; insert ssc_dbupdate values (seq_ssc_dbupdate.nextval, sessionno, sysdate, smartsoftversionitem, maxscriptlevel, null, '17.00.01', 'ssc_ivc_transaction_detail_v', 'v'); sqlcommand := 'create view ssc_ivc_transaction_detail_v select ivc_transaction_detail.ivc_transaction_nbr, ivc_transaction_detail.plc_id, ivc_transaction_detail.commodity_id, ivc_transaction_detail.opening_date, ivc_transaction_detail.group_nbr, ivc_transaction_detail.sort_order, ivc_transaction_detail.transaction_source, ivc_transaction_detail.transaction_time, ivc_transaction_detail.quantity_lb, round(ivc_transaction_detail.quantity_lb * quantity_uom.conv_factor / 10000, quantity_uom.to_nbr_of_decimals) quantity, ivc_transaction_detail.dollar_value, ivc_transaction_detail.add_by, ivc_transaction_detail.orderlog_plc_id, ivc_transaction_detail.orderlog_nbr, ivc_transaction_detail.quantity_entry_nbr, ivc_transaction_detail.contract_nbr, ivc_transaction_detail.vendor_customer_id, ivc_transaction_detail.transaction_note, ivc_transaction_detail.ivc_lot_nbr, ivc_transaction_detail.vehicle_disposition_nbr, ivc_transaction_detail.receipt_nbr, ivc_transaction_detail.adj_type_nbr, ivc_transaction_detail.inv_adj_nbr, ivc_transaction_detail.adj_quantity, ivc_transaction_detail.production_nbr, ivc_transaction_detail.bin_transaction_nbr, ivc_transaction_detail.prd_to_prd_processing_nbr, ivc_transaction_detail.oe_plc_id, ivc_transaction_detail.oe_order_nbr, ivc_transaction_detail.oe_line_item_nbr, ivc_transaction_detail.po_plc_id, ivc_transaction_detail.po_order_nbr, ivc_transaction_detail.po_line_item_nbr, ivc_transaction_detail.mps_contract_nbr, ivc_transaction_detail.production_oh_dollar_value, ivc_transaction_detail.transfer_in_product_cost, ivc_transaction_detail.ae_plc_id, ivc_transaction_detail.ae_accrual_nbr, ivc_transaction_detail.transfer_plc_id, ivc_transaction_detail.transfer_order_nbr, ivc_transaction_detail.transfer_sort_order, ivc_transaction_detail.exchange_rate, ivc_transaction_detail.from_currency_code, '; if maxscriptlevel >= 1700000117 -- wo-1702 sqlcommand := sqlcommand || 'ivc_transaction_detail.theoretical_variance_value, ivc_transaction_detail.dollar_value_basis, ivc_transaction_detail.dollar_value_futures, ivc_transaction_detail.dollar_value_discount, ivc_transaction_detail.dollar_value_other, ivc_transaction_detail.adj_futures_by, ivc_transaction_detail.iv_option_month, ivc_transaction_detail.after_adj_iv_option_month, ivc_transaction_detail.iv_roll_option_month_nbr, ivc_transaction_detail.market_futures_subs_flag, ivc_transaction_detail.zero_futures_subs_flag, ivc_transaction_detail.market_basis_subs_flag, ivc_transaction_detail.zero_basis_subs_flag, '; end if; if maxscriptlevel > 1700030087 -- wo-1840 sqlcommand := sqlcommand || 'ivc_transaction_detail.dollar_value_custom1, ivc_transaction_detail.dollar_value_custom2, '; end if; if maxscriptlevel > 1800000091 -- wo-2404 sqlcommand := sqlcommand || 'ivc_transaction_detail.transfer_receiving_nbr, '; end if; if maxscriptlevel > 1800020121 -- wo-3066 sqlcommand := sqlcommand || 'round(ivc_transaction_detail.cost_summary_quantity_lb * quantity_uom.conv_factor / 10000, quantity_uom.to_nbr_of_decimals) cost_summary_quantity, ivc_transaction_detail.cost_summary_dollar_value '; end if; sqlcommand := sqlcommand || ' ivc_transaction_detail left outer join (select ssc_plc_commodity_uom_v.plc_id, ssc_plc_commodity_uom_v.commodity_id, ssc_plc_commodity_uom_v.conv_factor, ssc_plc_commodity_uom_v.to_nbr_of_decimals ssc_plc_commodity_uom_v ) quantity_uom on quantity_uom.plc_id = ivc_transaction_detail.plc_id , quantity_uom.commodity_id = ivc_transaction_detail.commodity_id '; dbms_output.put_line ('sql command = ' || sqlcommand ); execute immediate 'sqlcommand'; end;
the sql meant dynamic; i.e.: if have reached predetermined script level want include additional columns otherwise not.
yet, if take output sql sqlcommand variable , run creates view. i'm missing obvious - don't see now.
any assistance appreciated. murray
change
execute immediate 'sqlcommand';
to
execute immediate sqlcommand; -- no single quotes