Pages

To update the sal with exception

declare
vempno number(4);
vename varchar2(20);
vsal number;
begin
select empno,ename, sal into vempno,vename, vsal from emp
where empno=&empno;
if vsal<1000 then
update emp set sal=sal+sal*0.35
where empno=vempno;
end if;
dbms_output.put_line('the emp det are:'||vename||''||vsal);
exception
when no_data_found then
dbms_output.put_line('the empno is not exists');
end;

Load data from query to excel file in a procedure

Load data from query to excel file in a procedure
Please execute this code...you can get proper result ...

emp table date in one sheet...dept data in one sheet in one excel book.
First login as sysdba and create a direcotry..and grant the permissions to your schema..
Open your my computer icon .. in 'C' drive create a folder as test_dir.
Then run this script....!!
As sys user:
Create user defined directory

GRANT CREATE ANY DIRECTORY TO Scott;

CREATE OR REPLACE DIRECTORY TEST_DIR AS 'c:\myfiles' /* directory on the Oracle database server */
/
GRANT READ, WRITE ON DIRECTORY TEST_DIR TO myuser
/
As myuser:

DECLARE
v_fh UTL_FILE.FILE_TYPE;
v_dir VARCHAR2(30) := 'TEST_DIR';
v_file VARCHAR2(30) := 'myfile.xls';
PROCEDURE run_query(p_sql IN VARCHAR2) IS
v_v_val VARCHAR2(4000);
v_n_val NUMBER;
v_d_val DATE;
v_ret NUMBER;
c NUMBER;
d NUMBER;
col_cnt INTEGER;
f BOOLEAN;
rec_tab DBMS_SQL.DESC_TAB;
col_num NUMBER;

BEGIN
c := DBMS_SQL.OPEN_CURSOR;
-- parse the SQL statement
DBMS_SQL.PARSE(c, p_sql, DBMS_SQL.NATIVE);
-- start execution of the SQL statement
d := DBMS_SQL.EXECUTE(c);
-- get a description of the returned columns
DBMS_SQL.DESCRIBE_COLUMNS(c, col_cnt, rec_tab);

-- bind variables to columns

FOR j in 1..col_cnt
LOOP
CASE rec_tab(j).col_type
WHEN 1 THEN DBMS_SQL.DEFINE_COLUMN(c,j,v_v_val,4000);
WHEN 2 THEN DBMS_SQL.DEFINE_COLUMN(c,j,v_n_val);
WHEN 12 THEN DBMS_SQL.DEFINE_COLUMN(c,j,v_d_val);
ELSE
DBMS_SQL.DEFINE_COLUMN(c,j,v_v_val,4000);
END CASE;
END LOOP;

-- Output the column headers

