15 Ekim 2014 Çarşamba

AS OF TIMESTAMP

This is a very useful sql code to retrieve older data which is deleted.

sys.sample_table is a custom table created by sys user.


select *
from sys.sample_table as of timestamp (systimestamp - interval '10' minute);

select *
from sys.sample_table as of timestamp (systimestamp - interval '10' day);


select *
from sys.sample_table as of timestamp (sysdate -1);     -- 1 day ago 

select *
from sys.sample_table as of timestamp (sysdate - 1/24);   --1 hour ago

select *
from sys.sample_table as of timestamp (sysdate -1/(24*60));     -- 1 minute ago

select *
from sys.sample_table as of timestamp (sysdate - 1/(24*60*60));  --1 second ago



It is also good to see result by testing with these sql below and how it works;

select sysdate , (sysdate + 1)  from dual;  -- 1 day later

select sysdate, (sysdate + 1/24) from dual; --1 hour later

select sysdate, (sysdate + 1/(24*60)) from dual; --1 minute later

select sysdate, (sysdate + 1/(24*60*60)) from dual; --1 second later




There are also two different errors prompted while using 




1-)There is one day difference between these two select statements. What causes these two different errors?

select * 
from sys.sample_table as of timestamp (systimestamp - interval '5' day);

ORA - 01466

select *
from from sys.sample_table as of timestamp (systimestamp - interval '6' day);

ORA - 08180



HOW TO MOVE A TABLE FROM ONE TABLESPACE TO ANOTHER

Let's explain this with an scenerio sample.Here are the steps,

1-)Create a table with sys dba privileges.
2-)Create an index on this table.
3-)Add some constraints on table.
4-)Check which tablespace this table and index belongs to.
5-)Move table from one tablespace from one to another
6-)Insert data to table after moving tablespace and investigate reaction of select statement.



1-)

,


2-)



3-) It is also possible to do these constraints while creating table




4-)

 Retrieved data;




5-)


6-)The first two insert statements before changing table's tablespace

Retrieved data;

The last  insert statement after changing table's tablespace from SYSTEM to XXXT.


Error after changing only table's tablespace;




As seen on scenerio above, If there is an index created on table,it is a must to change that indexes' tablespace too. Index remained at its last block. So need to change it;








                                                                   Just leave yourself on way and walk,the way will appear.







14 Ekim 2014 Salı

HOW TO RESIZE OR ADD TABLESPACE SIZE ?


How to resize an existing tablespace datafile;

alter database
datafile  '<datafile_path/data_file_name>'
resize 150M;

For example;

alter database
datafile '/ora_data/PROD/proddata/xxxt06.dbf'
resize 150M;


How to add a new datafile on partition for an existing tablespace;

alter tablespace
<tablespace_name>
add datafile '<datafile_path/data_file_name>'
size 200M
autoextend on;

For example;

alter tablespace 
xxxt
add datafile '/ora_data/PROD/proddata/xxxt07.dbf'
size 500M
autoextend off;

I have also added  'autoextend on/off' option which is useful.It will manage automatically extending datafile's size.

To see also tablespace autospace management;

select tablespace_name,segment_space_management
from dba_tablespace;

WHICH TABLESPACE BELONGS TO WHICH DATAFILE?


It is possible to see in two ways;

1-)select *
    from dba_data_files;


2-)select df.name,ta.name
    from v$datafile df,v$tablespace ta
    where df.ts#=ta.ts#; 


Data dictionary stuffs.



9 Ekim 2014 Perşembe

GET_HOST_NAME,GET_HOST_ADDRESS

These sql codes below provides us to see our instance's database's host name and host address.

1-)Press F5 to see script output.


2-)Other possible use of utl_inaddr.get_host_name and utl_address.get_host_address


1 Ekim 2014 Çarşamba

CASCADE

drop user USER_NAME cascade;

It also drops the objects created by user,if you do not write cascade it will prompt  ORA-01922 error.

25 Eylül 2014 Perşembe

REMAINDER FUNCTION,MOD FUNCTION

Remainder function does the same job with mod.
But valid for 10g,11g,12c

Mod function is valid for 8i,9i,10g,11g,12c database versions.

Some repetittions;

select abs(-10) from dual;

10

select ceil(1.3) from dual;

2

select floor(1.3) from dual;

1

select power(3,2) from dual;

9

select round(22.5) from dual;

23

select round (-22.5) from dual;

-23

select sign(-30) from dual;

-