【问题标题】:how use procedure in oracle rest data servicesoracle rest数据服务中如何使用procedure
【发布时间】:2019-10-01 08:53:45
【问题描述】:

我有一个如下所示的 oracle 存储过程:

CREATE OR REPLACE PROCEDURE SABAPAY.omid (ttime OUT VARCHAR2,tYear OUT INTEGER, tMonth OUT INTEGER)
    IS
        year1 NUMBER;
        month1 VARCHAR2 (20);
        month2 NUMBER;
    BEGIN
        SELECT SPT.FISCAL_YEAR, SPT.PAY_MONTH
          INTO year1, month2
          FROM SABAPAY.PAY_TIMEBUCKET spt
         WHERE SPT.IS_CURRENT = '1';
        tyear := year1;
        tmonth := month2;
        ttime := year1 || '  ' || month2;
    END;

我想用 oracle rest 数据服务创建 web 服务。 我该如何为此创建模块? 我用下面的脚本来做

BEGIN
    ORDS.define_service (p_module_name      => 'testmodule1',
                         p_base_path        => 'testmodule1/',
                         p_pattern          => 'tt/',
                         p_source_type      => 'plsql/block',
                         p_source           => 'DECLARE
    ttime    VARCHAR2 (200);
    tyear    INTEGER;
    tmonth   INTEGER;
BEGIN
    SABAPAY.omid (ttime, tYear, tMonth);

END;',
                         p_items_per_page   => 0);

    COMMIT;
END;

但是当我运行 url 时,我什么也没得到 我的 db 和 oracle rest 数据服务服务器是分开的

【问题讨论】:

    标签: oracle plsql oracle-ords


    【解决方案1】:

    你必须定义一个处理程序,而不仅仅是一个模块

    -- Generated by Oracle SQL Developer REST Data Services 19.2.1.247.2212
    -- Exported REST Definitions from ORDS Schema Version 19.3.0.b2541456
    -- Schema: HR   Date: Tue Oct 01 08:32:57 EDT 2019
    --
    BEGIN
      ORDS.ENABLE_SCHEMA(
          p_enabled             => TRUE,
          p_schema              => 'HR',
          p_url_mapping_type    => 'BASE_PATH',
          p_url_mapping_pattern => 'hr',
          p_auto_rest_auth      => FALSE);    
    
      ORDS.DEFINE_MODULE(
          p_module_name    => 'so_plsql',
          p_base_path      => '/so_plsql/',
          p_items_per_page =>  25,
          p_status         => 'PUBLISHED',
          p_comments       => NULL);      
      ORDS.DEFINE_TEMPLATE(
          p_module_name    => 'so_plsql',
          p_pattern        => 'do_nothing',
          p_priority       => 0,
          p_etag_type      => 'HASH',
          p_etag_query     => NULL,
          p_comments       => NULL);
      ORDS.DEFINE_HANDLER(
          p_module_name    => 'so_plsql',
          p_pattern        => 'do_nothing',
          p_method         => 'POST',
          p_source_type    => 'plsql/block',
          p_items_per_page =>  0,
          p_mimes_allowed  => '',
          p_comments       => NULL,
          -- your SABAPAY.omid (ttime, tYear, tMonth); codes goes here
          p_source         => 
    'begin
     do_nothing();
    end;'
          );
    
    
      COMMIT; 
    END;
    

    我将其实现为我的 HTTP 调用的 POST 处理程序,因为我不确定您的存储过程做了什么 - 如果它对您的系统进行任何更改,它可能不应该是 GET。

    如果不是 GET,则需要在测试时使用 cURL 或 POSTMAN (GUI) 进行 POST 调用。

    我有更多示例here

    【讨论】:

      猜你喜欢
      • 2015-07-23
      • 2017-05-25
      • 2021-02-12
      • 1970-01-01
      • 2015-09-16
      • 1970-01-01
      • 1970-01-01
      • 2021-01-22
      • 1970-01-01
      相关资源
      最近更新 更多