当前位置:网站首页>Study notes 22/1/18
Study notes 22/1/18
2022-06-28 07:44:00 【Zeiyalo】
Learning notes
One 、 Block code
1. conditional (if else)
- Grammatical structure
IF Conditions 1 THEN
operation 1;
ELSIF Conditions 2 THEN
operation 2;
ELSIF Conditions 3 THEN
operation 3;
...
ELSE operation N;
END IF;
eg: Pass in an employee's job number if the employee's The position is ANALYST perhaps CLERK perhaps SALESMAN Just give the staff 500 Block salary if the employee's Position MANAGER , Just give the staff 800 Block salary if it is PRESIDENT , Don't worry , Do nothing ;
CREATE TABLE EMP_7521 AS SELECT * FROM EMP;
-- Create a new table , prevent emp The data in the table has been changed
DECLARE
V_ENO EMP_7521.EMPNO%TYPE := 7521;
V_JOB EMP_7521.JOB%TYPE;
BEGIN
SELECT E.JOB
INTO V_JOB
FROM EMP_7521 E
WHERE E.EMPNO = V_ENO;
IF V_JOB IN('ANALYST' , 'LERK' , 'SALESMAN') THEN
UPDATE EMP_7521 E SET E.SAL = E.SAL + 500
WHERE E.EMPNO = V_ENO;
ELSIF V_JOB = 'MANAGER' THEN
UPDATE EMP_7521 E SET E.SAL = E.SAL + 500
WHERE E.EMPNO = V_ENO;
END IF;
/* CASE WHEN V_JOB IN('ANALYST' , 'LERK' , 'SALESMAN') THEN UPDATE EMP_7521 E SET E.SAL = E.SAL + 500 WHERE E.EMPNO = V_ENO; WHEN V_JOB = 'MANAGER' THEN UPDATE EMP_7521 E SET E.SAL = E.SAL + 500 WHERE E.EMPNO = V_ENO; END CASE; */
-- CASE WHEN It can do the same thing
COMMIT;
END;
SELECT * FROM EMP_7521; -- Used to view the modified table
2.if else Nesting of clauses
There's nothing to say in this part , It's just a set in a set and it's over .
3. loop
(1)for loop
Grammatical structure :
FOR Loop variable IN Cycle lower limit .. Cycle upper limit LOOP
-- Loop variables can use any letter or word
The loop body ( Logic to repeat )
END LOOP;
eg: Calculation 1 To 10 The cumulative value of an even number in a number ;
DECLARE
V_SUM NUMBER := 0;
BEGIN
FOR I IN 1..10 LOOP
IF MOD(I,2) = 0 THEN
V_SUM := V_SUM + I;
DBMS_OUTPUT.put_line(V_SUM);
END IF;
END LOOP;
DBMS_OUTPUT.put_line(' Cumulative value :'||V_SUM);
END;
PS: There is a problem in the above question , I found the = As the difference between assignment and comparison , When = For comparison , It is used alone or added later any、all Other key words , But when it is used for assignment , You have to use := Assign values to the style of , Use it directly = Assignment in PLSQL It's not allowed in ;
(2)loop loop
Grammatical structure :
LOOP
The loop body ;
-- EXIT Exit circular keyword
/*IF Exit conditions THEN EXIT;*/
EXIT WHEN Exit conditions ;
END LOOP;
eg: Calculation 1 To 10 The cumulative value of (LOOP loop );
DECLARE
V_SUM NUMBER := 0;
V_I NUMBER := 1;
BEGIN
LOOP
V_SUM := V_SUM + V_I;
/*IF V_I = 10 THEN EXIT; END IF;*/
-- use if Statement exit loop loop
EXIT WHEN V_I = 10;
V_I := V_I + 1;
END LOOP;
DBMS_OUTPUT.put_line(V_SUM);
END;
eg: Calculation 1 To 10 The cumulative value of an even number in a number (LOOP loop );
DECLARE
V_SUM NUMBER := 0;
V_I NUMBER := 1;
BEGIN
LOOP
IF MOD(V_I,2) = 0 THEN
V_SUM := V_SUM + V_I;
END IF;
EXIT WHEN V_I = 10;
V_I := V_I + 1;
END LOOP;
DBMS_OUTPUT.put_line(V_SUM);
END;
(3)while loop
Grammatical structure :
WHILE Conditions for entering the cycle LOOP
The loop body ;
END LOOP;
eg: Calculation 1 To 10 The cumulative value of (while loop );
DECLARE
V_SUM NUMBER := 0;
V_I NUMBER := 1;
BEGIN
WHILE V_I <= 10 LOOP
V_SUM := V_SUM + V_I;
V_I := V_I + 1;
END LOOP;
DBMS_OUTPUT.put_line(V_SUM);
END;
eg: Calculation 1 To 10 The cumulative value of an even number in a number (while loop );
DECLARE
V_SUM NUMBER := 0;
V_I NUMBER := 1;
BEGIN
WHILE V_I <= 10 LOOP
IF MOD(V_I,2) = 0 THEN
V_SUM := V_SUM + V_I;
END IF;
V_I := V_I + 1;
END LOOP;
DBMS_OUTPUT.put_line(V_SUM);
END;
eg; Calculation 1 To 100 The cumulative value of prime numbers of ;
DECLARE
V_SUM NUMBER := 0; -- Prime and
V_POW NUMBER; -- Radical v_i, Used as a judgment condition
V_I NUMBER := 2; -- from 1~100 Count variables for
V_J NUMBER := 2; -- from 2~v_pow Count variables for
V_FLAG NUMBER := 0; -- Whether it is a prime number
BEGIN
LOOP
V_POW := POWER(V_I,0.5);
WHILE V_J <= V_POW LOOP -- V_J Should be less than v_i Square root
IF MOD(V_I,V_J) = 0 THEN
V_FLAG := 1;
EXIT; -- If you can divide , Not primes ,flag Set up 1, Exit inner loop
END IF;
V_J := V_J + 1; -- If it's not divisible ,v_j Cycle after self increase
END LOOP;
V_J := 2; -- Prepare for the next cycle
IF V_FLAG = 0 THEN
V_SUM := V_SUM + V_I;
DBMS_OUTPUT.put_line(V_SUM);
DBMS_OUTPUT.put_line(V_I);
DBMS_OUTPUT.put_line('----------------------');
-- If v_flag zero , It's prime number , Add to v_sum In the middle
ELSE V_FLAG := 0; -- If not zero , take flag Zeroing
END IF;
V_I := V_I + 1;
EXIT WHEN V_I > 100;
END LOOP;
DBMS_OUTPUT.put_line('0~100 The sum of prime numbers of is :'||V_SUM);
END;
SELECT POWER(4,0.5)
FROM DUAL;
- There is still a problem with this question , But I really don't understand , Why, logically 4 Obviously will not be added , But it will be judged as a prime number for accumulation ;
eg: multiplication table ;
DECLARE
V_MUL NUMBER;
V_I NUMBER := 1;
V_J NUMBER := 1;
BEGIN
WHILE V_I <= 9 LOOP
V_J := 1;
WHILE V_J <= V_I LOOP
V_MUL := V_I * V_J;
DBMS_OUTPUT.put(V_J||'*'||V_I||'='||V_MUL||'|');
V_J := V_J + 1;
END LOOP;
DBMS_OUTPUT.put_line(' ');
V_I := V_I + 1;
END LOOP;
END;
Finishing work , The king of the new season , Go back to the glory of the king .
边栏推荐
- 8 figures | analyze Eureka's first synchronization registry
- golang gin框架进行分块传输
- Ice - resources
- Drawing animated bubble chart with R language
- Porting ucosiii to stm32f429
- Software design of resistance test board
- The solution of "user account control to continue, please enter administrator user name and password" appears in win10 Professional Edition
- Idea package together, using compact middle packages to solve &
- 腾讯下半年继续裁员,所有事业群至少缩减 10%,对此你怎么看?关注者
- Investment transaction and settlement of the fund
猜你喜欢

