[Oracle Database] - Oracle Database A->Z
Oracle Database Concept/Installation
Each database has a different concept and we should know that and it helps easy to organize, manage also easy to choose an accordant RMS for your system.
Oracle Instance and database |
Database Storage Structure
* Physical Storage Structure:
Data files > Control File > Online redo log file
- Data files: Oracle DB has one or more physical data files.
- Control File: Contain metadata specifying the physical structure of the database included database name, the names, and location of the database file.
- Online redo log file: is made up of redo entries, which record all changes made to data.
* Logical Storage Structure:
Data blocks > Extents > Segments > Tablespaces.
- Data blocks: data stored in data blocked. 1 data block correspond number byte on disk.
- Extents: An extent is a specific number of logically contiguous data blocks, obtained in a single allocation, used to store a specific type of information.
- Segments: A segment is a set of extents allocated for a user object (for example, a table or index), undo data, or temporary data.
- Tablespaces: A database is divided into logical storage units called tablespaces. A tablespace is a logical container for a segment. Each tablespace contains at least one data file.
Oracle Database 11c
* Data Type
+ Character
char(s), nchar(s)
varchar2(s), nvarchar2(s)
+ Number (p is the precision and s is the scale)
number(p,s): p = 1 to 38, s = -84 to 124
+BOOLEAN : NULL, TRUE, FALSE
<var1> BOOLEAN; //declare with null
<var2> BOOLEAN NOT NULL := TRUE;
<var3> BOOLEAN NOT NULL := FALSE;
Ex:
department_id number(10), department_name varchar2(50) NOT NULL,
Ref: https://www.techonthenet.com/oracle/datatypes.php
========================================================================
INDEX
An index is an optional structure, associated with a table or table cluster, that can sometimes speed data access.
Create index:
CREATE INDEX <INDEX_NAME> ON <TABLE> (COLUMN1, COLUMN2,...);Ex:
CREATE INDEX members_last_name_i
ON members(last_name);
Type of Indexes
B-tree indexes
B-trees, short for balanced trees. B-tree index is an ordered list of values divided into ranges.B-Tree has 2 types: Branch Blocks and Leaf Block.
- Branch Blocks: for searching
- Leaf Block: for store values.
========================================================================
Source:
https://docs.oracle.com/cd/E11882_01/server.112/e40540/intro.htm#CNCPT914
========================================================================
Create Synonym
CREATE SYNONYM <NAME> ON FOR schema.object;Ex:
RMAN tool
$ORACLE_HOME/bin
.Other
1. Show table structure/columnsdescribe <table_name>; // in SQL Plus
DESC <table_name>;
alter tablespace USERS add datafile '+DATA' size 100M autoextend on;
set lin 250col name format a10col USABLE_FILE_GB format 999,999.00col TOTAL_GB format 999,999.00col FREE_GB format 999,999.00col USABLE_CALC_GB format 999,999.00select name, USABLE_FILE_MB/1024 USABLE_FILE_GB, total_mb/1024 TOTAL_GB, free_mb/1024 FREE_GB, 100-round(free_mb/total_mb*100) "usgae(%)", ((FREE_MB - REQUIRED_MIRROR_FREE_MB))/1024 USABLE_CALC_GB, state, type, group_numberfrom v$asm_diskgroup;
show parameter DB_RECOVERY_FILE_DEST_SIZE;
alter system set DB_RECOVERY_FILE_DEST_SIZE = 300G SCOPE=BOTH SID='*';
SELECT session_key, input_type, status, start_time, end_time, elapsed_seconds/3600 hrsFROM v$rman_backup_job_details;
SQL> archive log list;
Oracle: select * from table where rownum <= 2;
SQL Server: select top 200 * from table;
MySql: select * from table where condition limit 20;
//ora-00937: not a single-group group function
SELECT CUS_NAME, MAX(AGE)
FROM CUSTOMER;
// CORRECT
SELECT CUS_NAME, MAX(AGE)
FROM CUSTOMER
GROUP BY CUS_NAME;
SQL
Select *From dual aWhere trunc(a.reg_dt) = trunc(current_date)
//MB
Select (sum(bytes)/1024/1024) Space_allocatedfrom dba_data_fileswhere tablespace_name=upper('&tname');
//GBSelect (sum(bytes)/1024/1024/1024) Space_allocatedfrom dba_data_fileswhere tablespace_name=upper('&tname');
Comments[ 0 ]
Post a Comment