Avoiding global variables means you can use the function in a pipe. Here is an example:

#!/bin/bash

makeJunk()
{
   echo 'this is junk'
   echo '#more junk and "b@d" characters!'
   echo '!#$^%^&(*)_^&% ^$#@:"<>?/.,\\"'"'"
}

processJunk()
{
    local -a arr=()    
    # read each input and add it to arr
    while read -r line
    do 
       arr[${#arr[@]}]='"'"$line"'" is junk'; 
    done;

    # output the array as a string in the "declare" representation
    declare -p arr | sed -e 's/^declare -a [^=]*=//'
}

# processJunk returns the array in a flattened string ready for "declare"
# Note that because of the pipe processJunk cannot return anything using
# a global variable
returned_string=`makeJunk | processJunk`

# convert the returned string to an array named returned_array
# declare correctly manages spaces and bad characters
eval "declare -a returned_array=${returned_string}"

for junk in "${returned_array[@]}"
do
   echo "$junk"
done

Output is:

"this is junk" is junk
"#more junk and "b@d" characters!" is junk
"!#$^%^&(*)_^&% ^$#@:"<>?/.,\\"'" is junk


A. OR 조건을 사용하는 경우

주의 : 이 방식은 항상 full scan 으로 처리되므로 주의해야 한다


B. LIKE 연산지를사용하는 경우


인덱스 사용이 가능하지만 시용자가 :isu_cd 값을 입력하지 않았을 때  table  full Scan이 유리한데도 인덱스를 사용하게 되므로 성능이 나빠질 수 있다.



C. NVL 함수를 시용하는 경우




D. Decode 함수를 사용하는 경우


조건 칼럼이 NOT NULL 일 경우에만 사용 가능하다  NULL 허용일 경우 결과가 달라질 수 있다.
:isu_cd 가   없으면  isu_cd = isu_cd가 되는 데   null 인 경우 항상 false 이므로 null 인 레코드는 제외하고 결과가 리턴된다.

E. UNION ALL 을 사용하는 경우




null 값을 허용하고 인덱스 엑세스 조건이 의미있는 경우라면 union all  사용을 권장함.


'DBMS > SQL(쿼리튜닝)' 카테고리의 다른 글

함수 부하가 병목인 쿼리 튜팅  (0) 2018.08.04

세션 커서에서 커서를 찾은 비율, 즉 세션 커서 캐시 히트율(Hit Ratio) 을 구하는 쿼리


1. 쿼리

select a.value "session cursor cache hits"

                   , b.value "total parse call count"

                  , round (a.value/b.value* 100, 2) "session cursor cache hits%"

          from v$sysstat a, v$sysstat b

          where a.name = 'session cursor cache hits'

         and b.name = 'parse count (total)'



2. 결과

session cursor cache hits total parse call count session cursor cache hits%

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

                    88745                 115342                      76.94

1. 쿼리

SQL> set linesize 300

SQL> column TABLE_NAME format a30

SQL> column COMMENTS   format a30

SQL> select * from dict where table_name like 'DBA_HIST_SQL%';


2.결과

TABLE_NAME                     COMMENTS

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

DBA_HIST_SQLBIND               SQL Bind Information

DBA_HIST_SQLCOMMAND_NAME       Sql command types

DBA_HIST_SQLSTAT               SQL Historical Statistics Info

                               rmation


DBA_HIST_SQLTEXT               SQL Text

DBA_HIST_SQL_BIND_METADATA     SQL Bind Metadata Information

DBA_HIST_SQL_PLAN              SQL Plan Information

DBA_HIST_SQL_SUMMARY           Summary of SQL Statistics

DBA_HIST_SQL_WORKAREA_HSTGRM   SQL Workarea Histogram History


8 rows selected.


SQL>  select * from dict where table_name like 'DBA_ALL_%';


TABLE_NAME                     COMMENTS

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

DBA_ALL_TABLES                 Description of all object and

                               relational tables in the datab

                               ase



SQL> 

v$sql 의 값들은 누적치.

SQL 수행횟수로 나눈 평균값, SQL한번 수행당 얼만만큼의 일량과 시간을 소비하는 지 계산해야 의미 있는 분석이 가능함.



1. 스키마별 쿼리 수행 통계

select parsing_schema_name 

     , count(*) sql_cnt

     , count(distinct substr(sql_text, 1, 100)) sql_cnt2

     , sum(executions) executions

     , round(avg(buffer_gets/executions)) buffer_gets

     , round(avg(disk_reads/executions)) disk_reads

     , round(avg(rows_processed/executions)) rows_processed

     , round(avg(elapsed_time/executions/1000000),2) "ELAPSED_TIME(AVG)"

     , count(case when elapsed_time/executions/1000000 >= 10 then 1 end) "BAD SQL"

     , round(max(elapsed_time/executions/1000000),2) "ELAPSED_TIME(MAX)"

from   v$sql

where  last_active_time >= sysdate - 7

and    executions > 0

group by parsing_schema_name



2. 실행예




3. 개별쿼리별 조회

select 

         sql_id  , child_number , sql_text  , sql_fulltext   , parsing_schema_name      -- (1)

       , sharable_mem    , persistent_mem    , runtime_mem                             --(2)

       , loads    , invalidations    , parse_calls    , executions   , fetches   , rows_processed  --(3)

       , cpu_time   , elapsed_time                                                             -- (4)

       , buffer_gets   , disk_reads   , sorts                                                  -- (5)

       , application_wait_time , concurrency_wait_time                                    -- (6)

       , cluster_wait_time , user_io_wait_time                                               -- (6)

       , first_load_time , last_active_time                                                     --(7)

from v$sql;

1) 라이브러리 캐시에 적재된 SQL 커서 자체에 대한 정보

2) SQL 커서에 의해 사용되는 메모리 사용량