Uninstall and reinstall the latest version of MySQL database. The test is valid

软件测试与质量期末复习
![[ thanos源码分析系列 ]thanos query组件源码简析](/img/e4/2a87ef0d5cee0cc1c1e1b91b6fd4af.png)
[ thanos源码分析系列 ]thanos query组件源码简析

ES6 use of return in arrow function

Solving the longest palindrome substring by dynamic programming

扩展Prometheus的解决方案thanos的简介和几个月使用心得

flex布局

Modifying MySQL user name root under Linux

安全培训是员工最大的福利!2022新员工入职安全培训全员篇

Mysql57 zip file installation
随机推荐
Helloword routine for ROS
Source code analysis of kubernetes' process of deleting pod
PLC -- Notes
Localization SoC development plan
Code submission specification
Modifying MySQL user name root under Linux
ACM notes
Evaluation of inverse Polish expression < difficulty coefficient >
7-2 Finnish wooden chess structure Sorting
linux下修改mysql用户名root
大型项目中的Commit Message规范化控制实现
Ice - resources
Mysql57 zip file installation
ABAP skill tree
异或的应用。(提取出数字中最右侧的1,面试中经常用的到)
打新债注册开户靠谱吗?安全吗?
2021 programming language ranking summary
HJ质数因子
Mysql8.0 and mysql5.0 accessing JDBC connections
阿里云服务器创建快照、回滚磁盘