--When verifying that the stored procedure is correct, you need to use the declare block.
declare
i integer;
v_sql varchar2(1000);
-- define cursor
CURSOR C_EMP IS SELECT category FROM act_hq_tem_def;
begin
select count(*) into i from user_tables t where t.table_name ='SSS';
dbms_output.put_line('The value of I is:');
dbms_output.put_line(i);
if i=1 then
execute immediate 'drop table sss'; end if;
IF I=0 THEN
execute immediate '
create table sss(
name number(20) )';
end if;
dbms_output.enable(1000000);
for tab in (
select t.guid gd, t.name nm from fasp_T_causer t
)
loop --loop is the beginning of the loop, and the end mark loop end is required.
v_sql := 'select count(*) from fasp_T_causer';
execute immediate v_sql into i;
If i > 0 then
DBMS_OUTPUT.PUT_LINE(tab.nm || ' tab 中的name值 ' || tab.gd );
end if;
end loop ;
-- traverse the cursor
for c_row22 in c_emp loop
if substr(c_row22.category,-4) ='2016' then
dbms_output.put_line('Process type' || c_row22.category);
end if;
end loop ;
------------------------------------------------------------
-- create stored procedure
create or replace procedure p_wf_cf(yn varchar2,yo varchar2,allds out varchar2) as
cursor c_emp is select category from act_hq_tem_def;
tablec1 number;
begin
select count(*) into tablec1 from user_tables where table_name='ACT_HI_PROCINST_' || yn;
allds := tablec1;
end p_wf_cf;
--Call the stored procedure, and the output value is also passed in the function. The output value can then be replaced and printed.
declare
v_titleAVARCHAR2(20) := '2017';
v_titlebVARCHAR2(20) := '2016';
v_titlec11VARCHAR2(20) :='12';
begin
p_wf_cf(v_titleA,v_titleb,v_titlec11);
v_titlec11 :=p_wf_cf(v_titleA,v_titleb); --The return operation is required in the stored procedure to use this method.
dbms_output.put_line('Output value:' || v_titlec11);
end;
-- write stored procedure
create or replace procedure p_fasp_sc (dblink in varchar) as
type refcursor is ref cursor;--Define the cursor type
col_cursor refcursor;--Define the cursor variable
v_deptRowfasp_T_causer%ROWTYPE;-- define the row type
v_empRowfasp_T_causer%ROWTYPE;-- define the row type
tablename varchar2(100);
tmpsql varchar2(20000);
exesql varchar2(20000);
v_enoemp.empno%TYPE ; -- The same type as the empno field type in the emp table.
v_resultA NUMBER NOT NULL := 100 ; -- define a non-null variable v_resultA and assign a value at the same time
v_enameVARCHAR2(10) ;
v_deptRowdept%ROWTYPE ;-- Load a row of records from the dept table
v_date1DATE := SYSDATE ;--Define the time
type emp_type is recode(
ename emp.ename%type,
job emp.job%type,
sal emp.sal%type,
comm emp.comm%type
);
v_emp emp_type;--Define a specified composite type variable
begin
v_eno: = & empno;-- Enter employee number by keyboard
SELECT * INTO v_deptRow FROM dept WHERE deptno=10 ;--Query a row of records in v_deptRow.
tmpsql :='select table_name as tablename from fasp_v_usertables where table_name like ''FASP_T_GL%''';
open col_cursor for tmpsql; -- open the cursor
loop
fetch col_cursor into tablename ; -- get cursor data
exit when col_cursor%notfound; -- exit if there is no data
exesql := 'select count(*) from fasp_v_usertables';
begin
execute immediate exesql;
exception
when others then
dbms_output.put_line('baocuole');
raise;
end;
end loop;
close col_cursor;
end;
-- call stored procedure
declare
v_titleAVARCHAR2(20) := '1212';
begin
p_fasp_sc(v_titleA) ;
end;
-- subroutine
if 。。then 。。 else
and
or
between and
is null
not null
like
--case
CASE v_choose
WHEN 0 THEN
DBMS_OUTPUT.put_line('You selected item 0.');
WHEN 1 THEN
DBMS_OUTPUT.put_line('You selected item 1.');
ELSE
DBMS_OUTPUT.put_line('No options are satisfied.');
END CASE ;
RAISE -- An exception was reported.
COMMIT ;
--for
declare
--type definition
c_sal cursor
is
select empno,ename,sal from emp ;
--Define a cursor variable v_cinfo c_emp%ROWTYPE, which is the data type of a row in the cursor c_emp
c_row c_sal%rowtype;
begin
for c_row in c_sal loop
dbms_output.put_line(c_row.empno||'_'||c_row.ename||'-'||c_row.sal); end loop;
end;