Saturday, August 7, 2021

search utility

     #/bin/ksh

rm -rf stored_files sorted_search_files 2>/dev/null

while read file_list

do

    echo "======================================================================================" >> stored_files

    echo "Search Directory : $file_list" >> stored_files

echo "**************************************************************************************" >> stored_files

while read search_line

do

    find "$file_list"  -maxdepth 1 -name "*" ! -name "*.dat*" ! -name "*.bad*" ! -name "*.pdf*" ! -name  "*.txt*" ! -name  "*.log*" ! -name "*.csv*" -type f -exec egrep -i "$search_line" {} \; -print >> stored_files

    find "$file_list"  -maxdepth 1 -name "*" ! -name "*.dat*" ! -name "*.bad*" ! -name "*.pdf*" ! -name  "*.txt*" ! -name  "*.log*" ! -name "*.csv*" -type f -exec egrep -il "$search_line" {} \; -print >> sorted_search_files

done < search_list

echo "======================================================================================" >> stored_files

done < search_directory

if [ -f "sorted_search_files" ] ; then

    sort -u sorted_search_files |mailx -s "Searched File List" emailAddress

    echo "Check your email"

fi

if [ -f "stored_files" ] ; then

    echo "Searched file content is created in the directory `pwd` file name : stored_files" 

    uuencode stored_files stored_files |mailx -s "Searched File List Content" emailAddress

fi

Trigger

 Introduction to Oracle Statement-level triggers

A statement-level trigger is fired whenever a trigger event occurs on a table regardless of how many rows are affected. 

In other words, a statement-level trigger executes once for each transaction.

For example, if you update 1000 rows in a table, then a statement-level trigger on that table would only be executed once.

even it will execute without no rows affected


Due to its features, a statement-level trigger is not often used for data-related activities like auditing the changes 

of the data in the associated table. It’s typically used to enforce extra security measures on the kind of transaction that may 

be performed on a table.


Row-level triggers fires once for each row affected by the triggering event such as INSERT, UPDATE, or DELETE.


Row-level triggers are useful for data-related activities such as data auditing and data validation.


Pragma Autonomous_transaction;

------------------------------

when we issue rollback or commit inside the trigger it throw error

create or replace trigger mytriggers 

after insert on mytable

--declare

--pragma autonomous_transaction;

--null;

begin

  insert into chidam values('fire');

  commit;

end;


execute : insert into mytable values(1,'chidam1','y1');


it throws error we need to avoid for this used


create or replace trigger mytriggers 

after insert on mytable

declare

pragma autonomous_transaction;

--null;

begin

  insert into chidam values('fire');

  commit;

end;



=======================================================

Mutation


in row level trigger , trigger is written on one table , trying to use the same table in execution part it will throw error


avoid : convert the row level trigger to statement level trigger



8


SQL Error: ORA-04091: table APPS.MYTABLE is mutating, trigger/function may not see it


Avoid : use statement


=====================================

create or replace trigger mytriggers 

after insert on mytable

for each row

declare

lv_number number;

begin

  --insert into chidam values('fire');

  --select count(*) into lv_number from mytable where status='y';

  --dbms_output.put_line(lv_number);

  insert_data;

 -- commit;

end;




*Action:   Ensure that before returning from an autonomous PL/SQL block,

           any active autonomous transactions are explicitly committed

           or rolled bac


create or replace procedure insert_data

is

pragma autonomous_transaction;

begin

insert into chidam values('Akshara1');

commit; --- we should use commit or rollback 

end;    


================

calling function 

----------------

create or replace trigger mytriggers 

after insert on mytable

for each row

declare

lv_number number;

begin

  insert into chidam values('fire');

  --select count(*) into lv_number from mytable where status='y';

  --dbms_output.put_line(lv_number);

  insert_data;

  dbms_output.put_line(insert_data_fun);

 -- commit;

end;


---------------------------------------------


9


