Home > Database > Mysql Tutorial > PL/SQL 中Returning Into的用法_MySQL

PL/SQL 中Returning Into的用法_MySQL

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2016-05-30 17:09:48
Original
1901 people have browsed it

ORACLE的DML语句中可以指定RETURNING INTO语句。RETURNING INTO语句的使用在很多情况下可以简化PL/SQL编程,少一次select into语句。

DELETE操作:RETURNING返回的是DELETE之前的结果;
 

INSERT操作:RETURNING返回的是INSERT之后的结果;
 

UPDATE操作:的RETURNING语句是返回UPDATE操作之后的结果。

 

-- Created on 2015/11/5 星期四 by YANCONG-ZHANG
-- Returning的用法
DECLARE
    -- Local variables here
    i       INTEGER;
    l_tid   NUMBER;
    l_tname VARCHAR2(200);
    l_tage  NUMBER;

BEGIN
    -- Test statements here
    --返回要插入的数据
    INSERT INTO zyc
    VALUES
        (4, 'wy', 20)
    RETURNING tid, tname, tage INTO l_tid, l_tname, l_tage;
    dbms_output.put_line(l_tid || '-' || l_tname || '-' || l_tage);

    --返回要删除的数据
    DELETE zyc
     WHERE tid = 1
    RETURNING tid, tname, tage INTO l_tid, l_tname, l_tage;
    dbms_output.put_line(l_tid || '-' || l_tname || '-' || l_tage);

    --返回要更新的数据
    UPDATE zyc
       SET tid = 5, tname = 'lwj', tage = 22
     WHERE tid = 2
    RETURNING tid, tname, tage INTO l_tid, l_tname, l_tage;
    dbms_output.put_line(l_tid || '-' || l_tname || '-' || l_tage);
    COMMIT;

END;
Copy after login

 


Related labels:
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Issues
sql file
From 1970-01-01 08:00:00
0
0
0
php - Overhead of prepare vs sql?
From 1970-01-01 08:00:00
0
0
0
Print sql statement
From 1970-01-01 08:00:00
0
0
0
Insert from CTE
From 1970-01-01 08:00:00
0
0
0
Pass array to SQL insert query using PHP
From 1970-01-01 08:00:00
0
0
0
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template