UTL_FILE.PUT_LINE(v_fh,'');
FOR j in 1..col_cnt
LOOP
UTL_FILE.PUT_LINE(v_fh,'');
UTL_FILE.PUT_LINE(v_fh,''||rec_tab(j).col_name||'');
UTL_FILE.PUT_LINE(v_fh,'');
END LOOP;
UTL_FILE.PUT_LINE(v_fh,'');
-- Output the data
LOOP
v_ret := DBMS_SQL.FETCH_ROWS(c);
EXIT WHEN v_ret = 0;
UTL_FILE.PUT_LINE(v_fh,'');
FOR j in 1..col_cnt
LOOP
CASE rec_tab(j).col_type
WHEN 1 THEN DBMS_SQL.COLUMN_VALUE(c,j,v_v_val);
UTL_FILE.PUT_LINE(v_fh,'');
UTL_FILE.PUT_LINE(v_fh,''||v_v_val||'');
UTL_FILE.PUT_LINE(v_fh,'');
WHEN 2 THEN DBMS_SQL.COLUMN_VALUE(c,j,v_n_val);
UTL_FILE.PUT_LINE(v_fh,'');
UTL_FILE.PUT_LINE(v_fh,''||to_char(v_n_val)||'');
UTL_FILE.PUT_LINE(v_fh,'');
WHEN 12 THEN DBMS_SQL.COLUMN_VALUE(c,j,v_d_val);
UTL_FILE.PUT_LINE(v_fh,'');
UTL_FILE.PUT_LINE(v_fh,''||to_char(v_d_val,'YYYY-MM-DD"T"HH24:MI:SS')||'');
UTL_FILE.PUT_LINE(v_fh,'');
ELSE
DBMS_SQL.COLUMN_VALUE(c,j,v_v_val);
UTL_FILE.PUT_LINE(v_fh,'');
UTL_FILE.PUT_LINE(v_fh,''||v_v_val||'');
UTL_FILE.PUT_LINE(v_fh,'');
END CASE;
END LOOP;
UTL_FILE.PUT_LINE(v_fh,'');
END LOOP;
DBMS_SQL.CLOSE_CURSOR(c);
END;
--
PROCEDURE start_workbook IS
BEGIN
UTL_FILE.PUT_LINE(v_fh,'');
UTL_FILE.PUT_LINE(v_fh,'');
END;
PROCEDURE end_workbook IS
BEGIN
UTL_FILE.PUT_LINE(v_fh,'');
END;
--
PROCEDURE start_worksheet(p_sheetname IN VARCHAR2) IS
BEGIN
UTL_FILE.PUT_LINE(v_fh,'');
UTL_FILE.PUT_LINE(v_fh,'');
END;
PROCEDURE end_worksheet IS
BEGIN
UTL_FILE.PUT_LINE(v_fh,'');
UTL_FILE.PUT_LINE(v_fh,'');
END;
--
PROCEDURE set_date_style IS
BEGIN
UTL_FILE.PUT_LINE(v_fh,'');
UTL_FILE.PUT_LINE(v_fh,'');
UTL_FILE.PUT_LINE(v_fh,'');
UTL_FILE.PUT_LINE(v_fh,'');
UTL_FILE.PUT_LINE(v_fh,'');
END;
BEGIN
v_fh := UTL_FILE.FOPEN(upper(v_dir),v_file,'w',32767);
start_workbook;
set_date_style;
start_worksheet('EMP');
run_query('select * from emp');
end_worksheet;
start_worksheet('DEPT');
run_query('select * from dept');
end_worksheet;
end_workbook;
UTL_FILE.FCLOSE(v_fh);
END;

Daily use Unix Commands

Daily use Unix Commands


$uptime <-- To check the system uptime and we get to know that if its rebooted recently with other details.

ps -eaf | grep i<inode> <-- Fetch file using I node number.

ps -eaf | grep i check <-- to get the all inode numbers with file name in PWD.

topas <-To get the usage of  kernel ,cpu,user,idle.

at now <-- to start process manually right away

> <filenname> <-- to make file size as 0 byte or Zero byte .

df -gt . <--To find where the file is mounted on or where its located with file  system usage= Example like :/Home or /Shared.
 where . <-- current path

df -gt <file name or /P /CDW> <-- Directly fetch exact info(file permission,size,created date) file/Dir which u metioned  .

dsmc arch <File Name> <-- To takes bakup on TSM server.

chfs -a size=+10MB /home <--To add 10MB under /Home

ls -ltr <-- To get all list of files /Dir's with file size  in current path.

ls -ld <Dir> <--To get the exact dir.
-----------------------------
Mount unmount nfsmount
------------------------
echo $SHELL <-- Command to find the current shell.
================================================================
Chown:
For example, the following would transfer the ownership of a file named file1 and a directory named dir1 to a new owner named alice:

chown alice file1 dir1
===============================================
SCP Copy the file from SYSMGT04 to SYSMGT02:
$pwd
$sysmgt02
$ scp vrathth@sysmgt04:/home/vrathth/file1 /home/vrathth/
vrathth@sysmgt04's password:
file1                                         100%    0     0.0KB/s   00:00
$ls -l
file1
==================================================
$lscfg -v <-- list all the devices with model numbers

sysmgt04: /# getconf DISK_SIZE /dev/hdisk1
140013
sysmgt04: /# who -r <-- runlevel
   .        run-level 2 Dec  5 13:27       2    0    S
sysmgt04: /# lsdev -Pc tape <-- list tape devices

sysmgt04: /# getconf BOOT_DEVICE <-- boot device
hdisk0
==============================

Using the chgrp Command on a File
--------------------------------

# ls -l
total 12
-rw-rw-r– 1 tclark authors 2229 Jan 13 21:35 declaration.txt
-rw-rw-r– 1 tclark authors 1310 Jan 13 17:48 gettysburg.txt
-rw-rw-r– 1 tclark authors 360 Jan 13 17:48 preamble.txt
# chgrp presidents gettysburg.txt
# ls -l
total 12
-rw-rw-r– 1 tclark authors 2229 Jan 13 21:35 declaration.txt
-rw-rw-r– 1 tclark presidents 1310 Jan 13 17:48 gettysburg.txt
-rw-rw-r– 1 tclark authors 360 Jan 13 17:48 preamble.txt
======================================

