Search This Blog

Tuesday, November 15, 2011

Automatic Partition Management for Oracle 10g


* You can’t migrate to Oracle 11g on the fly. You’re stuck in 10g
* You also need to drop the oldest partition, because you have lack of storage issues
Then if you are in this situation we have the solution for you. It’s bullet-proof tested and proven at production sites.
Every night you need to add another partition and remove the oldest. Pure moving window stuff. The format of the partition name is: PXXXX_YYYY_MM_DD, where XXXX is a sequential number that increments every day. This is daily partitioning and should only have a job running this code everynight:
declare
x varchar2(90);
s varchar2(900);
begin
-- Fetchs the name of the oldest partition
select partition_name
into x
from sys.dba_tab_partitions
where partition_position = 1
and table_name = 'MYTABLE'
and table_owner = 'MYOWNER';
-- Builds the name-string
s := 'ALTER TABLE MYOWNER.MYTABLE DROP PARTITION '||x||' UPDATE INDEXES';
-- Uses a customized report and sends it by email
-- so you can see the partitions state before and after
MYOWNER.my_pkg.sends_email('REPORT6');
-- Drops the Partition
execute immediate s;
-- And now adds another
MYOWNER.add_partition;
MYOWNER.my_pkg.sends_email('REPORT6');
--dbms_output.put_line(s);
end;
The procedure “add_partition” is another piece of automatic code that you must create prior to the previous PL/SQL block:

CREATE OR REPLACE procedure MYOWNER.add_partition
is
next_part varchar2(40);
less_than_char varchar2(20);
comando_add varchar2(1000);
BEGIN
-- Generates the name of the partition
select 'P'||to_char(to_number(substr(partition_name,2,
         instr(partition_name,'_',1)-2))+1)||'_'||
         to_char(to_date(substr(partition_name,
         instr(partition_name,'_',1)+1),'yyyy_mm_dd')+1,'yyyy_mm_dd'),
         replace(to_char(to_date(substr(partition_name,
        instr(partition_name,'_',1)+1),'yyyy_mm_dd')+2,'yyyy_mm_dd'),'_','-')
into next_part,less_than_char
from dba_tab_partitions
where table_owner = 'MYOWNER'
and table_name = 'MYTABLE'
and partition_position = (select max(partition_position)
from dba_tab_partitions where table_owner = 'MYOWNER'
and table_name = 'MYTABLE');
-- Builds the statement string
comando_add :=              'ALTER TABLE MYOWNER.MYTABLE ADD PARTITION '||next_part;
comando_add := comando_add||' VALUES LESS THAN (to_date('||chr(39)||less_than_char;
comando_add := comando_add||chr(39)||','||chr(39)||
'yyyy-mm-dd'||chr(39)||')) TABLESPACE DATA_PARTITIONED';
-- Executes the statement
execute immediate(comando_add);
--dbms_output.put_line(comando_add);
end;
/

You will have permission issues that you can resolve reading this.

Source: http://ocpdba.wordpress.com/2009/10/12/automatic-partition-management-for-oracle-10g/

Friday, September 16, 2011

R12 Subledger Accounting Process Events

You can run accounting in two ways, one is Online other is batch mode. Online accounting is ideal when you want to generate accounting event for one transaction. Batch mode accounting process will be initiated by submitting accounting concurrent request (Create Accounting, Submit accounting)
There is no difference if you run online accounting or batch accounting in terms of the event generation. Only different is in detailed reporting
Tables that are involved in this process are
XLA_TRANSACTION_ENTITIES
XLA_EVENTS
XLA_AE_HEADERS
XLA_AE_LINES
GL_IMPORT_REFERENCES
GL_JE_LINES
GL_JE_HEADERS
GL_BALANCES

Links Between these tables

