All technological notes.
select 1 from dual; # any sql
save file_name # the path will be thw pwd where login sqlplus.

@file_name

cd target_path
sqlplus sys/pwd@tns_name file_name
# example
cd ~/Desktop
sqlplus sys@orcl @test.sql

Oracle data dictionary
Structure of Data Dictionary
| Data Dictionary | Objects | User |
|---|---|---|
CDB_ |
in the CDB and PDBs | DBA account* |
DBA_ |
in a container or PDB | DBA account* |
ALL_ |
accessible by the current user | any user |
USER_ |
owned by current user | any user |
DBA account*:
CDB_ only returns objects in opened PDBs.CDB_ only returns the objects in the current PDB.重点: 易错. CDB_, DBA与 session 有关.
CDB_: root + opened pdbDBA_: rootCDB_: pdbDBA_: pdbALL_ or USER_.
ALL_data_files or USER_data_files does not exist. Because the user does not need to know the data file. only the dba does. So the CDB_DATA_FILES and DBA_DATA_FILES exist.show con_name
#CON_NAME
#------------------------------
#CDB$ROOT
select con_id,name,open_mode from v$pdbs;
#2 PDB$SEED READ ONLY
#3 ORCLPDB READ WRITE
--make sure that the pluggable database is open
alter pluggable database ORCLPDB open;
CDB_ Dict--this will show all the tables in the CDB and PDBS
select owner,table_name,con_id from cdb_tables
order by 1,2;
--count of tables per container
SELECT con_id, COUNT(table_name)
FROM cdb_tables
GROUP BY con_id;
DBA_show con_name
-- root
-- return the current container
SELECT COUNT(table_name)
FROM DBA_tables;
# change session to PDB
ALTER session set container=ORCLPDB;
show con_name
#CON_NAME
#------------------------------
#ORCLPDB
# return the PDB container
SELECT COUNT(table_name)
FROM DBA_tables;
alter session set container=cdb$root;
show con_name
Dynamic Performance Views / v$ views:
SYS.Identified:
Dynamic performance views are identified by the prefix V_$.V$.Availability:
V$ views that read from memory are accessible. 内存的, 实例启动即可The dynamic performance views are used by Enterprise Manager and Oracle Trace, which is the primary interface for accessing information about system performance
show con_name
alter pluggable database orclpdb open;
alter session set container=orclpdb;
show con_name
v$locked_object show the locked objectdba_objects shows details of the locked oject
select
oracle_username
os_user_name,
locked_mode,
object_name,
object_type
from
v$locked_object a,dba_objects b
where
a.object_id = b.object_id
select * from hr.employees;
# update a row
update hr.employees
set salary=salary+1
where employee_id=100;
select
oracle_username
os_user_name,
locked_mode,
object_name,
object_type
from
v$locked_object a,dba_objects b
where
a.object_id = b.object_id;

rollback;
select
oracle_username
os_user_name,
locked_mode,
object_name,
object_type
from
v$locked_object a,dba_objects b
where
a.object_id = b.object_id
multi-tennant
select name,cdb,con_id ,OPEN_MODE
from V$DATABASE;
show parameter db_name;


select banner from v$version;

select *
from v$instance;
show parameter instance_name;


show con_name;
select con_id,name,open_mode from V$CONTAINERS;

alter session set container=orclpdb;
select con_id,name,open_mode from V$CONTAINERS;

show con_name
select pdb_id,pdb_name, status
from cdb_PDBS;

alter session set container=orclpdb;
show con_name;
select pdb_id,pdb_name, status
from cdb_PDBS;
