Search This Blog

Total Pageviews

Monday, 7 November 2011

ARCHIVE LOG START is DEPRECATED in Oracle 11g

ARCHIVE LOG START is not valid in Oracle 11g
ARCHIVE LOG START




SQL> archive log list
Database log mode Archive Mode
Automatic archival Enabled
Archive destination /opt/app/oracle/admin/arch
Oldest online log sequence 79
Next log sequence to archive 81
Current log sequence 81

SQL>
SQL> !mkdir -p /opt/app/oracle/admin/arch1

SQL> !ls -ltr /opt/app/oracle/admin/arch1
total 0

SQL> ARCHIVE LOG START '/opt/app/oracle/admin/arch1' ; ----- will not do any thing in Oracle 11g
Statement processed.


SQL> !ls -ltr /opt/app/oracle/admin/arch1
total 0




SQL> ALTER SYSTEM SET log_archive_dest ='/opt/app/oracle/admin/arch1' ;

System altered.



SQL> !ls -ltr /opt/app/oracle/admin/arch1
total 4
-rw-r----- 1 oracle oinstall 2560 2011-11-07 14:19 1_83_757353423.dbf

Oracle Table detail info

Table detail info



set echo off term on
accept 2 prompt "Enter the name of the Table: "
accept 1 prompt "Enter table owner: "
set heading on newpage 0
ttitle 'Table Description - Space Definition'

btitle off
column Nline newline
set pagesize 54
set linesize 78
set heading off embedded off verify off

-- set term off

set embedded on heading on

column Ts format a20
column Ta format a20
column Clu format a20
column Pcf format 99999999999990
column Pcu format 99999999999990
column Int format 99,999,999,990
column Mat format 99,999,999,990
column Inx format 99,999,999,990
column Nxt format 99,999,999,990
column Mix format 99,999,999,990
column Max format 99,999,999,990
column Pci format 99999999999990
column Num format 99,999,999,990
column Blo format 99,999,999,990
column Emp format 99,999,999,990
column Avg format 99,999,999,990
column Cha format 99,999,999,990
column Rln format 99,999,999,990
column Hdg format a30 newline
set heading off
select 'Table Name' Hdg, Table_Name Ta,
'Tablespace Name' Hdg, Tablespace_Name Ts,
'Cluster Name' Hdg, Cluster_Name Clu,
'% Free' Hdg, Pct_Free Pcf,
'% Used' Hdg, Pct_Used Pcu,
'Ini Trans' Hdg, Ini_Trans Int,
'Max Trans' Hdg, Max_Trans Mat,
'Initial Extent (K)' Hdg, Initial_Extent/1024 Inx,
'Next Extent (K)' Hdg, Next_Extent/1024 Nxt,
'Min Extents' Hdg, Min_Extents Mix,
'Max Extents' Hdg, Max_Extents Max,
'% Increase' Hdg, Pct_Increase Pci,
'Number of Rows' Hdg, Num_Rows Num,
'Number of Blocks' Hdg, Blocks Blo,
'Number of Empty Blocks' Hdg, Empty_Blocks Emp,
'Average Space' Hdg, Avg_Space Avg,
'Chain Count' Hdg, Chain_Cnt Cha,
'Average Row Length' Hdg, Avg_Row_len Rln,
'Last Analyzed' Hdg, Last_Analyzed La
from DBA_TABLES
where Table_Name=UPPER('&&2')
and Owner=UPPER('&&1')
/
set heading on
set embedded off
column Cn format a30 heading 'Column Name'
column Fo format a15 heading 'Type'
column Nu format a8 heading 'Null'
-- column Nds format 99,999,999 heading 'No Distinct'
-- column Dfl format 99 heading 'Dflt Len'
column Dfv format a12 heading 'Default Val'
ttitle 'Table Description - Column Definition'
select Column_Name Cn,
Data_Type ||
DECODE(Data_Type,
'NUMBER',
'('||TO_CHAR(Data_Precision)||
DECODE(Data_Scale,0,'',','||
TO_CHAR(Data_Scale))||')',
'VARCHAR2',
'('||TO_CHAR(Data_Length)||')',
'CHAR',
'('||TO_CHAR(Data_Length)||')',
'DATE','',
'LONG','',
'Error') Fo,
DECODE(Nullable,'Y','','NOT NULL') Nu,
Data_Default Dfv
from DBA_TAB_COLUMNS
where Table_Name=UPPER('&&2')
and Owner=UPPER('&&1')
order by Column_ID
/