Using the chgrp Command on a Directory
-------------------------------
# ls -l
total 4
-rw-rw-r– 1 tclark tclark 0 Jan 13 21:13 example1.fil
-rw-rw-r– 1 tclark tclark 0 Jan 13 21:13 example2.xxx
drwxrwxr-x 2 tclark tclark 4096 Jan 13 21:35 examples
# chgrp authors examples
# ls -l
total 4
-rw-rw-r– 1 tclark tclark 0 Jan 13 21:13 example1.fil
-rw-rw-r– 1 tclark tclark 0 Jan 13 21:13 example2.xxx
drwxrwxr-x 2 tclark authors 4096 Jan 13 21:35 examples

====================================
Change User Ownership
---------------------
The chown (change owner) command can be used to change ownership of a file or directory. The syntax is very similar to chgrp.

# ls -l
total 12
-rw-rw-r– 1 tclark authors 2229 Jan 13 21:35 declaration.txt
-rw-rw-r– 1 tclark authors 1310 Jan 13 17:48 gettysburg.txt
-rw-rw-r– 1 tclark authors 360 Jan 13 17:48 preamble.txt
# chown abe gettysburg.txt
# ls -l
total 12
-rw-rw-r– 1 tclark authors 2229 Jan 13 21:35 declaration.txt
-rw-rw-r– 1 abe authors 1310 Jan 13 17:48 gettysburg.txt
-rw-rw-r– 1 tclark authors 360 Jan 13 17:48 preamble.txt
===============================================
sysmgt04: /home/vdas9am/sample# ls -l <--copying data with file permission.
total 0
-rw-rw-r-x    1 root     system            0 Apr 23 01:00 b
-rw-------    1 root     system            0 Apr 23 01:14 c

sysmgt04: /home/vdas9am/sample# cp -p b c
sysmgt04: /home/vdas9am/sample# ls -l
total 0
-rw-rw-r-x    1 root     system            0 Apr 23 01:00 b
-rw-rw-r-x    1 root     system            0 Apr 23 01:00 c
===============================================
$istat mydir  <-- to see all the details abt dir.
$. <file/Dir> <-- to excute the file or dir or Shall (after . one speace should be there)
===========
etc/inittab
tsm:2:wait <--once it start after other related process will get start if its doesn't start other related process also won't
start.

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





What's the command to see the kernel version?

uname -r
uname -a <-- to see all information like machine model
uname -v <-- see OS version
------------------------------------------
When we create user then following files are edited

/etc/passwd

/etc/security/passwd

/etc/security/limits

/etc/security/user

/etc/security/.profile

/usr/lib/security/mkuser.default

/usr/lib/security/mkuser.sys

-------------------------------------------------
how to take backup in aix server


Best Rated Answer:

(1)For backup of rootvg, mksysb command can be used on command line or via smitty.

Advantage of mksysb is that it can create a 'bootable' media of the backup of rootvg.

(2) For backup of filesystems, 'backup' command can be used ( restore command to be used for restoration of the backup).

(3) The answer given regarding savevg ( and restvg ) is correct
-----------------------------------------------------
How will u create bosboot image (Except bosboot -ad /dev/diskname)?

Best Rated Answer:

There is also a command to create boot image

mkboot -c -d /dev/diskname
------------------------

SQL*PLUSCOMMNANDS



These commands does not require statement terminator and applicable to the sessions , those will be automatically cleared when session was closed.

BREAK

This will be used to breakup the data depending on the grouping.

Syntax:
            Break or bre [on <column_name> on report]
         
COMPUTE

This will be used to perform group functions on the data.

Syntax:
            Compute or comp [group_function of column_name on breaking_column_name or
                                            report]

TTITLE

This will give the top title for your report. You can on or off the ttitle.

Syntax:
            Ttitle or ttit [left | center | right] title_name  skip n other_characters
           Ttitle or ttit [on or off]

BTITLE

This will give the bottom title for your report. You can on or off the btitle.

Syntax:
            Btitle or btit [left | center | right] title_name  skip n other_characters
           Btitle or btit [on or off]
Ex:
            SQL> bre on deptno skip 1 on report
SQL> comp sum of sal on deptno
SQL> comp sum of sal on report
SQL> ttitle center 'EMPLOYEE DETAILS' skip1 center '----------------'
SQL> btitle center '** THANKQ **'
SQL> select * from emp order by deptno;

