• OkayAPI Docs
  • Login
  • Try for free



YesApi 接口文档

5201 执行查询类的存储过程

接口路径(新):http://api.okayapi.com/api/App/DB_MsSQL_Proc/QueryProc

接口路径(旧):http://api.okayapi.com/?s=App.DB_MsSQL_Proc.QueryProc

接口描述: 在sql server中,执行预先定义的查询类存储过程。此类查询操作,只会进行数据的查询,不会进行数据的修改。最后返回查询的报表、数据或结果。

API Params

ParameterTypeRequiredDefaultNoteDescription
HTTP_APPKEYStringRequiredMIN: 32Common Put Your APPKEY
db_markStringRequired直连数据库代号,注意!这是开发者添加的数据库代号,不是数据库的名称。使用API前请先添加新数据库连接配置。
proc_nameStringRequiredMIN: 1存储过程的名称,对应create proc [过程名称]。
pro_paramsArrayJSON FormatOptaion[]存储过程的参数,没有时可不传。JSON格式,key对应参数名称,参数名称不需要在前面加@符号,注意参数类型(支持:字符串/整型/浮点型/NULL),只支持一级参数。例如:{"name":"YesApi","quantity":666,"parent_id":null}

API Usage Demo

HTTP
假设原来有数据:
1> use TestDB;
2> go
Changed database context to 'TestDB'.
1> select * from TestTable ;
2> go
id          name                                               quantity    parent_id   is_used    
----------- -------------------------------------------------- ----------- ----------- -----------
          4 小白V6hxh                                                     27        NULL           1
          5 小白接口V5hxh                                                  674           0           0
          6 小白V8hxh                                                     19           4           0
          7 小白V8hxh                                                     20           4           0
          8 小白V8hxh                                                    131           0           0
          9 小白接口V5hxh                                                  131           8           0
          10 小白接口V5hxh                                                   10           8           0
          13 中文123abc                                                    10        NULL           0
          14 中文123abc                                                    10        NULL           0
          15 中文123abc                                                    10        NULL           0

(10 rows affected)

并且预先定义了以下存储过程:
1> create proc sum_quantity_func
2> @start_quantity INT,
3> @end_quantity INT
4> as
5> begin
6>     select sum(quantity) AS total from TestTable where quantity>=@start_quantity and quantity<=@end_quantity
7> end
8> go

请求接口:
{OKAYAPI_API_HOST}/?s=App.DB_MsSQL_Proc.QueryProc&db_mark=db_test&proc_name=sum_quantity_func&pro_params={"start_quantity":10,"end_quantity":20}&app_key={你的app_key}&sign={动态签名}

返回:
{
    "ret": 200,
    "data": {
        "err_code": 0,
        "err_msg": "",
        "result": [
        {
            "total": "79"
        }
        ]
    },
    "msg": "V1.5.0 小白开放接口 App.DB_MsSQL_Proc.QueryProc"
}

API Response

KEYTypeDescription
err_codeInt操作状态码,0成功,1失败
err_msgString错误提示信息,err_code非0时参考此提示信息
resultArray正常时,返回结果集数组。失败时返回null。

YesApi 接口文档

5202 调用命令类的存储过程

接口路径(新):http://api.okayapi.com/api/App/DB_MsSQL_Proc/ExecProc

接口路径(旧):http://api.okayapi.com/?s=App.DB_MsSQL_Proc.ExecProc

接口描述: 在sql server中,执行预先定义的命令类存储过程。此类命令操作,会进行数据的修改、增加、删除等副作用的操作。最后返回操作后的结果。

API Params

ParameterTypeRequiredDefaultNoteDescription
HTTP_APPKEYStringRequiredMIN: 32Common Put Your APPKEY
db_markStringRequired直连数据库代号,注意!这是开发者添加的数据库代号,不是数据库的名称。使用API前请先添加新数据库连接配置。
proc_nameStringRequiredMIN: 1存储过程的名称,对应create proc [过程名称]。
pro_paramsArrayJSON FormatOptaion[]存储过程的参数,没有时可不传。JSON格式,key对应参数名称,参数名称不需要在前面加@符号,注意参数类型(支持:字符串/整型/浮点型/NULL),只支持一级参数。例如:{"name":"YesApi","quantity":666,"parent_id":null}

API Usage Demo

HTTP
假设原来有数据:
1> select * from TestTable where parent_id=6 or parent_id=5;
2> go
id          name                                               quantity    parent_id   is_used    
----------- -------------------------------------------------- ----------- ----------- -----------
          6 小白V8hxh                                                     19           5           0
          7 小白V8hxh                                                     20           5           0

(2 rows affected)

预先定义更新parent_id的存储过程为:
1> create proc update_parent_id_func
2> @new_parent_id INT,
3> @old_parent_id INT
4> as
5> begin
6>     update TestTable set parent_id=@new_parent_id where parent_id=@old_parent_id
7> end
8> go

请求:
{OKAYAPI_API_HOST}/?s=App.DB_MsSQL_Proc.ExecProc&db_mark=db_test&proc_name=update_parent_id_func&pro_params={"new_parent_id":6,"old_parent_id":5}&app_key={你的app_key}&sign={动态签名}

返回:
{
    "ret": 200,
    "data": {
        "err_code": 0,
        "err_msg": "",
        "result": 2
    },
    "msg": "V1.5.0 小白开放接口 App.DB_MsSQL_Proc.ExecProc"
}

重新查询:
1> select * from TestTable where parent_id=6 or parent_id=5;
2> go
id          name                                               quantity    parent_id   is_used    
----------- -------------------------------------------------- ----------- ----------- -----------
          6 小白V8hxh                                                     19           6           0
          7 小白V8hxh                                                     20           6           0

(2 rows affected)

API Response

KEYTypeDescription
err_codeInt操作状态码,0成功,1失败
err_msgString错误提示信息,err_code非0时参考此提示信息
affected_rowsInt正常时,返回影响的行数。失败时返回0。

Power by OkayAPI.com Contact us (WA: okayapi OR Email: chanzonghuang@gmail.com).
Timezone: America/New_York May/10/2025 04:53:56