Compare the data in a table with the input parameters in Oracle and perform corresponding operations (stored procedure)

Source: Internet
Author: User


In Oracle, compare the data in a table with the input parameters, and perform corresponding operations (Stored Procedures) in Oracle. in Oracle, compare the input data in a table. http://topic.csdn.net/u/20120712/14/7ff39445-a8bc-46fd-a984-64114b2c8e90.html?94669 Table has a number field. The Stored Procedure test has a variable x. \ If there are records y with fields a greater than x in table A, insert y records with fields a equal to x into table a. If field a does not have records greater than x, then all fields a are added with 100. Okay, go directly to the test data [SQL] SQL> select * from t; www.2cto.com A ---------- 1382.4 1920 1500 2975 1500 2850 2940 5000 1800 1320 1368 1560 selected 12 rows. SQL> create or replace procedure emp_test 2 (3 x number 4) www.2cto.com 5 is 6 v_a employee. salary % type; 7 v_count number; 8 I number; 9 begin 10 I: = 0; 11 select count (a) into v_count from t where a> x; 12 if v_count> 0 then 13 for I in 1 .. v_count loop 14 insert into t (a) values (x); 15 end loop; www.2cto.com 16 else 17 update t set a = a + 100; 18 end if; 19 end; 20/the process has been created. The SQL> exec emp_test (9000) PL/SQL process has been completed successfully. SQL> select * from t; A ---------- 1482.4 2020 1600 3075 1600 2950 3040 5100 1900 1420 1468 1660 12 rows have been selected. The SQL> exec emp_test (3000) PL/SQL process has been completed successfully. SQL> select * from t; www.2cto.com A ---------- 1482.4 2020 1600 3075 1600 2950 3040 5100 1900 1420 1468 1660 3000 3000 3000 select 15 rows. Prepared by szstephen Zhou

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.