Output:

                                                      EMPLOYEE DETAILS
                                                    -----------------------

      EMPNO    ENAME    JOB              MGR     HIREDATE     SAL     COMM   DEPTNO
      ---------- ---------- ---------       -------  --------------  -------- ---------- ----------
      7782        CLARK   MANAGER     7839   09-JUN-81     2450                       10
      7839        KING     PRESIDENT              17-NOV-81    5000
      7934        MILLER CLERK           7782   23-JAN-82     1300
                                                                                          ----------            **********
                                                                                            8750                 sum

      7369        SMITH   CLERK           7902   17-DEC-80          800                    20
      7876        ADAMS  CLERK           7788   23-MAY-87       1100
      7902        FORD    ANALYST       7566   03-DEC-81        3000
      7788        SCOTT  ANALYST       7566   19-APR-87        3000
      7566        JONES  MANAGER      7839   02-APR-81        2975
                                                                                           ----------            **********
                                                                                             10875                 sum

      7499       ALLEN    SALESMAN    7698   20-FEB-81       1600        300         30
      7698       BLAKE    MANAGER     7839   01-MAY-81       2850
      7654       MARTIN SALESMAN    7698   28-SEP-81       1250       1400
      7900       JAMES    CLERK           7698   03-DEC-81         950
      7844       TURNER SALESMAN    7698   08-SEP-81       1500          0
      7521       WARD    SALESMAN    7698   22-FEB-81       1250        500
                                                                                         ----------             **********
                                                                                              9400                  sum
                                                                                         ----------
      sum                                                                               29025

                                                      ** THANKQ **

CLEAR

This will clear the existing buffers or break or computations or columns formatting.

Syntax:
            Clear or cle buffer | bre | comp | col;

Ex:
            SQL> clear buffer
        Buffer cleared
            SQL> clear bre
                   Breaks cleared
            SQL> clear comp
                   Computes cleared
            SQL> clear col
                   Columns cleared

CHANGE

This will be used to replace any strings in SQL statements.

Syntax:
              Change or c/old_string/new_string

If the old_string repeats many times then new_string replaces the first string only.

Ex:
                        SQL> select * from det;
select * from det
              *
ERROR at line 1:
ORA-00942: table or view does not exist

SQL> c/det/dept
  1* select * from dept
SQL> /

      DEPTNO  DNAME            LOC
     ---------- ---------------- -----------
        10        ACCOUNTING  NEW YORK
        20        RESEARCH       ALLAS
        30        SALES              CHICAGO
        40        OPERATIONS   BOSTON

COLUMN

This will be used to increase or decrease the width of the table columns.

Syntax:
            Column or col <column_name> format <num_format|text_format>

Ex:
            SQL> col deptno format 999
            SQL> col dname format a10

SAVE

This will be used to save your current SQL statement as SQL Script file.

Syntax:
             Save or sav <file_name>.[extension] replace or rep

If you want to save the filename with existing filename the you have to use replace option.
By default it will take sql as the extension.

Ex:
            SQL> save ss
        Created file ss.sql
            SQL> save ss replace
                  Wrote file ss.sql
           
EXECUTE

This will be used to execute stored subprograms or packaged subprograms.

Syntax:
            Execute or exec <subprogram_name>

Ex:
            SQL> exec sample_proc

SPOOL

This will record the data when you spool on, upto when you say spool off. By default it will give lst as extension.

Syntax:
            Spool on | off | out | <file_name>.[Extension]

Ex:
            SQL> spool on
SQL> select * from dept;

DEPTNO DNAME            LOC
--------- --------------   ----------
    10      ACCOUNTING  NEW YORK
    20      RESEARCH       DALLAS
    30      SALES              CHICAGO
    40      OPERATIONS   BOSTON

SQL> spool off
SQL> ed on.lst

SQL> select * from dept;

DEPTNO DNAME            LOC
--------- --------------   ----------
    10      ACCOUNTING  NEW YORK
    20      RESEARCH       DALLAS
    30      SALES              CHICAGO
    40      OPERATIONS   BOSTON

SQL> spool off

LIST

This will give the current SQL statement.

Syntax:
            List or li [start_line_number] [end_line_number]

Ex:
            SQL> select
                2  *
                3  from
                4  dept;
SQL> list
               1  select
               2  *
               3  from
               4* dept
SQL> list 1
               1* select
SQL> list 3
             3* from

SQL> list 1 3
             1  select
             2  *
             3* from
           
INPUT

This will insert the new line to the current SQL statement.

Syntax:
            Input or in <string>

Ex:
            SQL> select *
            SQL> list
  1* select *