GL_JE_LINES (JE_HEADER_ID, JE_LINE_NUM)    GL_IMPORT_REFERENCES (JE_HEADER_ID, JE_LINE_NUM)
GL_IMPORT_REFERENCES (GL_SL_LINK_TABLE, GL_SL_LINK_IDXLA_AE_LINES (GL_SL_LINK_TABLE, GL_SL_LINK_ID)
XLA_AE_LINES (APPLICAITON_ID, AE_HEADER_ID)XLA_AE_HEADERS (APPLICATION_ID, AE_HEADER_ID)
XLA_AE_HEADERS (APPLICATION_ID, EVENT_ID)XLA_EVENTS (APPLICATION_ID, EVENT_ID)
XLA_EVENTS (APPLICATION_ID, ENTITY_ID)XLA_TRANSACTION_ENTITIES (APPLICATION_ID, ENTITY_ID)

Draft : Draft will create journal entries, which are not final, which means they are not ready to be transferred to GL.
You can create accounting on this transaction again and again, which will delete the old journal entries and create new ones. You can’t transfer these journal entries to GL.
xla_events.process_status_code = D
xla_events.event_status_code = U
xla_ae_headers.accounting_entry_status_code = D

Final : Final will create journal entries, which can be transferred to GL. Once it is finally accounted you can’t run create accounting on the particular transaction (specifically on that event).
Run Transfer Journal Entries to GL program
xla_events.process_status_code = P
xla_events.event_status_code = P
xla_ae_headers.accounting_entry_status_code = F

Final Post: Final Post will create journal entries in final mode, transfer them to GL and post them.
xla_ae_headers.accounting_entry_status_code = F
xla_ae_headers.transfer_status_code = Y
xla_events.process_status_code = P
xla_events.event_status_code = P


Source: http://appssupport.com/2010/05/21/r12-subledger-accounting-process-events/

Friday, September 9, 2011

Reading parameterized cursor example

declare
p_eod_signal_type varchar2(29) := 'FAGIO';
p_eod_date varchar2(29) := '2011-08-09';
v_rec_count number := 0;
 CURSOR gl_eod_txns_c(p_eod_date IN VARCHAR2, p_eod_signal_type IN VARCHAR2) IS
SELECT je_header_id,
           period,
           je_line_num,
           effective_date,
           bank_day,
           accounted_cr,
           accounted_dr,
           is_credit,
           verification_number,
           source_nr,
           clnr,
           account_nr,
           rst,
           aggr_flag,
           accounting_sequence,
           ledger_id, --added by p950nle for RESTORE
           je_category_key --added for defect 1037
    FROM   xxogl_f04_gl_eod_txns_v xfgetv
    WHERE  xfgetv.eod_date = p_eod_date
    AND xfgetv.ledger_id in decode(p_eod_signal_type, 'CAL', '2047', 'FAGIO', '2044');
   
begin
  for l2 in gl_eod_txns_c(p_eod_date, p_eod_signal_type)
  loop
     dbms_output.put_line(gl_eod_txns_c%Rowcount || ' ' || l2.ledger_id);
  end loop;
  dbms_output.put_line('Executed');
end;

Wednesday, August 10, 2011

Concurrent program executable file name

Select a.concurrent_program_id, c.user_concurrent_program_name, a.concurrent_program_name, b.executable_name, b.execution_file_name, b.execution_file_path,
DECODE(b.EXECUTION_METHOD_CODE,'Q','SQLPLUS','P','Oracle Reports','I','PL/SQL Stored Procedure','L','SQLLOADER','H','HOST','A','SPAWNED','J','JAVA','R','SQLREPORT','X','Flexrpt','S','IMMEDIATE', 'K', 'Java Concurrent Program', b.execution_method_code)
EXECUTION_METHOD_CODE
from fnd_concurrent_programs a,
     fnd_executables b,
     fnd_concurrent_programs_tl c
where a.executable_id = b.executable_id
and a.concurrent_program_id = c.concurrent_program_id
and c.user_concurrent_program_name like <concurr_prog_name>

Tablespace usage query

Tablespace usage in percentage

select  tsu.tablespace_name, ceil(tsu.used_mb) "size MB"
, decode(ceil(tsf.free_mb), NULL,0,ceil(tsf.free_mb)) "free MB"
, decode(100 - ceil(tsf.free_mb/tsu.used_mb*100), NULL, 100,
               100 - ceil(tsf.free_mb/tsu.used_mb*100)) "% used"
from (select tablespace_name, sum(bytes)/1024/1024 used_mb
 from  dba_data_files group by tablespace_name union all
 select  tablespace_name || '  **TEMP**'
 , sum(bytes)/1024/1024 used_mb
 from  dba_temp_files group by tablespace_name) tsu
, (select tablespace_name, sum(bytes)/1024/1024 free_mb
 from  dba_free_space group by tablespace_name) tsf
where tsu.tablespace_name = tsf.tablespace_name (+)
order by 4

Source: http://www.shutdownabort.com/dbaqueries/Structure_Tablespace.php

Wednesday, August 3, 2011

RequestSet+Stages+Programs+parameters (Oracle R12)

The query below lists Stages, programs and its parameters (only for particular type of program)

SELECT rs.request_set_id set_id,    --rsp.request_set_program_id,
  rs.user_request_set_name set_name,
  rstg.display_sequence seq, rstg.stage_name,
  rstgtl.user_stage_name,
  rsp.concurrent_program_id con_PROG_ID,
  CCP.user_concurrent_program_name,
  fccp.concurrent_program_name,
  (select Default_value from FND_REQUEST_SET_PROGRAM_ARGS x
  where x.request_set_id = rs.request_set_id
  and x.descriptive_flexfield_name = '$SRS$.XXOGL_F16_REPORT_FRAMEWORK'
  and x.application_column_name = 'ATTRIBUTE3' --the column used to store params
  and x.request_set_program_id = rsp.request_set_program_id
   ) "param: prog",
   (select Default_value from FND_REQUEST_SET_PROGRAM_ARGS x
  where x.request_set_id = rs.request_set_id
  and x.descriptive_flexfield_name = '$SRS$.XXOGL_F16_REPORT_FRAMEWORK'
  and x.application_column_name = 'ATTRIBUTE13'
  and x.request_set_program_id = rsp.request_set_program_id
   ) "param: parameter_list",
   (select Default_value from FND_REQUEST_SET_PROGRAM_ARGS x
  where x.request_set_id = rs.request_set_id
  and x.descriptive_flexfield_name = '$SRS$.XXOGL_F16_REPORT_FRAMEWORK'
  and x.application_column_name = 'ATTRIBUTE7'
  and x.request_set_program_id = rsp.request_set_program_id
   ) "param: destination"
FROM apps.fnd_request_Sets_tl rs,
  apps.FND_REQUEST_SET_STAGES RSTG,
  apps.fnd_REQUEST_SET_STAGES_tl rstgtl,
  apps.FND_REQUEST_SET_PROGRAMS RSP,
  apps.FND_CONCURRENT_PROGRAMS_TL CCP,
  apps.fnd_CONCURRENT_PROGRAMS fccp
WHERE RS.request_set_id = rstg.request_set_id
and rs.request_set_id = rstgtl.request_set_id
and rstg.request_set_id = rstgtl.request_set_id
and rstg.request_set_stage_id = rstgtl.request_set_stage_id
AND rs.request_set_id = rsp.request_set_id
AND rstg.request_set_stage_id = rsp.request_set_stage_id
AND rsp.concurrent_program_id = CCP.concurrent_program_id
and ccp.concurrent_program_id = fccp.concurrent_program_id
AND rs.user_request_set_name LIKE '<Request Set Name>' --'%F70 EOP%'
ORDER BY rstg.display_sequence

Wednesday, July 27, 2011

List all the programs for a Request Set (oracle R12)

The query below lists all the stages and concurrent programs in a Request Set.

SELECT rs.request_set_id set_id,
  rs.user_request_set_name set_name,
  rstg.display_sequence seq, rstg.stage_name,
  rstgtl.user_stage_name,
  rsp.concurrent_program_id con_PROG_ID,
  CCP.user_concurrent_program_name
  , fccp.concurrent_program_name
FROM apps.fnd_request_Sets_tl rs,
  apps.FND_REQUEST_SET_STAGES RSTG,
  apps.fnd_REQUEST_SET_STAGES_tl rstgtl,
  apps.FND_REQUEST_SET_PROGRAMS RSP,
  apps.FND_CONCURRENT_PROGRAMS_TL CCP
  ,  apps.fnd_CONCURRENT_PROGRAMS fccp
WHERE RS.request_set_id = rstg.request_set_id
and rs.request_set_id = rstgtl.request_set_id
and rstg.request_set_id = rstgtl.request_set_id
and rstg.request_set_stage_id = rstgtl.request_set_stage_id
AND rs.request_set_id = rsp.request_set_id
AND rstg.request_set_stage_id = rsp.request_set_stage_id
AND rsp.concurrent_program_id = CCP.concurrent_program_id
and ccp.concurrent_program_id = fccp.concurrent_program_id
AND rs.user_request_set_name LIKE :req_set_name --'%F70 Flows'
ORDER BY rstg.display_sequence

Tuesday, June 7, 2011

Install and use RAR in Linux or Unix

Download binary package from official rarlab site:
$ cd /tmp
$ wget http://www.rarlab.com/rar/rarlinux-3.6.0.tar.gz

Untar file
$ tar -zxvf rarlinux-3.6.0.tar.gz
Both unrar and rar commands are located in rar sub-directory. Just go to rar directory:
$ cd rar
$ ./unrar

Now copy rar and unrar to /bin directory:
# cp rar unrar /bin

How to use unrar

unrar command supports various options below are common options that you need to use everyday.

Task: To open rar (unpack) file in current directory type command:

$ unrar e file.rar
Please note that replace file.rar filename with your actual filename.

Task: List (l) file inside rar archive:

$ unrar l file.rar

Task: To extract (x) files with full path type command:

$ unrar x file.rar
(D) To test (t) integrity of archive, file type command:
$ unrar t file.rar

Source: http://www.cyberciti.biz/faq/open-rar-file-or-extract-rar-files-under-linux-or-unix/