创建存储过程:
CREATE OR REPLACE PROCEDURE 存储过程名称 AS
BEGIN
需要执行的sql;
END;
创建带参数的存储过程:
CREATE OR REPLACE PROCEDURE sp_budget_share_build (
in_ysny VARCHAR DEFAULT NULL,
in_gs VARCHAR DEFAULT NULL,
code OUT NUMBER,
msg OUT VARCHAR) AS
YSNYVAR VARCHAR(10);
params2 VARCHAR(20);
BEGIN
YSNYVAR := nvl(in_ysny, to_char(sysdate, 'yyyy-mm'));
UPDATE FLYCO_SALES_RESULTS a SET YSJE = (
SELECT INPUT_YSJE FROM flyco_amortization_input b WHERE b.BMID = a.BMID AND b.YSNY = a.YSNY AND a.YSZBXH = b.INPUT_YSZBXH
) WHERE YSNY = YSNYVAR AND EXISTS(
SELECT INPUT_YSJE FROM flyco_amortization_input b WHERE b.BMID = a.BMID AND b.YSNY = a.YSNY AND a.YSZBXH = b.INPUT_YSZBXH
);
END;
CREATE
OR
REPLACE
PROCEDURE 存储过程名称。 创建或替换存储过程sp_budget_share_build 存储过程名称
in_ysny 、in_gs 入参 默认值为null
msg code。 出参(out不能丢哦)
调用存储过程:
declare
msg VARCHAR2(4000);
code NUMBER;
BEGIN
-- 存储过程明(入参,入参,将变量传递进去 当作存储过程的out值,将变量传递进去 当作存储过程的out值)
sp_budget_share_build('2022-05',NULL, code, msg);
dbms_output.put_line( '--' || code || '---' || msg);
end;
查看存储过程(TEST_FUNCTION为存储过程名称):
SELECT
text
FROM
user_source
WHERE
NAME = 'TEST_FUNCTION'
ORDER BY
line
删除存储过程:
DROP PROCEDURE 存储过程名称