SQL> input from dept
SQL> list
  1  select *
  2* from dept         

APPEND

This will adds a new string to the existing string in the SQL statement without any space.

Syntax:
            Append or app <string>

Ex:
            SQL> select *
SQL> list
  1* select *
SQL> append  from dept
  1* select * from dept
SQL> list
  1* select * from dept

DELETE

This will delete the current SQL statement lines.

Syntax:
            Delete or del <start_line_number> [<end_line_number>]

Ex:
            SQL> select
    2  *
    3  from
    4  dept
    5  where
    6  deptno
    7  >10;
SQL> list
   1  select
   2  *
   3  from
   4  dept
   5  where
   6  deptno
   7* >10
SQL> del 1
SQL> list
   1  *
   2  from
   3  dept
   4  where
   5  deptno
   6* >10
SQL> del 2
SQL> list
   1  *
   2  dept
   3  where
   4  deptno
   5* >10
SQL> del 2 4
SQL> list
   1  *
   2* >10
SQL> del
SQL> list
   1  *

VARIABLE

This will be used to declare a variable.

Syntax:
            Variable or var <variable_name> <variable_type>

Ex:
            SQL> var  dept_name varchar(15)
            SQL> select dname into dept_name from dept where deptno = 10;

PRINT

This will be used to print the output of the variables that will be declared at SQL level.

Syntax:
            Print <variable_name>

Ex:
            SQL> print dept_name

                        DEPT_NAME
                        --------------
                        ACCOUNTING

START

This will be used to execute SQL scripts.

Syntax:
            start <filename_name>.sql

Ex:
SQL> start ss.sql
SQL> @ss.sql             -- this will execute sql script files only.

HOST

This will be used to interact with the OS level from SQL.

Syntax:
            Host [operation]

Ex:
SQL> host
SQL> host dir

SHOW

Using this, you can see several commands that use the set command and status.

Syntax:
            Show all | <set_command>

Ex:
SQL> show all
appinfo is OFF and set to "SQL*Plus"
arraysize 15
autocommit OFF
autoprint OFF
autorecovery OFF
autotrace OFF
blockterminator "." (hex 2e)
btitle OFF and is the first few characters of the next SELECT statement
cmdsep OFF
colsep " "
compatibility version NATIVE
concat "." (hex 2e)
copycommit 0
COPYTYPECHECK is ON
define "&" (hex 26)
describe DEPTH 1 LINENUM OFF INDENT ON
echo OFF
editfile "afiedt.buf"
embedded OFF
escape OFF
FEEDBACK ON for 6 or more rows
flagger OFF
flush ON

SQL> sho verify
verify OFF

RUN

This will runs the command in the buffer.

Syntax:
Run | /

Ex:
SQL> run
SQL> /
STORE

This will save all the set command statuses in a file.

Syntax:
Store set <filename>.[extension] [create] | [replace] | [append]

Ex:
SQL> store set my_settings.scmd
Created file my_settings.scmd
SQL> store set my_settings.cmd replace
Wrote file my_settings.cmd
SQL> store set my_settings.cmd append
Appended file to my_settings.cmd

FOLD_AFTER

This will fold the columns one after the other.

Syntax:
Column <column_name> fold_after [no_of_lines]

Ex:
SQL> col deptno fold_after 1
SQL> col dname fold_after 1
SQL> col loc fold_after 1
SQL> set heading off
SQL> select * from dept;

        10
ACCOUNTING
NEW YORK

        20
RESEARCH
DALLAS
        30
SALES
CHICAGO

        40
OPERATIONS
BOSTON

FOLD_BEFORE

This will fold the columns one before the other.

Syntax:
Column <column_name> fold_before [no_of_lines]

DEFINE

This will give the list of all the variables currently defined.

Syntax:
Define [variable_name]

Ex:
SQL> define
DEFINE _DATE           = "16-MAY-07" (CHAR)
DEFINE _CONNECT_IDENTIFIER = "oracle" (CHAR)
DEFINE _USER           = "SCOTT" (CHAR)
DEFINE _PRIVILEGE      = "" (CHAR)
DEFINE _SQLPLUS_RELEASE = "1001000200" (CHAR)
DEFINE _EDITOR         = "Notepad" (CHAR)
DEFINE _O_VERSION      = "Oracle Database 10g Enterprise Edition Release
                                              10.1.0.2.0 – Production With the Partitioning, OLAP and
                                              Data Mining options" (CHAR)
DEFINE _O_RELEASE      = "1001000200" (CHAR)