A mutating table occurs when a statement causes a trigger to fire and that trigger references the table that caused the trigger. The best way to avoid such problems is to not use triggers, but I suspect the DBA didn’t take the time to do that. He could have done one of the following:


Changed the trigger to an after trigger.

Changed it from a row level trigger to a statement level trigger.

Convert to a Compound Trigger.

Modified the structure of the triggers to use a combination of row and statement level triggers.

Made the trigger autonomous with a commit in it.


----------------------


sqlloader

 

options(skip=1)

load data

truncate into table sqlldr_ex

fields terminated by ","

optionally enclosed by '"'

trailing nullcols

(id,name,jdate date "yyyymmdd")

 

xxchidam_multiple.ctl_edit

 

sqlldr apps/apps data=xxchidam_datafile.dat control=xxchidam_multiple.ctl_edit direct=true discard=chidam.csv

 

** dont use skip option when using when clause

** we need to use position from second when clause

** use discard option to capture disard records

 

CREATE TABLE tab1(ID NUMBER, NAME VARCHAR2(100),jdate DATE);

 

CREATE TABLE tab2(ID NUMBER, NAME VARCHAR2(100),jdate DATE);

 

CREATE TABLE tab2(ID NUMBER, NAME VARCHAR2(100),const varchar2(100),func varchar2(100),default_v varchar2(100),created_date date);

 

load data

append

into table tab1

when name='chidam'

fields terminated by ","

optionally enclosed by '"'

trailing nullcols

(

     name POSITION(1) CHAR,

     id,

     jdate date "yyyymmdd"

)

into table tab2

when (name='divi')

fields terminated by ","

optionally enclosed by '"'

trailing nullcols

(

       name POSITION(1) CHAR,

       id,

       jdate date "yyyymmdd"

)

into table tab3

when (name='aksh')

fields terminated by ","

optionally enclosed by '"'

trailing nullcols

(

       name POSITION(1) CHAR "TRIM(:name)",

       x filler,

       id,

       const constant "CHIDAM",

       func "sqlldr_fun",

       default_v "NVL(:default_v,'default')",

       created_date "SYSDATE"

)

 

begindata

id,name,date

chidam,1,20200120

divi,2,20200122

aksh,filler_data,100,,,,,

 

 

 

sqlldr parfile=chidam.parfile

parfile=chidam.parfile

chidam.parfile content

                       userid=ot@pdborc/Abcd1234

                       control=email.ctl

                       log=email.log

                       bad=email.bad

                       data=email.dat

                       direct=true

 

 

 

POSITION BASED

 

$ cat employee-fixed.txt

200JasonTechnology5500

300MaylaTechnology7000

400NishaTechnology9500

500RandyTechnology6000

 

$ cat sqlldr-fixed.ctl

load data

 infile '/home/ramesh/employee-fixed.txt'

 into table employee

 fields terminated by ","

 ( id position(1:3), name position(4:8), dept position(9:18), salary position(19:22) )

 

CREATE TABLE xxlin_load_file_sqlldr(ID NUMBER, file_name VARCHAR2(100),file_data CLOB)

 

load data

truncate into table xxlin_load_file_sqlldr

fields terminated by ","

optionally enclosed by '"'

trailing nullcols

(

id,

file_name,

file_data lobfile(file_name) terminated by eof

)

begindata

100,/home/oracle/xxchidam/xxchidam_datafile_1.dat

101,/home/oracle/xxchidam/xxchidam_datafile_2.dat

102,/home/oracle/xxchidam/xxchidam_datafile_3.dat

Coding round

 set serveroutput on;

DECLARE

    n NUMBER := 0;

BEGIN

    WHILE n < 5 LOOP

        dbms_output.put_line(n);

        n := n + 1;

    END LOOP;

END;


DECLARE

    n NUMBER := 0;

BEGIN

    LOOP

        dbms_output.put_line(n);

        n := n + 1;

        exit when n=10;

    END LOOP;

END;

;


select level from dual connect by level<11;


