首页 > 代码库 > plsql语法
plsql语法
1.PL/SQL代码块的结构:
declare
常量、变量、游标和异常等的定义,可选
begin
SQL和PL/SQL语句执行部分,必选
exception
异常处理部分,可选
end;
2.PL/SQL变量类型:标量类型、复合类型、参照类型和LOB(Large Object)类型
2.1标量变量:数字、字符、日期和布尔
2.2复合变量:PL/SQL记录、PL/SQL表、嵌套表和VARRAY
3.for循环语句:
for loop_counter in [REVERSE] lowest_number .. highest_number
loop
{.statements.}
end loop;
示例:
declare
v_i number(4) := 0;
begin
for v_i in 0 .. 10
loop
dbms_output.put_line(v_i);
end loop;
end;
begin
for rec in (select * from dba_objects where rownum<100) loop
dbms_output.put_line(rec.object_id);
end loop;
end;
4.while循环语句:
while condition
loop
{.statement.}
end loop;
示例:
declare
v_loopCount number(10) := 0;
begin
while v_loopCount < 100
loop
dbms_output.put_line(v_loopCount);
v_loopCount := v_loopCount + 1;
end loop;
end;
5.if语句:
if condition then
{.statements.}
elsif condition then
{.statements.}
else
{.statements.}
end if;
6.删除表字段:
alter table tab_name drop column col_name;
7.删除表的主键:
alter table tab_name drop primary key;
8.修改表字段定义:
alter table tab_name modify col_name default ‘0‘;
alter table tab_name modify col_name varchar2(512);
9.删除索引:
drop index IDX_EX_0771;
10.修改字段名:
alter table tab_name rename column col_name_1 to col_name_2;
11.修改表名
alter table tab_name_1 rename to tab_name_2;
plsql语法