1.
SHOW USER(or SELECT USER FROM DUAL)
/
2.
SELECT USERNAME, USER_ID, PASSWORD FROM DBA_USERS ORDER BY USERNAME
/
3.
SELECT DEFAULT_TABLESPACE FROM USER_USERS
/
4.
SELECT TABLE_NAME, TABLESPACE_NAME FROM USER_TABLES <----- only find the current user tables.
/
5.
ALTER TABLE FOO MOVE TABLESPACE TS_MY_TABLESPACE
/
6.
SELECT * FROM DBA_TABLESPACES
/
7.
CREATE TABLESPACE MY_TABLESPACE
LOGGING
DATAFILE 'C:\ORCL\TS\MY_DB_01.DBF' SIZE 32M AUTOEXTEND ON NEXT 32M MAXSIZE 128M,
'C:\ORCL\TS\MY_DB_02.DBF' SIZE 32M AUTOEXTEND ON NEXT 32M MAXSIZE 128M
EXTENT MANAGEMENT LOCAL
/
note: If contents exceed the tablespace max size, then [ORA-01654: unable to extend index ASRAN.SYS_C0024968 by 128 in tablespace] thrown.
-----------------------------
SELECT * FROM V$DATAFILE;
-----------------------------
Moving and Renaming Tablespaces:
1.Take the tablespace offline using an ALTER TABLESPACE statement with the OFFLINE clause:
ALTER TABLESPACE tbs_02 OFFLINE NORMAL;
2.Copy the file from 'C:\ORACLEXE\APP\ORACLE\PRODUCT\10.2.0\SERVER\DATABASE\TS_DENGAS_01.DBF' to 'C:\oraclexe\oradata\TEST\TS_DENGAS_01.DBF' using your operating system commands.
3.Rename the datafile using an ALTER TABLESPACE statement with the RENAME DATAFILE clause:
ALTER TABLESPACE tbs_02
RENAME DATAFILE 'C:\ORACLEXE\APP\ORACLE\PRODUCT\10.2.0\SERVER\DATABASE\TS_DENGAS_01.DBF'
TO 'C:\oraclexe\oradata\TEST\TS_DENGAS_01.DBF';
4.Bring the tablespace back online using an ALTER TABLESPACE statement with the ONLINE clause:
ALTER TABLESPACE tbs_02 ONLINE;
-----------------------------
Add/Drop datafiles:
alter tablespace ts_dengas
add datafile 'c:\oraclexe\oradata\test\ts_dengas_02.dbf' size 100k autoextend off
/
alter tablespace ts_dengas
drop datafile 'c:\oraclexe\oradata\test\ts_dengas_02.dbf'
/
-----------------------------
Drop tablespace:
drop tablespace <tablespace_name> [including contents] [and datafiles] [cascade constraints]
/
-----------------------------
Resize datafile:
alter database datafile '<datafile-path>'
resize 2M
/
note: If the target size is too small, then [ORA-03297: file contains used data beyond requested RESIZE value] thrown.
8.
VAR[IABLE] VARIABLE_NAME DATA_TYPE
PRINT VARIABLE_NAME
9.
SET SERVEROUTPUT ON ESCAPE OFF
DBMS_OUTPUT.PUT_LINE('MSG...');
10.
The values of all parts of the primary key must never be null.
1. First Normal Form means that the database doesn't contain any repeating attributes.
2. Violations of Second Normal Form occur when the table contains attributes that depend on a portion of the primary key.
3. Second Normal Form violations can exist only when you have a multi-column primary key.
4. Third Normal Form violations occur when a transitive dependency exists.
5. All attributes in entities (columns in tables) must be dependent upon the primary key or one of the candidate keys and not on other attributes.
11.
SELECT OBJECT_NAME, OWNER FROM DBA_OBJECTS WHERE OBJECT_TYPE='TABLE' AND OWNER = 'SYSTEM'
/
12.
SELECT TABLE_NAME.COLUMN_NAME FROM TABLE_NAME -- NO ALIAS
/
13.
SELECT LEVEL, empno, manager_id, ename
FROM employee
START WITH empno = 1
CONNECT BY PRIOR empno = manager_id
ORDER BY LEVEL
/
14. is null VS. =
SELECT m.* FROM SA_MENU_ITEM m
WHERE m.DISPLAY_IND= :displayInd
CONNECT BY PRIOR m.ID = m.PARENT_MENU_ID
START WITH NVL(m.PARENT_MENU_ID, NULL) || ' ' = NVL(:rootMenuId, NULL) || ' ';
15. set nls lange & characterset:
set NLS_LANG=AMERICAN_AMERICA.al32UTF8
set nls_nchar_characterset=american_america.al16utf16
16. full setting of creating user:
--------------------------------------------------------------------------------
-- Create the user
create user asran
identified by asran
default tablespace ASRAN_TS
temporary tablespace TEMP
profile DEFAULT
password expire
account lock
quota 1m on asran_ts;
-- Grant/Revoke object privileges
grant select, insert, update, delete on ALL_ALL_TABLES to asran with grant option;
-- Grant/Revoke role privileges
grant connect to asran with admin option;
grant resource to asran with admin option;
-- Grant/Revoke system privileges
grant update any table to asran with admin option;
17. synonym:
--------------------------------------------------------------------------------
create tablespace asran_ts
logging
datafile 'c:\usr\orcl\ts\asran_ts\asran_ts_01.dbf'
size 2M
autoextend off;
create user asran identified by asran
default tablespace asran_ts
temporary tablespace temp
quota 32k on asran_ts;
grant connect to asran;
create user ada identified by ada
default tablespace asran_ts
temporary tablespace temp
quota 16k on asran_ts;
alter user ada quota 1M on asran_ts;
create table ada.bl_profile(
id int not null,
name varchar2(200)
);
alter table ada.bl_profile add constraint ada_bl_profile_pk primary key(id);
create table ada.private_bl_profile(
id int not null,
name varchar(200)
) tablespace asran_ts;
alter table ada.private_bl_profile add constraint ada_private_bl_profile_pk primary key(id);
select * from ada.bl_profile;
grant select on ada.bl_profile to asran;
revoke select on ada.bl_profile from asran;
create synonym ada.bl_profile_alias for ada.bl_profile; -- create synonym in current schema
grant select on ada.bl_profile_alias to asran; -- grant priviledges of synonym to other users
sqlplus asran/asran
select * from ada.bl_profile; -- can't find table or view
select * from ada.bl_profile_alias; -- works well
note: all synonym and real object(table,view,...) share the same object, as a result, any grant/revoke on one of them should effect each other.
18. display oracle version:
SELECT * FROM V$VERSION;
19. customer defined object type(HashMap):
create or replace type <my_type_obj> as object(<property_name> <property_type>, ...)
/
usage:
declare: <variable_name> <my_type_obj>;
assign value: <variable_name> := <schema>.<my_type_obj>(value1, value2, ...);
get value: <variable_name>.<property_name>
note:
an object type is just as a key-value pair map.
20. customer defined table type(List<HashMap>):
create or replace type <my_type_tbl> as table of <my_type_object>
/
usage:
declare and initialize: <my_tbl> <schema>.<my_type_tbl> := <schema>.<my_type_tbl>(); -- size 0
extend the size of list: <my_tbl>.extend;
add obj: <my_tbl>(index start at 1) := <my_type_obj>(value1, value2, ...);
e.g.: <my_tbl>(<my_tbl>.count) := <my_type_obj>(value1, value2, ...)
21. cursor:
declare
v_id asran.t_student.id%type;
v_name asran.t_student.name%type;
cursor v_cursor is select id, name from asran.t_student;
begin
open v_cursor;
loop
fetch v_cursor into v_id, v_name;
exit when v_cursor%notfound;
dbms_output.put_line('id=' || v_id || ', name=' || v_name);
end loop;
close v_cursor;
end;
/
or use for...loop:
declare
cursor v_cursor is select id, name from asran.t_student;
begin
for c in v_cursor loop
dbms_output.put_line('id=' || c.id || ', name=' || c.name);
end loop;
end;
/
22. package:
--------------------define package
create or replace package asran.pkg_all
as
function add(p_a in int, p_b in int) return int;
end;
/
--------------------define package body
create or replace package body asran.pkg_all
as
function add(p_a in int, p_b in int)
return int
is
v_sum int := 0;
begin
v_sum := p_a + p_b;
return v_sum;
end;
end;
/
--------------------using package
declare
v_sum int;
begin
v_sum := asran.pkg_all.add(2,4);
dbms_output.put_line('sum:' || v_sum);
end;
/
23. trigger:
create or replace trigger tri_as_student_insert
after insert or delete on asran.as_student
for each row
declclsare
updating_key_fields exception;
v_count int := 0;
begin
if inserting then
select count(1) into v_count from asran.as_student;
dbms_output.put_line('The total records of asran.as_student is ' || v_count);
end if;
if updating then
raise updating_key_fields;
end if;
if deleting then
....
end if;
end;
/
alter trigger asran.tri_as_student_insert disable
/
alter trigger asran.tri_as_student_insert enable
/
24. arguments / return type declaration:
Never specify the size/(precision, scale) for char/varchar/number types in Oracle10g.
25. sequence:
create sequence [schema.]sequence_name increment by 1 start with 0 nomaxvalue nocycle nocache
/
note:
1. can't use [create or replace ...] for create sequence, saying that we can't replace an existing sequence.
2. can't alter sequence start with [ORA-02283: cannot alter starting sequence number].
26. pass parameter to plsql:
begin
dbms_output.put_line('&name is a good staff');
end;
/
note: [&****] is named parameter.
27. use function in index creation:
create index asran.t_student_idx on asran.t_student(upper(name))
/
28. retrieve the next day:
select next_day(sysdate, 'MON|Mondy,...') from dual
/
select add_months(sysdate, 2) from dual
/
29. dump sqlplus sreen output to a specified file:
sqlplus>define fil = 'c:\oral_spool.log'
sqlplus>spool &fil <--- open file output stream
sqlplus>prompt *** Spool to 'c:\oral_spool.log'
sqlplus>....
sqlplus>spool off <--- flush output buffer to file system
30. set SQLPATH environment variable:
set SQLPATH=c:\usr\orcl\sqlpath
sqlplus will find and save buffer file to this folder.(search in current folder, and then SQLPATH folder)
31. start sqlplus with silent mode and run a sql script file:
sqlplus -silent asran/asran @init_script.sql
32. start sqlplus without login:
sqlplus /nolog
33. clear buffer/screen
clear buffer
clear screen
33. read a script file to buffer:
get test.sql list|nolist
34. export/imprt db in Oracle10g:
select * from nls_database_parameters where parameter = 'NLS_CHARACTERSET';
set NLS_LANG=AMERICAN_AMERICA.AL32UTF8
exp cs2_afw_owner/cs2_afw_owner@zhcs2qa2 file=cs2_afw_owner.dmp
-----------------------
sqlplus sys/sys as sysdba
create tablespace cs2_ts
logging
datafile 'c:\usr\orcl\ts\cs2_ts\cs2_data_01.dbf' size 512m autoextend on next 128m maxsize 1024m
extent
management local
create user cs2_afw_owner identified by cs2_afw_owner default tablespace cs2_ts;
imp file=cs2_afw_owner.dump fromuser=cs2_afw_owner touser=cs2_afw_owner
>username: sys/sys as sysdba
35. find the company which have the same personnel amount:
select c.* from company c where c.personnel_amt in (
select personnel_amt from company group by personnel_amt having count(1) > 1
);
36. utilites functions:
PL/SQL – String Manipulation:
rtrim, ltrim, trim, concat, rpad, lpad, upper, lower, length, replace(), initcap(), instr(), substr()
Generating random numbers and strings in Oracle:
Generating a random number (positive or negative)
select dbms_random.random from dual;
Generating a random number between 0 and 1
select dbms_random.value from dual;
Generating a random number from a range, between 1 to 1000
select dbms_random.value(1,1000) num from dual;
Generating a 12 digit random number
select dbms_random.value(100000000000, 999999999999) num from dual
Generating an upper case string of 20 characters
select dbms_random.string('U', 20) str from dual;
Generating a lower case string of 20 characters
select dbms_random.string('L', 20) str from dual;
Generating an alphanumeric string of 20 characters
select dbms_random.string('A', 20) str from dual;
Generating an upper case alphanumeric string of 20 characters
select dbms_random.string('X', 20) str from dual;
Generating a string of printable 20 characters
select dbms_random.string('P', 20) str from dual;
Example for calling the dbms_random package and setting the seed for generating the same set of random numbers in different sessions
declare
l_num number;
begin
l_num := dbms_random.random;
dbms_output.put_line(l_num);
dbms_random.seed('amar testing 67890');
l_num := dbms_random.random;
dbms_output.put_line(l_num);
end;
/
37. export & import:
exp userid=scott/tigger full=y file=myfile.dmp
exp userid=scott/tigger owner=(scott,ali) file=exp_own.dmp
exp userid=scott/tigger tables=(scott.emp,scott.sales) file=exp_tab.dmp
imp scott/tigger ignore-y tables(emp,dept) full=n
or imp scott/tigger ignore-y tables(T1:P1,T2:P2) full=n, if T1 is partioned table
38. SQLPLUS:
COLUMN <col_name> FORMAT A<width>
相关推荐
Oracle 9i Client (Oracle 9i 客户端) 简化版 (不安装Oracle客户端,也可以使用PLSQL Developer 不用安装Oracle客户端也可以使用PLSQL Developer 绿色! 安全! 轻便! 可靠! 1、本软件可作为简单的Oracle9i客户端...
oci.dll是Oracle Call Interface的缩写,它是Oracle数据库的一个核心组件,允许开发者使用各种编程语言与Oracle数据库进行交互。在Oracle 10G和11G版本中,oci.dll扮演了至关重要的角色,为应用程序提供了访问数据库...
Oracle JDBC驱动包是Oracle数据库与Java应用程序之间进行通信的关键组件,它使得Java程序员能够通过编写Java代码来操作Oracle数据库。标题中的"ojdbc6"指的是Oracle JDBC驱动的一个特定版本,适用于Java SE 6环境。...
cx_Oracle是Python编程语言中用于连接Oracle数据库的一个模块。该模块遵循Python数据库API规范,并且适用于Oracle 11.2和12.1版本,同时兼容Python 2.x和3.x版本。cx_Oracle模块通过使用Oracle客户端库来实现与...
首先,Oracle.ManagedDataAccess是Oracle公司提供的一个纯.NET框架的客户端驱动,它允许开发者在不安装Oracle客户端的情况下,直接与Oracle数据库进行交互。这个库包含了所有必要的组件,使得C#程序可以方便地执行...
cx_Oracle是Python数据库API规范的实现,用于访问Oracle数据库。目前,该模块经过对Oracle客户端版本11.2、12.1和12.2以及Python版本2.7、3.4、3.5和3.6的测试。cx_Oracle遵循开源的BSD许可证,这表示用户可以自由地...
Oracle Client是Oracle公司提供的数据库连接工具,用于与Oracle数据库服务器进行通信。19C是Oracle Database的一个版本,代表第19个主要版本。这个压缩包包含的Oracle Client适用于Windows和Linux操作系统,使得...
《Oracle 12c数据库基础教程》教学课件—03Oracle数据库管理工具.pdf《Oracle 12c数据库基础教程》教学课件—03Oracle数据库管理工具.pdf《Oracle 12c数据库基础教程》教学课件—03Oracle数据库管理工具.pdf《Oracle...
Dbmover for Mysql to Oracle 是高效的将Mysql导入到Oracle数据库的工具。 使用DBMover可以灵活定义Mysql和Oracle之间表和字段的对照关系,也可以在DBMover创建一个查询,把查询结果当作源表转入到Oracle中。 ...
Oracle 11g客户端是Oracle数据库的一个轻量级版本,主要供开发人员和系统管理员用于连接到Oracle数据库服务器,执行查询、管理和维护数据库任务。这个精简版在保持基本功能的同时,减少了安装体积,便于快速部署和...
Oracle各版本驱动包,有需要的可以下载使用,支持目前常用的不同版本oracle和JDK,根据自己需要调整和使用 主要包括的jar有: ojdbc5.jar 适用JDK版本:JDK 1.5 对应Oracle数据库版本:Oracle数据库版本(如Oracle ...
### Tianlesoftware Oracle 学习手册(v1.0)中的关键知识点 #### 1. ORACLE基础知识 ##### 1.1 OLAP与OLTP介绍 **1.1.1 什么是OLTP** OLTP(Online Transaction Processing,在线事务处理)是一种主要针对企业...
python-oracledb的源码和使用示例代码, python-oracledb 1.0,适用于Python versions 3.6 through 3.10. Oracle Database; This directory contains samples for python-oracledb. 1. The schemas and SQL ...
Oracle 19c是Oracle数据库的一个重要版本,尤其在Windows平台上,它提供了全面的功能和优化,使得数据库管理和开发更为高效。以下将详细讲解Oracle 19c Windows客户端的关键知识点: 1. **Oracle Client**: Oracle...
Veeam 备份恢复 Oracle 数据库详细配置文档 本文档旨在详细介绍如何使用 Veeam 备份恢复 Oracle 数据库的配置过程。该文档将指导读者从环境准备到推送 Oracle RMAN Plugin,再到创建备份作业和运行备份作业,最后...
这里提到的三本书籍——"Oracle 9i初学者指南.zip"、"Oracle专家高级编程.pdf"以及"Effective Oracle by Design.pdf"都是Oracle学习者和专业开发者的宝贵资源。 "Oracle 9i初学者指南.zip":这是一本针对Oracle 9i...
Oracle Instant Client 11.2.0.1.0是轻量级Oracle客户端,用于连接访问Oracle 9i、10g、11g 11.2.0.1.0版本的Oracle数据库。 Oracle Instant Client11.2.0.1.0 安装程序包含OCI/ OCCI、JDBC-OCI SDK(软件开发工具...
Oracle客户端是用于与Oracle数据库服务器交互的软件工具,主要功能是提供对数据库的查询、更新、管理等操作。Oracle客户端支持多种操作系统,包括Windows,且有32位和64位之分。在这个场景中,我们关注的是"Oracle...
标题中的“System.Data.OracleClient 需要 Oracle 客户端软件 8.1.7 或更高版本”是一个常见的错误提示,它涉及到在.NET环境中使用Oracle数据库时遇到的问题。这个错误表明,当你试图在应用程序中使用System.Data....
本人琢磨了下使用VS .Net 2005开发的客户端程序,需要访问oracle数据库,但不想在客户端安装oracle客户端的解决方法。终于给弄清楚了,其实根本不需要在安装oracle客户端就可以轻松实现了。方法是将相关的9个oracle...