ORACLE creates multiple cursors and nested loops

Source: Internet
Author: User
Tags testq

ORACLE needs to create multiple cursors and nested loops: The data of cursor 1 is traversed each time the record of cursor 2 is traversed, insert the temporary table create or replace procedure testq is DownDictate VARCHAR2 (200) DEFAULT ''; t_IsExist NUMBER: = 0; use_DownDictate VARCHAR2 (200) DEFAULT ''; BEGIN -- determines whether the command will be wrong select downdictate into DownDictate FROM T_MS_AUTOPLANDICTATE where procedurename = 'pkg _ medi_imm.query_medi_imm'; IF DownDictate is null then return; END IF; -- start to define the cursor declare --- define the CURSOR 1 CURSOR C_PARAMETERS is select functionnodecode, functionnodename from T_MS_FUNCTIONNODES where functionid = (select functionid from T_MS_FUNCTION where functionproce = 'pkg _ parameter '); --- define the CURSOR 2 CURSOR C_MEDIIMME is select * FROM (select. GRANTMASTER_BARCODE,. GRANTMASTER_DATE, B. UNITINFO_NAME, C. USERINFO_REALNAME FROM T_LABEL_GRANTMASTER a left outer join T_ER_UNITINFO B ON. GRANTMASTER_FARMID = B. UNITINFO_ID left outer join T_SYS_USERINFO c on. GRANTMASTER_FARMERSID = C. USERINFO_ID where c. USERINFO_MOBILE is not null or c. USERINFO_PHONE is not null) T; -- defines the row TYPE paraType is record (code VARCHAR2 (20), codecn VARCHAR2 (50); paraRowType paraType; --- define the row TYPE rtype is record (yzpch VARCHAR2 (50), g_date DATE, yzc VARCHAR2 (100), yznh VARCHAR2 (50); c_rtype rtype; -- start to execute begin open C_MEDIIMME; -- OPEN the cursor 2 loop fetch C_MEDIIMME INTO c_rtype; exit when C_MEDIIMME % NOTFOUND; use_DownDictate: = DownDictate; OPEN C_PARAMETERS; -- open cursor 1 (WHEN you need to traverse a piece of data in cursor 2, open cursor 1) -- traverse the parameter table begin loop fetch C_PARAMETERS INTO paraRowType; exit when C_PARAMETERS % NOTFOUND; IF paraRowType. code = 'yzpch' THEN use_DownDictate: = REPLACE (use_DownDictate, paraRowType. codecn | '#', c_rtype.yzpch); ELSIF paraRowType. code = 'yz2' THEN use_DownDictate: = REPLACE (use_DownDictate, paraRowType. codecn | '#', c_rtype.yznh); ELSIF paraRowType. code = 'yzc' THEN use_DownDictate: = REPLACE (use_DownDictate, paraRowType. codecn | '#', c_rtype.yzc); end if; end loop; END; CLOSE C_PARAMETERS; -- CLOSE cursor 1 -- INSERT temporary table insert into T_MEDIIMMETABLE (ReplaceResult, DateResult) VALUES (use_DownDictate, c_rtype.g_date); end loop; CLOSE C_MEDIIMME; -- CLOSE cursor 2 END; end testq;

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.