select rownum from dual connect by rownum<11;


SELECT rownum

FROM XMLTABLE('1 to 10');


declare

n varchar2(100) :='chidambaram';

begin

for i in 1 .. length(n)

loop

dbms_output.put_line(substr(n,length(n)-i+1,1));

end loop;

end;


DECLARE

    prim BOOLEAN := true;

BEGIN

    FOR i IN 1..25 LOOP

        FOR j IN 1..i LOOP 

        IF MOD(i, j) = 0 AND j != 1 AND i != j THEN

            prim := false;

            EXIT;

        ELSE

            prim := true;

        END IF;

        END LOOP;


        IF prim = true THEN

            dbms_output.put_line('prim:' || i);

        END IF;

    END LOOP;

END;



select reverse('chidambaram') from dual;

================================================================


select * from tab;

set serveroutput OFF;

select /*+ gather_plan_stastics */ *  from DEPARTMENTS;

select * from table(dbms_xplan.display_cursor(null,null,'ALLSTATS LAST'));

select /*+ gather_plan_statistics CHIDAM*/ count(*) from dba_objects;

SELECT *

FROM   TABLE (DBMS_XPLAN.display_cursor ('73pq2vs0hc86n', null, 'ALLSTATS LAST'));

SELECT * FROM V$SQL;

SELECT * FROM V$SQLTEXT WHERE SQL_TEXT LIKE '%CHIDAM%';


===================================


SELECT a.msg_state, 

       a.user_data.event_name, 

       a.user_data.send_date

FROM applsys.aq$wf_deferred a

WHERE a.user_data.event_name LIKE 'oracle.apps.ar.transaction.Invoice.complete' --Here We need to pass Business event name

GROUP BY a.msg_state, a.user_data.event_name, a.user_data.send_date

ORDER BY a.user_data.event_name,a.user_data.send_date DESC;


select w_even.name

  ,w_even.status event_status

  ,w_e_subs.status subscription_status

  ,nvl(w_e_subs.phase,0) subscription_phase

  ,w_e_subs.rule_function

from wf_events w_even

  ,wf_event_subscriptions w_e_subs

where

  w_even.name like 'oracle.apps.ar.transaction.Invoice.complete'

  and w_e_subs.event_filter_guid = w_even.guid;

  

  SELECT wd.user_data.event_name,

       wd.user_data.event_key,

       rank() over(PARTITION BY wd.user_data.event_name, wd.user_data.event_key ORDER BY n.NAME) AS serial_no,

       n.NAME parameter_name,

       n.VALUE parameter_value,

       wd.user_data.error_message,

       wd.user_data.error_stack,

       wd.msgid,

       wd.delay

  FROM apps.wf_deferred wd, TABLE(wd.user_data.parameter_list) n

 WHERE  1=1

 AND wd.user_data.event_name  ='oracle.apps.ar.transaction.Invoice.complete'

 ORDER BY wd.user_data.send_date DESC,

          wd.user_data.event_name,

          wd.user_data.event_key,

          n.NAME;

  

  

  select regexp_substr('chidam-baram-k--B','[^-]+',1,level) val_ou

                     from   dual

                     connect by regexp_substr('chidam-baram-k--B','[^-]+',1,level);

                     

with t as (select 'chidam,ram,baram,,k,,,J' descript from dual 

                              )

                     select regexp_substr(descript,'[^,]+',1,level) val_ou

                     from   t

                     connect by regexp_substr(descript,'[^,]+',1,level) is not null;

                     

  select regexp_substr('chidam-baram-k--B','([^-]*)(-|$)',1,5,null,1) from dual;                   

  

  select * from wf_events where upper(name) like 'ORACLE.APPS.AR.TRANSACTION.INVOICE.COMPLETE';

  

  set serveroutput off;


select /+ gather_plan_statistics/ * from dual;


select /+ gather_plan_statistics/ count(p) from t where x > sysdate - 30;


