1、创建测试表,
create table test_val(id varchar2(20),remark varchar2(20));
2、插入测试数据;
insert into test_val select level, 'lvl_'||level remark from dual connect by level<=100;
commit;
3、编写语句,将表中的记录数赋值给变量;
declare
v_int number;
begin
execute immediate 'select count(*) from test_val' into v_int;
end;
4、将变量值打印,查看结果;
dbms_output.put_line(v_int);
declare
m_num number;
begin
select count(1) into m_num from weixin_depart;
dbms_output.put_line('m_num=' || m_num);
end;
单独定义声明变量后,在语句里使用into,如下:
select count(*) into num from table1;