简体   繁体   English

从SQL集创建存储过程-Oracle

[英]Create stored procedure from set of SQL - Oracle

I have a set of SQL like and I would like to convert it to function or a stored procedure in an automated way: 我有一组类似的SQL,并且希望将其自动转换为函数或存储过程:

create table test as
select * from test1;

DELETE FROM test
WHERE
    e_id LIKE '%00-01';



MERGE INTO test tgt USING (
  SELECT 
    LISTAGG(e_val, ':') WITHIN GROUP(
      ORDER BY 
        e_id
    ) OVER(PARTITION BY unique_id, line) e_val, 
    CASE WHEN e_id IN ('BHT03-02', 'BHT03-03') THEN 'Y' ELSE 'N' END del 
  FROM 
    test 
  WHERE 
    e_id IN (
      'ABC03-01'
    )
) src ON (
  tgt.unique_id = src.unique_id 
  AND tgt.line = src.line 
  AND tgt.e_id = src.e_id
)
WHEN MATCHED THEN 
UPDATE 
SET 
  tgt.e_value = src.e_value DELETE 
WHERE 
  src.del = 'Y';

Is there any easy way of creating a stored procedure or function using this? 有没有使用此方法创建存储过程或函数的简便方法?

You can just enclose this code between procedure definition 您可以将这些代码放在过程定义之间

example

create or replace procedure do_some_work
as

begin
  --paste your code here;
end;

you can run this procedure by calling it : 您可以通过调用以下程序来运行此过程:

EXEC do_some_work;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM