oracle-plsql 基本语法
基本结构
--方法一(简单赋值)
declare
v_name varchar2(10);
v_sum number(5);
begin
v_name :='张三';
v_sum :=10000;
dbms_output.put_line('姓名:' || v_name || ',总和:' || v_sum);
end;
--方法二(获取数据库数据)
declare
v_id number(10,2);
v_name varchar2(10);
begin
select id,name into v_id,v_name from user where id=1;
dbms_output.put_line('姓名:' || v_name || ',编号:' || v_id);
end;
--方法三(动态获取数据类型)
declare
v_id user.id%type;
v_name user.name%type;
begin
select is,name into v_id,v_name from user where id=1;
dbms_output.put_line('编号:' || v_name || ',姓名:' || v_name);
end;
--方法四(记录类型)
declare
type user_record is record(
v_id user.id%type,
v_name user.name%type
);
v_user_record user_record;
begin
select id,name into v_user_record from user where id=1;
dbms_output.put_line('编号:' || v_user_record.v_id || ',姓名:' || v_name_record.v_name);
end;
--方法五(获取所有列数据)
declare
v_user_record user%rowtype;
begin
select * into v_user_record from user where id=1;
dbms_output.put_line('编号:' || v_user_record.id || ',姓名:' || v_name_record.name);
end;