alter table myschema.mytable rename to mytable_old;Change ownership for a table:
alter table myschema.mytable owner to anotherschema;
Minimalistic Oracle contains a collection of practical examples from my encounters with Oracle technologies. When relevant, I also write about other technologies, like Linux or PostgreSQL. Many of the posts starts with "how to" since they derive directly from my own personal experience. My goal is to provide simple examples, so that they can be easily adapted to other situations.
alter table myschema.mytable rename to mytable_old;Change ownership for a table:
alter table myschema.mytable owner to anotherschema;
pg_dump mydb -n 'myschema' -a -Fp -t myschema.mytable --column-inserts > /data1/insert_statements.sql| gzip
mydb # select 'myschema.mytable'::regclass::oid; oid ---------- 19561436 (1 row)
SELECT pg_size_pretty(sum(pg_relation_size(quote_ident(schemaname) || '.' || quote_ident(tablename)))::bigint) FROM pg_tables WHERE schemaname = 'yourschema';
export HOST=${HOSTNAME%%.*}
SYS@cdb SQL> alter session set container=pdb1; ERROR: ORA-65011: Pluggable database PDB1 does not exist.Check the setting of _pdb_name_case_sensitive:
SYS@cdb SQL> show parameter pdb NAME TYPE VALUE ------------------------------------ ----------- ------------------------------ _pdb_name_case_sensitive boolean TRUE
SYS@cdb SQL> alter session set container="pdb1"; Session altered. SYS@cdb SQL> show con_name CON_NAME ------------------------------ pdb1 SYS@cdb SQL> show con_id CON_ID ------------------------------ 3The note ORA-65011: Pluggable Database Does Not Exist (Doc ID 2642230.1) from Oracle Support confirms this finding.
set serveroutput on
DECLARE
v_version sys.v_$instance.version%type;
v_param_value sys.v_$system_parameter.value%type;
v_pdb boolean;
v_con_id number;
v_con_type varchar(7);
BEGIN
-- find current setting of optimizer_dynamic_sampling
select value
into v_param_value
from v$parameter
where name = 'optimizer_dynamic_sampling';
-- find current(major) version
select version
into v_version
from sys.v_$instance;
-- find container type
select
case when (sys_context('USERENV','CON_ID') = 0 ) then 'NON-CDB'
when (sys_context('USERENV','CON_ID') = 1 ) then 'CDB'
when (sys_context('USERENV','CON_ID') > 1 ) then 'PDB'
end
into v_con_type
from DUAL;
--dbms_output.put_line('v_con_type: ' || v_con_type);
--dbms_output.put_line('version: ' || v_version);
--dbms_output.put_line('optimizer_dynamic_sampling: ' || v_param_value);
v_pdb := FALSE;
IF v_con_type = 'PDB' THEN
v_pdb := TRUE;
ELSE
v_pdb := FALSE;
END IF;
CASE WHEN v_version IN ('18.0.0.0.0','19.0.0.0.0') AND v_param_value = '0' THEN
dbms_output.put_line('version is >= 18 and optimizer_dynamic_sampling = 0');
IF v_pdb = FALSE THEN
dbms_output.put_line('execute immediate alter system set optimizer_dynamic_sampling=4 scope=both;');
execute immediate 'alter system set optimizer_dynamic_sampling=4 scope=both';
ELSIF v_pdb = TRUE THEN
dbms_output.put_line('execute immediate alter system set optimizer_dynamic_sampling=4 container=current scope=both;');
execute immediate 'alter system set optimizer_dynamic_sampling=4 container=current scope=both';
END IF;
WHEN v_version IN ('18.0.0.0.0','19.0.0.0.0') AND v_param_value <> '0' THEN
dbms_output.put_line('version is >= 18 and optimizer_dynamic_sampling is already set.');
ELSE
dbms_output.put_line('version is < 18');
END CASE;
END;
/