3) 하드파싱 및 무효화 발생횟수, Parse, Execute, Fetch Call 발생 횟수, Execute 또

는 Fetch Call 시점에 처리한 로우 건수 등

4) SQL을 수행하면서 사용된 CPU time과 소요시간(microsecond)

5) SQL을 수행하면서 발생한 논리적 블록 읽기와 디스크 읽기, 그리고 소트 발생 횟수

6) SQL 수행 도중 대기 이벤트 때문에 지연이 발생한 시간(microsecond)

7) 커서가 라이브러리 캐시에 처음 적재된 시점, 가장 마지막에 수행된 시점


$ORA_HOME/network/admin/listener.ora


LISTENER =

  (DESCRIPTION_LIST =

    (DESCRIPTION =

      (ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC1521))

      (ADDRESS = (PROTOCOL = TCP)(HOST = localhost)(PORT = 1521))

      (ADDRESS = (PROTOCOL = TCP)(HOST = 10.0.2.15)(PORT = 1521))

    )

  )


SID_LIST_LISTENER =

  (SID_LIST =

   (SID_DESC =

      (SID_NAME = PLSExtProc)

      (ORACLE_HOME = /oracle11/product/11.2.0/dbhome_1)

      (PROGRAM = extproc)

   )

   (SID_DESC =

      (GLOBAL_DBNAME = orcl11)

      (ORACLE_HOME = /oracle11/product/11.2.0/dbhome_1 )

      (SID_NAME = orcl11)

    )

  )



ADR_BASE_LISTENER = /oracle11



$ORA_HOME/network/admin/tnsnames.ora


ORCL11 =

  (DESCRIPTION =

    (ADDRESS_LIST =

      (ADDRESS = (PROTOCOL = TCP)(HOST = 10.0.2.15)(PORT = 1521))

      (ADDRESS = (PROTOCOL = TCP)(HOST = localhost)(PORT = 1521))

    )

    (CONNECT_DATA =

      (SERVER = DEDICATED)

      (SERVICE_NAME = orcl11)

    )

  )


LISTENER_ORCL11 =

 (ADDRESS_LIST =

   (ADDRESS = (PROTOCOL = TCP)(HOST = localhost)(PORT = 1521))

   (ADDRESS = (PROTOCOL = TCP)(HOST = 10.0.2.15)(PORT = 1521))

 )




/* runLoader.sh */


wait4loader()

{

while(true)

do

     CNT=`ps -ef | grep -v grep | grep -c loader`

    if [ $CNT -ge 16 ]; then     #  이미 지정된 갯수보다 더 많은  프로세스가 동시 실행중이면

          sleep 1;                    #   대기한다.   16= CPU core 수

    else

          break;                     # 적으면 다음 프로세스 추가 실횅을 위해서 loop를 빠져 나간다.

   fi


done


}



loaderTable(0

{

     if [ $TABLE != "X" ] ; then

         loader ... -T $TABLE

     fi


}


for  TABLE in ${TABLES[@]}

do

           TABLE=${TABLE:="X"}

           wait4loader

           loaderTable


done




http://blog.redjini.com/282  참고


배열선언

array_name_1=("value 1" "value 2" "value 3")

array_name_2=(1 2 3)



배열참조


array_name=("value 1" "value 2" "value 3")

 
echo "array_name[0]     = ${array_name[0]}"  #print array_name[0]
echo "array_name[2]     = ${array_name[2]}"  #print array_name[2]
echo "array_name[*]     = ${array_name[*]}"  #print array_name all item
echo "array_name[@]     = ${array_name[@]}"  #print array_name all item
echo "array_name index  = ${!array_name[@]}" #print array_name index number
echo "array_name size   = ${#array_name[@]}" #print array_name size
echo "array_name[0] size= ${#array_name[0]}" #print array_name[0] size



출력결과

array_name[0]     = value 1

array_name[2]     = value 3
array_name[*]     = value 1 value 2 value 3
array_name[@]     = value 1 value 2 value 3
array_name index  = 0 1 2
array_name size   = 3
array_name[0] size= 7



vim 을 통해서 shell 에서 문자열 치환도 가능하다.

문자열 치환시 정규표현식도 사용가능하다.

vim 에서 사용하는  기타 명령어 기술이 가능하다.



/* a.sh */

# 특정 문자열 라인 삭제

vim -e a.dat <<EOF

:g/\<JAEIK\>/d         <---  해당 라인 삭제

:g/\<Nara\>/d          <---- 해당 라인 삭제

:wq                           <--- 저장후 종료

EOF



#특정 문자열 교체후 다른 파일로 저장

TABLE="T1"

vim -e template.form <<EOF

:%s/#TABLE#/$TABLE/g     

:wq! newfile.form

EOF



'시스템 > Unix command' 카테고리의 다른 글

파일 검색방법 참고  (0) 2018.07.17
포트 스캔하는 명령  (0) 2018.07.14
od - 바이너리 파일 덤프  (0) 2018.07.01
rlwrap - readline 이 적용되지 않은 program 을 위한 wrapper  (0) 2018.04.27
vim 관련 정보  (0) 2018.04.08

sqlplus  에서 이전 명령어를 다시 실행할 때  편리하다.


rlwrap - readline 이 적용되지 않은 program 을 위한 wrapper




'시스템 > Unix command' 카테고리의 다른 글

파일 검색방법 참고  (0) 2018.07.17
포트 스캔하는 명령  (0) 2018.07.14
od - 바이너리 파일 덤프  (0) 2018.07.01
vim을 shell script에서 실행하는 방법  (0) 2018.04.27
vim 관련 정보  (0) 2018.04.08

+ Recent posts