ttitle off
prompt
prompt TABLE CONSTRAINTS
prompt
set heading on
column Cn format a20 heading 'Primary Constraint'
column Cln format a20 heading 'Table.Column Name'
column Ct format a7 heading 'Type'
column St format a7 heading 'Status'
column Ro format a20 heading 'Ref Owner|Constraint Name'
column Se format a70 heading 'Criteria ' newline
break on Cn on St
set embedded on
prompt Primary Key
prompt
select CNS.Constraint_Name Cn,
CNS.Table_Name||'.'||CLS.Column_Name Cln,
INITCAP(CNS.Status) St
from DBA_CONSTRAINTS CNS,
DBA_CONS_COLUMNS CLS
where CNS.Table_Name=UPPER('&&2')
and CNS.Owner=UPPER('&&1')
and CNS.Constraint_Type='P'
and CNS.Constraint_Name=CLS.Constraint_Name
order by CLS.Position
/
prompt Unique Key
prompt
column Cn format a30 heading 'Unique Key'
select CNS.Constraint_Name Cn,
CNS.Table_Name||'.'||CLS.Column_Name Cln,
INITCAP(CNS.Status) St
from DBA_CONSTRAINTS CNS,
DBA_CONS_COLUMNS CLS
where CNS.Table_Name=UPPER('&&2')
and CNS.Owner=UPPER('&&1')
and CNS.Constraint_Type='U'
and CNS.Constraint_Name=CLS.Constraint_Name
order by CLS.Position
/
prompt Foreign Keys
prompt
column Cln format a18 heading 'Foreign Key' newline
column Clfn format a18 heading 'Parent Key'
column Cn format a40 heading 'Foreign Constraint'
break on Cn on St skip 1
select CNS.Constraint_Name Cn,
INITCAP(CNS.Status) St,
CLS.Table_Name||'.'||CLS.Column_Name Cln,
CLF.Owner||'.'||CLF.Table_Name||'.'||CLF.Column_Name Clfn
from DBA_CONSTRAINTS CNS,
DBA_CONS_COLUMNS CLF,
DBA_CONS_COLUMNS CLS
where CNS.Table_Name=UPPER('&&2')
and CNS.Owner=UPPER('&&1')
and CNS.Constraint_Type='R'
and CNS.Constraint_Name=CLS.Constraint_Name
and CLF.Constraint_Name = CNS.R_Constraint_Name
and CLF.Owner = CNS.Owner
and CLF.Position = CLS.Position
order by CNS.Constraint_Name, CLS.Position
/
prompt Check Constraints
prompt
column Cn format a40 heading 'Check Constraint'
column Se format a75 heading 'Criteria'
set arraysize 1
set long 32000
select Constraint_Name Cn,
INITCAP(Status) St,
Search_Condition Se
from DBA_CONSTRAINTS
where Table_Name=UPPER('&&2')
and Owner=UPPER('&&1')
and Constraint_Type='C'
/
prompt View Constraints
column Cn format a40 heading 'View Constraint'
select Constraint_Name Cn,
INITCAP(Status) St,
Search_Condition Se
from DBA_CONSTRAINTS
where Table_Name=UPPER('&&2')
and Owner=UPPER('&&1')
and Constraint_Type='V'
/
set arraysize 30
















SQL> @tab1
Enter the name of the Table: EMP
Enter table owner: SCOTT
Table Name EMP
Tablespace Name USERS
Cluster Name
% Free 10
% Used
Ini Trans 1
Max Trans 255
Initial Extent (K) 64
Next Extent (K) 1,024
Min Extents 1
Max Extents 2,147,483,645
% Increase
Number of Rows 14
Number of Blocks 4
Number of Empty Blocks 0
Average Space 0
Chain Count 0
Average Row Length 38
Last Analyzed 15-OCT-11


1 row selected.


Mon Nov 07 page 1
Table Description - Column Definition

Column Name Type Null Default Val
------------------------------ --------------- -------- ------------
EMPNO NUMBER(4) NOT NULL
ENAME VARCHAR2(10)
JOB VARCHAR2(9)
MGR NUMBER(4)
HIREDATE DATE
SAL NUMBER(7,2)
COMM NUMBER(7,2)
DEPTNO NUMBER(2)

8 rows selected.


TABLE CONSTRAINTS

Primary Key

Primary Constraint
--------------------
Table.Column Name Status
-------------------- -------
SYS_C0022543
EMP.EMPNO Enabled


1 row selected.

Unique Key


no rows selected

Foreign Keys


no rows selected

Check Constraints


no rows selected

View Constraints

no rows selected

Oracle re Create table with max length

dynamic plsql example






set serverout on
set feedback off
set verify off

accept v_table prompt 'enter table name : '

declare

type r_c is ref cursor;
c_ref r_c;
v_cname col.cname%type;
t_table varchar2(30);
v_table varchar2(30);
t_command varchar2(200);
t_cid integer;
t_val number(10);
stat integer;
row_count integer;
tot_rows number;
tot_col number;

begin

t_table := '&v_table';
open c_ref for select cname from col where tname=t_table ;
select count(*) into tot_col from col where tname=t_table ;
dbms_output.put_line(' . ');
dbms_output.put_line(' . ');
dbms_output.put_line(' . ');
dbms_output.put_line(' ');

dbms_output.put('select ');

loop
fetch c_ref into v_cname;
exit when c_ref%NOTFOUND;
tot_rows:= c_ref%ROWCOUNT;

t_command := 'select max(length("'||v_cname|| '")) from &v_table';
t_cid := DBMS_SQL.OPEN_CURSOR;
DBMS_SQL.PARSE(t_cid,t_command,dbms_sql.native);
DBMS_SQL.DEFINE_COLUMN(t_cid,1,t_val);
stat := DBMS_SQL.EXECUTE(t_cid);
row_count := DBMS_SQL.FETCH_ROWS(t_cid);
DBMS_SQL.COLUMN_VALUE(t_cid,1,t_val);

if t_val is null then
t_val := 1;
end if;

dbms_output.put('substr('||v_cname||',1,'||t_val||') ' ||v_cname );
if tot_rows < tot_col then
dbms_output.put_line(' ,' );
else
dbms_output.put_line(' from "'||t_table||'"' );
end if;

end loop;
close c_ref;

dbms_output.put_line(' . ');
dbms_output.put_line(' . ');
dbms_output.put_line(' . ');
end;
/
undefine t
set feedback on
set verify on



SQL> @tab
enter table name : EMP
.
.
.
select substr(EMPNO,1,4) EMPNO ,
substr(ENAME,1,6) ENAME ,
substr(JOB,1,9) JOB ,
substr(MGR,1,4) MGR ,
substr(HIREDATE,1,9) HIREDATE ,
substr(SAL,1,4) SAL ,
substr(COMM,1,4) COMM ,
substr(DEPTNO,1,2) DEPTNO from "EMP"

Oracle DBA

anuj blog Archive