-- заказы на приобретение
Select pll.ship_to_organization_id as org_id,
pll.need_by_date as date_val,
pla.item_id as item_id,
msi.segment1 as item,
msi.primary_uom_code as uom_code,
-- заказано
pla.quantity as ordered_qty
from po_line_locations_all pll,
po_lines_all pla,
po_headers_all pha,
mtl_system_items_b msi
where 1=1
-- pll
and pll.po_line_id = pla.po_line_id
-- ! ограничиваем период
and pll.need_by_date >= trunc(sysdate, 'mm')
-- msi
and msi.inventory_item_id = pla.item_id
and msi.organization_id = pll.ship_to_organization_id
-- pha
and pha.po_header_id = pla.po_header_id
and pha.authorization_status = 'APPROVED' -- только утвержденные ЗП
order by pll.ship_to_organization_id, msi.inventory_item_id, pll.need_by_date
-- транзакции с материалами: расход, приход
select msi.organization_id as org_id,
mmt.transaction_date as date_val,
msi.inventory_item_id as item_id,
msi.segment1 as item,
msi.primary_uom_code as uom_code,
-- приход
case when mmt.primary_quantity > 0 then mmt.primary_quantity
end receive_qty,
-- расход
case when mmt.primary_quantity < 0 then abs(mmt.primary_quantity)
end charges_qty
--
from mtl_system_items_b msi,
mtl_material_transactions mmt
where 1 = 1
-- msi
and msi.inventory_item_status_code = 'Active'
-- mmt
and mmt.organization_id = msi.organization_id
and mmt.inventory_item_id = msi.inventory_item_id
-- ! ограничиваем период
and mmt.transaction_date >= trunc(sysdate, 'mm')
order by msi.organization_id, msi.inventory_item_id, mmt.transaction_date
Более сложный вариант, с учетом разных типов транзакций:
Читать дальше про “Модуль INV — Приход и расход по позициям” »
Заполнение пропусков в выборке.
Пробелы в столбце VAL заполняем по следующему принципу: берем следующее значение VAL и отнимаем от него текущее значение X
Читать дальше про “Заполнение пропусков в выборке” »
Если в таблице слишком много пустых блоков, то оптимизировать данные помогут следующие действия
ALTER TABLE name_table MOVE;
ALTER INDEX name_index REBUILD;
и не забыть обновить статистику для таблицы
begin
dbms_stats.gather_table_stats(schema,table);
end;
Читать дальше про “Убрать пустые блоки из таблицы” »
SELECT mp.compile_designator as plan_name,
msc.plan_id,
msi.organization_id,
msc.sr_inventory_item_id,
msi.inventory_item_id,
msi.segment1,
msi.description
FROM msc_system_items msc,
mtl_system_items_b msi,
msc_plans mp
where 1 = 1
and msi.inventory_item_id = msc.sr_inventory_item_id
and msi.organization_id = msc.organization_id
-- plan
and mp.plan_id = msc.plan_id
order by mp.compile_designator,
msc.plan_id,
msi.organization_id,
msi.inventory_item_id
select msi.organization_id as org_id,
md.formula_id as formula_id,
md.formulaline_id as formulaline_id,
md.line_type as line_type,
msi.inventory_item_id as item_id,
msi.segment1 as item_no,
msi.description as item_descr,
rr.start_date as start_date,
nvl(rr.end_date,to_date('01-01-2099','dd-mm-yyyy')) as end_date
/**/
from mtl_system_items_b msi,
fm_matl_dtl md,
gmd_recipes r,
gmd_recipe_validity_rules rr
where 1 = 1
-- formula
and md.organization_id = msi.organization_id
and md.inventory_item_id = msi.inventory_item_id
-- recipes
and r.formula_id = md.formula_id
and r.recipe_status = 700 -- Утверждено для общего использования
and r.delete_mark = 0 -- не помечен на удаление
and r.owner_organization_id = md.organization_id
-- recepe rules
and rr.recipe_id = r.RECIPE_ID
and rr.organization_id = md.organization_id
and rr.delete_mark = 0 -- не помечен на удаление
and rr.validity_rule_status = 700 -- Утверждено для общего использования
and rr.recipe_use = 0 -- использование рецепта = Производство
order by msi.organization_id, md.formula_id, md.line_type desc, md.line_no
select gbh.organization_id,
gbh.batch_no,
gmd.inventory_item_id,
gmd.line_type,
md.qty
from fm_matl_dtl md, gme_material_details gmd, gme_batch_header gbh
where 1 = 1
and gmd.batch_id = gbh.batch_id
and gmd.organization_id = gbh.organization_id
and md.formula_id = gbh.formula_id
and md.formulaline_id = gmd.formulaline_id
order by gbh.organization_id,
gbh.batch_no,
gmd.inventory_item_id,
gmd.line_type
select t.object_name,
t.object_type,
dbms_rowid.rowid_object('AABDKKAGRAAAOXhAAR') as "OBJECT",
dbms_rowid.rowid_relative_fno('AABDKKAGRAAAOXhAAR') as "FILE",
dbms_rowid.rowid_block_number('AABDKKAGRAAAOXhAAR') as "BLOCK",
dbms_rowid.rowid_row_number('AABDKKAGRAAAOXhAAR') as "ROW"
from dba_objects t
where dbms_rowid.rowid_object('AABDKKAGRAAAOXhAAR') = t.data_object_id
OBJECT_NAME OBJECT_TYPE OBJECT FILE BLOCK ROW
--------------- -------------- ---------- -------- ---------- ----------
FM_FORM_MST_B TABLE 275082 401 58849 17
Скрипт создания функции
create or replace type string_agg_type as object (
total varchar2(4000),
static function ODCIAggregateInitialize(sctx IN OUT string_agg_type )
return number,
member function ODCIAggregateIterate(self IN OUT string_agg_type ,
value IN varchar2 ) return number,
member function ODCIAggregateTerminate(self IN string_agg_type,
returnValue OUT varchar2,
flags IN number) return number,
member function ODCIAggregateMerge(self IN OUT string_agg_type,
ctx2 IN string_agg_type) return number
);
/
create or replace type body string_agg_type is
static function odciaggregateinitialize(sctx IN OUT string_agg_type)
return number is
begin
sctx := string_agg_type(null);
return odciconst.success;
end;
member function odciaggregateiterate(self IN OUT string_agg_type,
value IN varchar2) return number is
begin
self.total := self.total || ',' || value;
return odciconst.success;
end;
member function odciaggregateterminate(self IN string_agg_type,
returnvalue OUT varchar2,
flags IN number) return number is
begin
returnvalue := ltrim(self.total, ',');
return odciconst.success;
end;
member function odciaggregatemerge(self IN OUT string_agg_type,
ctx2 IN string_agg_type) return number is
begin
self.total := self.total || ctx2.total;
return odciconst.success;
end;
end;
/
CREATE or replace FUNCTION stragg(input varchar2) RETURN varchar2
PARALLEL_ENABLE
AGGREGATE USING string_agg_type;
/
Читать дальше про “Агрегатная функция stragg — складывает строки” »
Запрос для просмотра полномочий пользователя OEBS:
SELECT distinct
u.user_id,
u.user_name,
fr.responsibility_key,
r.responsibility_name as responsiblity,
fa.application_short_name,
a.application_name as application,
sg.security_group_key,
'dbms_output.put_line('''|| r.responsibility_name ||''');'||chr(10)||'fnd_user_pkg.addresp(l_user_name, '''||fa.application_short_name||''', '''|| fr.responsibility_key ||''', '''||sg.security_group_key||''', ''Add by script'', sysdate, null);' as str
FROM fnd_user u,
fnd_user_resp_groups g,
fnd_application_tl a,
fnd_application fa,
fnd_responsibility_tl r,
fnd_responsibility fr,
fnd_security_groups sg
WHERE g.user_id(+) = u.user_id
AND g.responsibility_application_id = a.application_id
AND a.application_id = r.application_id
and fa.application_id = r.application_id
AND g.responsibility_id = r.responsibility_id
and fr.responsibility_id = r.responsibility_id
and fr.application_id = r.application_id
and sg.security_group_id = g.security_group_id
AND a.LANGUAGE = 'RU'
AND r.LANGUAGE = 'RU'
AND u.user_name = '!!!USER_NAME'
ORDER BY user_name, responsiblity, application
Последние комментарии