select * from table(dbms_xplan.display_cursor(null, null, 'ALLSTATS LAST'));

  

   SELECT /*+ gather_plan_statistics */  description,lookup_code

                     FROM   fnd_lookup_values

                     WHERE  enabled_flag = 'Y'

                     and language='US'

                            AND SYSDATE BETWEEN NVL(start_date_active,SYSDATE-1) AND NVL(end_date_active,SYSDATE+1)

                          --  AND lookup_code = p_lookup_code_in

                            AND lookup_type = 'XXSWPE_WEBSERVICE_CONFIG';

                            

select * from table(dbms_xplan.display(FORMAT=>'ALLSTATS LAST'));

===================================



select * from WF_ROLES WHERE NAME='ERPSCHOOLS_DEMO_ROLE';

select * from WF_USER_ROLES WHERE ROLE_NAME='ERPSCHOOLS_DEMO_ROLE';

 

select * from WF_LOCAL_ROLES WHERE NAME='ERPSCHOOLS_DEMO_ROLE';

 

select * from WF_USER_ROLE_ASSIGNMENTS WHERE ROLE_NAME='ERPSCHOOLS_DEMO_ROLE';


select * from mtl_system_items_b where segment1='CDM_TEST1';


select * from fnd_user where user_name='CXK952';


SELECT * FROM wf_deferred;


select * from wf_messages where name='XOA_TEST_MSG';


select * from wf_notifications ;where recipient_role='ERPSCHOOLS_DEMO_ROLE'; message_name='ERP_SEND_ITEM_DET_MSG';


CREATE TABLE debug (msg varchar2(1000));


SELECT * FROM DEBUG;


SELECT * FROM wf_item_attribute_values WHERE item_type = 'CHIDAM_W';


SELECT * FROM wf_items WHERE item_type = 'CHIDAM_W';


SELECT * FROM wf_item_activities_history_v WHERE item_type = 'CHIDAM_W';

SELECT * FROM wf_item_attribute_values WHERE item_type = 'CHIDAM_W';

SELECT * FROM wf_items WHERE item_type = 'ENGCSTEP' AND ITEM_KEY='11505372';

SELECT * FROM wf_item_activities_history_v WHERE item_type = 'CHIDAM_W';

===================================

shell script for oracle apps help

 file_gw()

{

_CNT1=`ls -l "$1"| awk '{print $5}'`

_CNT2=0

until [[ ${_CNT1} = ${_CNT2} ]]; do

_CNT1=`ls -l "$1"| awk '{print $5}'`

sleep 5

_CNT2=`ls -l "$1"| awk '{print $5}'`

done

echo -e "File is stabled : $1"

}

para_file=$(mktemp)

chmod 600 $para_file

echo "userid=${FCP_LOGIN}" > $para_file

sqlldr parfile=$para_file  control=$FILE_PATH/XSIAP_ECHECK_CS_IMAGE_DETAILS.ctl log=$LOG_PATH/${file}.log bad=$LOG_PATH/${file}.bad  data=${each_files}



Control file

 LOAD DATA

                CHARACTERSET UTF8

                INFILE '$MSIAP_TOP/log/file_list_toload.dat'

                INTO TABLE XSIAP_RUSSIA_PMT_ACK_DATA APPEND

                (

                                REQUEST_ID constant \"$REQ_ID\",

                                FILENAME constant \"$fname\",

                                file_name filler char(200)

                                ,xml_data LOBFILE (file_name) TERMINATED BY EOF

                )

PLSQL in Shell

 sqlplus -s /nolog  <<ENDFTP

connect ${FCP_LOGIN}

set serveroutput on

whenever sqlerror exit FAILURE


BEGIN


declare

lv_return_msg VARCHAR2(500);

result boolean;

begin

result := GL_CMNPKG.FTP('AP_PFR_FTP','$source_file',lv_return_msg,'$val');

dbms_output.put_line(lv_return_msg);

end;


END;

/

ENDFTP


RC="$?"