文档中心MogDBMogDB StackUqbar
v5.0

文档:v5.0

支持的版本:

其他版本:

视图增加%rowtype属性

可获得性

本特性自MogDB 5.0.0版本开始引入。

特性简介

本特性为视图增加%rowtype属性,支持作为参数或变量。使用%ROWTYPE来声明一个与视图相匹配的变量时,该变量将拥有与视图行相同的结构。

客户价值

增强MogDB与Oracle的兼容性,减少应用程序的迁移代价。

语法描述

CREATE PROCEDURE pro_name (input IN view_name%rowtype) IS
BEGIN
...
END;

示例

MogDB=# DROP SCHEMA IF EXISTS test_view_sch;
NOTICE: SCHEMA "test_view_sch" does NOT exist, skipping

MogDB=# CREATE SCHEMA test_view_sch;

MogDB=# CREATE TABLE test_view_sch.tb_test (c1 INT, c2 varchar2);

MogDB=# CREATE VIEW test_view_sch.v_terst AS SELECT c1, c2 FROM test_view_sch.tb_test;

MogDB=# CREATE OR REPLACE PROCEDURE sp_p1 (i_proname IN test_view_sch.v_terst%rowtype) IS
BEGIN
  RAISE NOTICE 'i_proname.c1 is %, i_proname.c2 is %', i_proname.c1, i_proname.c2;
END;
/
CREATE PROCEDURE

MogDB=# DECLARE 
var1 test_view_sch.v_terst%rowtype := (1111, 'xxxx');
BEGIN
sp_p1(i_proname => var1);
END;
/
NOTICE:  i_proname.c1 is 1111, i_proname.c2 is xxxx
ANONYMOUS BLOCK EXECUTE

MogDB=# DROP SCHEMA test_view_sch CASCADE;
NOTICE:  drop cascades to 3 other objects
DETAIL:  drop cascades to table test_view_sch.tb_test
drop cascades to view test_view_sch.v_terst
drop cascades to function sp_p1(test_view_sch.v_terst)
DROP SCHEMA
Copyright © 2011-2024 www.enmotech.com All rights reserved.