0% found this document useful (0 votes)
56 views

Dba TP1

The document contains SQL commands and queries run against an Oracle database. It connects as different users, queries data dictionary views to get metadata on tables, columns and sessions. Procedures are created to display table and column names. Counts of tables are retrieved for different schema. The document shows basic SQL operations like connecting, querying, creating procedures etc.

Uploaded by

Fares Lamloum
Copyright
© © All Rights Reserved
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
56 views

Dba TP1

The document contains SQL commands and queries run against an Oracle database. It connects as different users, queries data dictionary views to get metadata on tables, columns and sessions. Procedures are created to display table and column names. Counts of tables are retrieved for different schema. The document shows basic SQL operations like connecting, querying, creating procedures etc.

Uploaded by

Fares Lamloum
Copyright
© © All Rights Reserved
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 4

SQL> connect sys/as sysdba

//SQL> alter user hr identified by hr account unlock; acces au HR


//SQL> show user; show current user
SQL> SELECT * FROM dictionary order by table_name; //dict
SQL> describe dba_users;

SQL> select count(*) from v$session;


COUNT(*)
----------
15
SQL> select username,type from v$session;
USERNAME TYPE
------------------------------ ----------
SYS USER
BACKGROUND
BACKGROUND
BACKGROUND
BACKGROUND
BACKGROUND
SQL> desc v$sga
Nom NULL ? Type
----------------------------------------------------- --------
------------------------------------
NAME VARCHAR2(20)
VALUE
SQL> select * from v$sga;
SQL> select sum(value) from v$sga;
SQL> select sum(value) from v$sga;

SQL> connect hr/hr


SQL> select * from user_objects;

SQL> select object_type,count(*) from user_objects group by object_type;

OBJECT_TYPE COUNT(*)
------------------- ----------
SEQUENCE 3
PROCEDURE 2
TRIGGER 2
TABLE 7
INDEX 19
VIEW 1

SQL> select object_type,count(*) from user_objects group by rollup(object_type);

OBJECT_TYPE COUNT(*)
------------------- ----------
INDEX 19
PROCEDURE 2
SEQUENCE 3
TABLE 7
TRIGGER 2
VIEW 1
34

SQL> select object_name from user_objects where object_type='TABLE';


OBJECT_NAME
-----------------------------------------------------------------------------------
-----------------
REGIONS
COUNTRIES
LOCATIONS
DEPARTMENTS
JOBS
EMPLOYEES
JOB_HISTORY

SQL> purge recyclebin;

SQL> desc user_objects;


Nom NULL ? Type
----------------------------------------------------- --------
------------------------------------
OBJECT_NAME VARCHAR2(128)
SUBOBJECT_NAME VARCHAR2(30)
OBJECT_ID NUMBER
DATA_OBJECT_ID NUMBER
OBJECT_TYPE VARCHAR2(19)
CREATED DATE
LAST_DDL_TIME DATE
TIMESTAMP VARCHAR2(19)
STATUS VARCHAR2(7)
TEMPORARY VARCHAR2(1)
GENERATED VARCHAR2(1)
SECONDARY VARCHAR2(1)

SQL> select object_name,object_type,created,last_ddl_time from user_objects;

SQL> select owner,count(*) from all_tables group by owner;

OWNER COUNT(*)
------------------------------ ----------
MDSYS 28
FLOWS_020100 7
CTXSYS 3
HR 7
SYSTEM 5
SYS 12

create or replace procedure affich_table


is
cursor c is
select table_name from user_tables;
begin
for vc in c loop
dbms_output.put_line(c%rowcount||' '||vc.table_name);
end loop;

end;
/
SQL> set serveroutput on
SQL> execute affich_table
1REGIONS
2LOCATIONS
3DEPARTMENTS
4JOBS
5EMPLOYEES
6JOB_HISTORY
7COUNTRIES

ProcÚdure PL/SQL terminÚe avec succÞs.

SQL> desc user_tab_columns;


------------

create or replace procedure aff_table_4


is
cursor ct is
select table_name from user_tables;

cursor ca (x user_tab_columns.table_name%type) is
select column_name from user_tab_columns
where table_name = x;

ch varchar2(1000);

begin
for vct in ct loop
ch := vct.table_name ||' (';
for vca in ca(vct.table_name) loop
if ca%rowcount = 1
then
ch := ch || vca.column_name;
else
ch := ch ||', '|| vca.column_name;
end if;
end loop;
ch := ch ||')';
dbms_output.put_line(ch);
end loop;
end;
/

SQL> set serveroutput on


SQL> execute affich_table

--------------------

create or replace procedure aff_table_4(nom dba_users.username%type)


is
cursor ct is
select table_name from dba_tables where owner=upper(nom);

cursor ca (x dba_tab_columns.table_name%type) is
select column_name from dba_tab_columns
where table_name = x and owner =upper(nom);
ch varchar2(1000);

begin
for vct in ct loop
ch := vct.table_name ||' (';
for vca in ca(vct.table_name) loop
if ca%rowcount = 1
then
ch := ch || vca.column_name;
else
ch := ch ||', '|| vca.column_name;
end if;
end loop;
ch := ch ||')';
dbms_output.put_line(ch);
end loop;
end;
/

SQL> set serveroutput on


SQL> execute aff_table_4('HR')

SQL> select count(*) from dba_tables;

COUNT(*)
----------
1089

SQL> select count(*) from all_tables;

COUNT(*)
----------
1089

SQL> select count(*) from user_tables;

COUNT(*)
----------
669

You might also like