-----------------Oracle10g--Windows---------------
cmd环境中
启动监听器: lsnrctl start
启动实例: oradim -startup -sid myoracle
sys身份登录: sqlplus / as sysdba (操作系统验证)
查看所有用户: select * from dba_users
查看当前用户系统权限:select * from user_sys_privs
查看当前用户对象权限:select * from user_tab_privs
---------------------------------------------------------------------
创建表,create table test_tab(
id varchar2(16)
default to_char(sysdate,'ddmmyyyyhh24miss')
)
更改表, alter TABLE<表名>
[ADD<新列名><数据类型>[完整性约束]]
[DROP<完整性约束名>]
[MODIFY<列名><数据类型>];
<表名>是要修改的基本表,
ADD子句用于增加新列和新的完整性约束条件,
DROP子句用于删除指定的完整性约束条件,
MODIPY子句用于修改原有的列定义,包括修改列名和数据类型。
-------------------------------------------------------------------------------
PL/SQL
1.数据类型
2.流程控制语句格式
数据类型:
char(n)------------定常,缺省为1,最大2000
varchar2(n)--------变长,不可缺省,最大4000
binary_integer-----整型,带符号
number(p,s)--------数值
long---------------变长字符串
date---------------日期
boolean------------布尔
rowid--------------数据库行号,物理地址
变量声明:
variable [constant] type [not null] [:=value]
eg. user_name char(8) :='jim'
空值处理:空值+字符=空值 空值||字符=字符
流程控制语句:
if loop exit goto null
============================
if() then
/////
end if;
---------------------------
if() then
////
else
////
end if;
---------------------------
if() then
////
elseif () then
////
elseif () then
////
......
else
////
end if;
---------------------------
case selector
when expression1 then result1
when expression2 then result2
when expression3 then result3
/////////
[else default_result]
end;
----------------------------
loop
////
exit when <>
end loop
----------------------------
while() loop
////
end loop
----------------------------
--yyj是一个表名
declare
V_id yyj.id%type; cursor c_cursor is select id from yyj;
begin
open c_cursor;
fetch c_cursor into v_id;
dbms_output.put_line(v_id);
while(c_cursor%found) loop
fetch c_cursor into v_id;
dbms_output.put_line(v_id);
end loop;
close c_cursor;
end;
result yyj%rowtype (同V_id,一个是单个字段值,一个是一行记录)
result yyj_view%rowtype (也可以是视图)