0% found this document useful (0 votes)
9 views10 pages

Y24 Week4 A.2 Data Dictionary

Uploaded by

msci.2303
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views10 pages

Y24 Week4 A.2 Data Dictionary

Uploaded by

msci.2303
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 10

Data Dictionary

– Central to every Oracle database


– Describes the database and its objects
– Contains read-only tables and views
– Stored in the SYSTEM tablespace
– Owned by the user SYS
– Maintained by the Oracle server
– Accessed with SELECT

The data dictionary provides information about:


– Logical and physical database structures; Definitions and space allocations of
objects
– Integrity constraints; Users; Roles; Privileges; Auditing Information

Oracle server modifies it when a DDL statement is executed.


– Users and DBAs use it as a read-only reference for information about the
database.
1
Data Dictionary View Categories
– Three sets of static views
– Distinguished by their scope:
 DBA: In all the schemas
 ALL: What the user can access
 USER: In the user’s schema

DBA_xxx All of the objects in the database

ALL_xxx Objects accessible by the current user

USER_xxx Objects owned by the current user

2
Data Dictionary
• User-friendly views are available
– e.g. USER_TABLES
• One row for every table in your schema

• More than 1200 data dictionary views


– Static views, e.g. USER_TABLES
– Dynamic views, e.g. V$NLS_PARAMETERS - monitor ongoing activity

Select table_name from dict;


Select * from dict where table_name=‘ ‘;
desc tabs;
desc user_tables;

3
Querying the data dictionary…contd
Prefix Scope
USER User’s view (what is in the user’s schema)
ALL Expanded user’s view (what the user can access)
DBA Database administrator’s view (what is in all users’ schemas)
“USER_TABLES”, is a view on the data dictionary
contains one row for every table owned by you (i.e. created in your schema).
DESC user_tables ^C
SELECT table_name, num_rows from user_tables;
SELECT owner, object_name, object_type FROM ALL_OBJECTS;
Select distinct owner from all_objects;
SELECT owner, table_name FROM all_tables WHERE owner=‘yma'

select table_name from dict where table_name like 'V$N%';


There are hundreds of data dictionary tables and views.
The views are built on underlying base tables such as SYS.TAB$.
However, the underlying tables such as SYS.TAB$ are difficult to use,
not documented and column names are not intuitive.

Execute the DESCRIBE command on V$NLS_PARAMETERS


4
Querying Oracle Data Dictionary
SQL> desc dict;
SQL>select table_name from dict;
SQL>desc all_all_tables;
SQL>select table_name from all_all_tables where owner=‘YMA’;
SQL>select table_name from user_tables where owner=‘YMA’; error

SQL> select table-name,comments from dictionary


where table-name like ‘DBA_TAB%’

SQL>desc dba_tables;
SQL> select owner,table_name from dba_tables (user_tables;all_tables)
where tablespace_name =‘USERS’

SQL> desc all_users  column is username (see the data)


SQL>desc user_tables
SQL>select table_name from user_tables; [tabs]

5
DML – Familiarize with Data Dictionary
 Find the name of the table that contains tablespace information for users;
SQL>select * from dict where table_name like 'USER_T%';
Find the names of tablespaces in the user tablespace table.
SQL> select tablespace_name from USER_TABLESPACES;

Can you create a tablespace? Try the create tablespace command

CREATE TABLESPACE userdata


DATAFILE 'data01.dbf' SIZE 50M;

Find all the schema objects you have created


List only tables created by you
List only objects created by you from the all_objects table
List view tables starting with V$
 Look for the table V$NLS_Parameters

List all constraints with table name on which they are created - created by you
Oracle - SQL
• Checking the Date Format
select value from V$NLS_Parameters
where parameter=‘NLS_DATE_FORMAT’

• Setting the Date Format


alter session set NLS_DATE_FORMAT=‘dd-mm-yy’

• Setting Locality
alter session set NLS_TERRITORY=‘India’

select value from V$NLS_Parameters


where parameter=‘NLS_CURRENCY’
Date format
• To view current date and its format
SELECT sysdate FROM dual;

• To change the standard date format to ‘YYYY-MM-DD’


ALTER SESSION SET NLS_DATE_FORMAT = 'YYYY-MM-DD';

• Format output using TO_CHAR() function


SELECT TO_CHAR( SYSDATE, 'Month DD, YYYY' ) FROM dual;
select to_char(sysdate,'YEAR DAY, MONTH') FROM DUAL;

SELECT TO_CHAR( '2-10-1966', 'Month DD, YYYY' ) FROM dual;


error

SELECT TO_CHAR( to_date('2-10-1966'), 'Month DD, YYYY' ) FROM dual;


SELECT TO_CHAR( to_date('22-10-1966'), 'Month DD, YYYY' ) FROM dual;
Date format
SELECT TO_CHAR( to_date('22-10-66'), 'Month DD, YYYY' )
FROM dual;
 Changes year to current century

SELECT value FROM V$NLS_PARAMETERS WHERE


parameter = 'NLS_DATE_LANGUAGE';

ALTER SESSION SET NLS_DATE_LANGUAGE = 'FRENCH';


select sysdate from dual;

select to_char(sysdate,'MONTH DD, YYYY') FROM DUAL;


Date datatype-
• Convert string to date
Because Oracle uses an internal format for storing the DATE data, you often
have to convert a string to a date value before storing it in the date column.

• Change format of date


ALTER SESSION SET NLS_DATE_FORMAT = 'YYYY-Month-DD';

• Using date ‘yyyy-mm-dd’


select date '2020-09-22' from dual;

insert into tablename values(date '2020-09-22');

insert into tablename values(to_date('09-22-2020','mm-dd-yyyy'));


insert into adate values('b',to_date('14-10-2020','mm-dd-yyyy')); invalid
month

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy