Oracle数据库----第七周实验____循环与游标

news2024/11/17 17:43:16

目录

Oracle数据库----第七周实验

循环与游标


Oracle数据库----第七周实验


循环与游标

循环与游标
	循环
	首先设置显示输出结果

Connected to Oracle Database 10g Enterprise Edition Release 10.2.0.3.0 
Connected as system@ORCL
SQL> set serveroutput on;
1.简单循环
例9-11.利用简单循环求1-100之间偶数的和。
SQL> 
SQL> declare
  2    v_counter binary_integer :=1;
  3    v_sum number :=0;
  4  begin
  5    loop
  6      if mod(v_counter,2)=0 then
  7      v_sum:=v_sum+v_counter;
  8      end if;
  9      v_counter :=v_counter +1;
 10      exit when v_counter>100;
 11    end loop;
 12    dbms_output.put_line(v_sum);
 13  end;
 14  
 15  /
2550
PL/SQL procedure successfully completed
SQL>
2.while循环

SQL> 
SQL> declare
  2    v_counter binary_integer :=1;
  3    v_sum number :=0;
  4  begin
  5    while v_counter<100 loop
  6    if mod(v_counter,2)=0 then
  7    v_sum :=v_sum+v_counter;
  8    end if;
  9    v_counter:=v_counter+1;
 10    end loop;
 11    Dbms_Output.put_line(v_sum);
 12  end;
 13  /
2450
PL/SQL procedure successfully completed
3.for循环
SQL> 
SQL> declare
  2  v_sum number :=0;
  3  begin
  4    for v_counter in 1..100 loop
  5      if mod(v_counter,2)=0 then
  6        v_sum :=v_sum+v_counter;
  7        end if;
  8        end loop;
  9        Dbms_Output.put_line(v_sum);
 10  end;
 11  /
 运行结果:
2550
 
PL/SQL procedure successfully completed
4跳转结构
先创建一个表:
temp_table

create table temp_table
(
   v_counter varchar2(255),
   v_sum varchar2(255)
)


SQL> 
SQL> create table temp_table
  2  (
  3     v_counter varchar2(255),
  4     v_sum varchar2(255)
  5  )
  6  /
 
Table created
 
SQL> 
SQL> declare
  2    v_counter binary_integer :=1;
  3  begin
  4    <<label>>
  5    insert into temp_table values(v_counter,'loop index');
  6    v_counter :=v_Counter+1;
  7    if v_counter<=50 then
  8      goto label;
  9      end if;
 10  end;
 11  /
 
PL/SQL procedure successfully completed
 
SQL>
	游标
【9-15】
例9-15.根据输入的部门号查询某个部门的员工信息,部门号在程序运行时指定。
SQL> 
SQL> declare
  2    v_deptno hr.employees.department_id%type;
  3    cursor c_emp is select * from hr.employees where department_id=v_deptno;
  4    v_emp c_emp%rowtype;
  5  begin
  6    v_deptno :=&x;
  7    open c_emp;
  8    loop
  9      fetch c_emp into v_emp;
 10      exit when c_emp%notfound;
 11      dbms_output.put_line(v_emp.employee_id||' '||v_emp.first_name||' '||v_emp.last_name||' '||v_emp.salary||' '||v_deptno);
 12    end loop;
 13    close c_emp;
 14  end;
 15  /
弹出输入框:
输入x的值:100
则, 运行结果为:
108 Nancy Greenberg 12000 100
109 Daniel Faviet 9000 100
110 John Chen 8200 100
111 Ismael Sciarra 7700 100
112 Jose Manuel Urman 7800 100
113 Luis Popp 6900 100
 
PL/SQL procedure successfully completed
SQL>

【9-16】
利用简单循环统计并输出各个部门的平均工资

SQL> 
SQL> declare
  2   cursor c_dept_stat is
  3   select hr.employees.department_id,avg(hr.employees.salary) avgsal from hr.employees group by
  4   department_id;
  5   v_dept c_dept_stat%rowtype;
  6   begin
  7     open c_dept_stat;
  8     loop
  9       fetch c_dept_stat into  v_dept;
 10       exit when c_dept_stat%notfound;
 11       Dbms_Output.put_line(v_dept.department_id||' '||v_dept.avgsal);
 12       end loop;
 13       close c_dept_stat;
 14       end;
 15  /
运行结果:

100 8600
30 4150
 7000
20 9500
70 10000
90 19333.3333333333333333333333333333333333
110 10150
50 3475.555555555555555555555555555555555556
40 6500
80 8955.882352941176470588235294117647058824
10 4400
60 5760
 
PL/SQL procedure successfully completed
 
SQL>

【9-17】
利用WHILE循环统计并输出各个部门的平均工资
SQL> 
SQL> declare
  2   cursor c_dept_stat is
  3   select hr.employees.department_id,avg(hr.employees.salary) avgsal from hr.employees group by
  4   department_id;
  5   v_dept c_dept_stat%rowtype;
  6   begin
  7     open c_dept_stat;
  8       fetch c_dept_stat into  v_dept;
  9       while c_dept_stat%found loop
 10       Dbms_Output.put_line(v_dept.department_id||' '||v_dept.avgsal);
 11       fetch c_dept_stat into  v_dept;
 12     end loop;
 13     close c_dept_stat;
 14  end;
 15  /
 
100 8600
30 4150
 7000
20 9500
70 10000
90 19333.3333333333333333333333333333333333
110 10150
50 3475.555555555555555555555555555555555556
40 6500
80 8955.882352941176470588235294117647058824
10 4400
60 5760
 
PL/SQL procedure successfully completed
 
SQL>
【9-18】
利用FOR循环统计并输出各个部门的平均工资
SQL> 
SQL> declare
  2   cursor c_dept_stat is
  3   select hr.employees.department_id,avg(hr.employees.salary) avgsal from hr.employees group by
  4   department_id;
  5   v_dept c_dept_stat%rowtype;
  6   begin
  7     FOR v_dept IN (
  8       select hr.employees.department_id,avg(hr.employees.salary) avgsal from hr.employees group by
  9   department_id
 10       ) LOOP
 11       Dbms_Output.put_line(v_dept.department_id||' '||v_dept.avgsal);
 12     end loop;
 13  end;
 14  /
 
100 8600
30 4150
 7000
20 9500
70 10000
90 19333.3333333333333333333333333333333333
110 10150
50 3475.555555555555555555555555555555555556
40 6500
80 8955.882352941176470588235294117647058824
10 4400
60 5760
 
PL/SQL procedure successfully completed
 
SQL>

测试全程代码

Connected to Oracle Database 10g Enterprise Edition Release 10.2.0.3.0 
Connected as system@ORCL
 
SQL> set serveroutput on;
SQL> 
SQL> DECLARE
  2  v_counter BINARY_INTEGER :=1;
  3  v_sum NUMBER :=0;
  4  BEGIN
  5    LOOP
  6      IF mod(v_counter,2)=0 THEN
  7        v_sum :=v_sum+v_counter
  8    END IF
  9    v_counter :=v_counter+1;
 10    EXIT WHEN v_counter>100;
 11    END LOOP
 12    DBMS_OUTPUT.PUT_LINE(v_sum);
 13  END;
 14  
 15  /
 
DECLARE
v_counter BINARY_INTEGER :=1;
v_sum NUMBER :=0;
BEGIN
  LOOP
    IF mod(v_counter,2)=0 THEN
      v_sum :=v_sum+v_counter
  END IF
  v_counter :=v_counter+1;
  EXIT WHEN v_counter>100;
  END LOOP
  DBMS_OUTPUT.PUT_LINE(v_sum);
END;
 
ORA-06550: 第 9 行, 第 3 列: 
PLS-00103: 出现符号 "END"在需要下列之一时:
 . ( * @ % & = - + ; < / >
   at in is mod remainder not rem <an exponent (**)>
   <> or != or ~= >= <= <> and or like LIKE2_ LIKE4_ LIKEC_
   between || member SUBMULTISET_
 
SQL> 
SQL> DECLARE
  2  v_counter BINARY_INTEGER :=1;
  3  v_sum NUMBER :=0;
  4  BEGIN
  5    LOOP
  6      IF mod(v_counter,2)=0 THEN
  7        v_sum :=v_sum+v_counter
  8    END IF;
  9    v_counter :=v_counter+1;
 10    EXIT WHEN v_counter>100;
 11    END LOOP
 12    DBMS_OUTPUT.PUT_LINE(v_sum);
 13  END;
 14  /
 
DECLARE
v_counter BINARY_INTEGER :=1;
v_sum NUMBER :=0;
BEGIN
  LOOP
    IF mod(v_counter,2)=0 THEN
      v_sum :=v_sum+v_counter
  END IF;
  v_counter :=v_counter+1;
  EXIT WHEN v_counter>100;
  END LOOP
  DBMS_OUTPUT.PUT_LINE(v_sum);
END;
 
ORA-06550: 第 9 行, 第 3 列: 
PLS-00103: 出现符号 "END"在需要下列之一时:
 . ( * @ % & = - + ; < / >
   at in is mod remainder not rem <an exponent (**)>
   <> or != or ~= >= <= <> and or like LIKE2_ LIKE4_ LIKEC_
   between || member SUBMULTISET_
符号 ";" 被替换为 "END" 后继续。
ORA-06550: 第 13 行, 第 14 列: 
PLS-00103: 出现符号 "."在需要下列之一时:
 ;
ORA-06550: 第 14 行, 第 1 列: 
PLS-00103: 出现符号 "END"
 
SQL> 
SQL> declare
  2    v_counter binary_integer :=1;
  3    v_sum number :=0;
  4  begin
  5    loop
  6      if mod(v_counter,2)=0 then
  7      v_sum:=v_sum+v_counter;
  8      end if;
  9      v_counter :=v_counter +1;
 10      exit when v_counter>100;
 11    end loop;
 12    dbms_output.put_line(v_sum);
 13  end;
 14  
 15  /
 
2550
 
PL/SQL procedure successfully completed
 
SQL> 
SQL> declare
  2    v_counter binary_integer :=1;
  3    v_sum number :=0;
  4  begin
  5    while v_counter<100 loop
  6    if mod(v_counter,2)=0 then;
  7    v_sum :=v_sum+v_counter;
  8    end if;
  9    v_counter:=v_counter+1;
 10    end loop;
 11    Dbms_Output.put_line(v_sum);
 12  end;
 13  /
 
declare
  v_counter binary_integer :=1;
  v_sum number :=0;
begin
  while v_counter<100 loop
  if mod(v_counter,2)=0 then;
  v_sum :=v_sum+v_counter;
  end if;
  v_counter:=v_counter+1;
  end loop;
  Dbms_Output.put_line(v_sum);
end;
 
ORA-06550: 第 7 行, 第 29 列: 
PLS-00103: 出现符号 ";"在需要下列之一时:
 begin case declare exit for
   goto if loop mod null pragma raise return select update while
   with <an identifier> <a double-quoted delimited-identifier>
   <a bind variable> << close current delete fetch lock insert
   open rollback savepoint set sql execute commit forall merge
   pipe
符号 "exit" 被替换为 ";" 后继续。
 
SQL> 
SQL> declare
  2    v_counter binary_integer :=1;
  3    v_sum number :=0;
  4  begin
  5    while v_counter<100 loop
  6    if mod(v_counter,2)=0 then
  7    v_sum :=v_sum+v_counter;
  8    end if;
  9    v_counter:=v_counter+1;
 10    end loop;
 11    Dbms_Output.put_line(v_sum);
 12  end;
 13  /
 
2450
 
PL/SQL procedure successfully completed
 
SQL> 
SQL> declare
  2  v_sum number :=0;
  3  begin
  4    for v_counter in 1..100 loop
  5      if mod(v_counter,2)=0 then
  6        v_sum=v_sum+v_counter;
  7        end if;
  8        end loop;
  9        Dbms_Output.put_line(v_sum);
 10  end;
 11  /
 
declare
v_sum number :=0;
begin
  for v_counter in 1..100 loop
    if mod(v_counter,2)=0 then
      v_sum=v_sum+v_counter;
      end if;
      end loop;
      Dbms_Output.put_line(v_sum);
end;
 
ORA-06550: 第 7 行, 第 12 列: 
PLS-00103: 出现符号 "="在需要下列之一时:
 := . ( @ % ;
ORA-06550: 第 8 行, 第 7 列: 
PLS-00103: 出现符号 "END"
 
SQL> 
SQL> declare
  2  v_sum number :=0;
  3  begin
  4    for v_counter in 1..100 loop
  5      if mod(v_counter,2)=0 then
  6        v_sum :=v_sum+v_counter;
  7        end if;
  8        end loop;
  9        Dbms_Output.put_line(v_sum);
 10  end;
 11  /
 
2550
 
PL/SQL procedure successfully completed
 
SQL> 
SQL> declare
  2    v_counter binary_integer :=1;
  3  begin
  4    <<label>>
  5    insert into temp_table values(v_counter,'loop index');
  6    v_counter :=v_Counter+1;
  7    if v_counter<=50 then
  8      goto label;
  9      enf if;
 10  end;
 11  /
 
declare
  v_counter binary_integer :=1;
begin
  <<label>>
  insert into temp_table values(v_counter,'loop index');
  v_counter :=v_Counter+1;
  if v_counter<=50 then
    goto label;
    enf if;
end;
 
ORA-06550: 第 10 行, 第 9 列: 
PLS-00103: 出现符号 "IF"在需要下列之一时:
 := . ( @ % ;
 
SQL> 
SQL> declare
  2    v_counter binary_integer :=1;
  3  begin
  4    <<label>>
  5    insert into temp_table values(v_counter,'loop index');
  6    v_counter :=v_Counter+1;
  7    if v_counter<=50 then
  8      goto label;
  9      end if;
 10  end;
 11  /
 
declare
  v_counter binary_integer :=1;
begin
  <<label>>
  insert into temp_table values(v_counter,'loop index');
  v_counter :=v_Counter+1;
  if v_counter<=50 then
    goto label;
    end if;
end;
 
ORA-06550: 第 6 行, 第 15 列: 
PL/SQL: ORA-00942: 表或视图不存在
ORA-06550: 第 6 行, 第 3 列: 
PL/SQL: SQL Statement ignored
 
SQL> 
SQL> create table temp_table
  2  (
  3     v_counter varchar2(255),
  4     v_sum varchar2(255)
  5  )
  6  /
 
Table created
 
SQL> 
SQL> declare
  2    v_counter binary_integer :=1;
  3  begin
  4    <<label>>
  5    insert into temp_table values(v_counter,'loop index');
  6    v_counter :=v_Counter+1;
  7    if v_counter<=50 then
  8      goto label;
  9      end if;
 10  end;
 11  /
 
PL/SQL procedure successfully completed
 
SQL> 
SQL> declare
  2  v_deptno hr.employees.department_id%type;
  3  cursor c_emp is select * from hr.employees where department_id=v_deptno;
  4  v_emp c_emp%rowtype;
  5  begin
  6    v_deptno :=&x;
  7    open c_emp;
  8    loop
  9       fetch c_emp into v_emp;
 10       exit when c_emp%notfound;
 11       Dbms_Output.put_line(v_emp.employees_id||''||v_emp.first_name||''||v_emp.last_name||''||v_emp.salary||' '||v_deptno);
 12       end loop;
 13       close c_emp;
 14  end;
 15  /
 
declare
v_deptno hr.employees.department_id%type;
cursor c_emp is select * from hr.employees where department_id=v_deptno;
v_emp c_emp%rowtype;
begin
  v_deptno :=10;
  open c_emp;
  loop
     fetch c_emp into v_emp;
     exit when c_emp%notfound;
     Dbms_Output.put_line(v_emp.employees_id||''||v_emp.first_name||''||v_emp.last_name||''||v_emp.salary||' '||v_deptno);
     end loop;
     close c_emp;
end;
 
ORA-06550: 第 12 行, 第 33 列: 
PLS-00302: 必须声明 'EMPLOYEES_ID' 组件
ORA-06550: 第 12 行, 第 6 列: 
PL/SQL: Statement ignored
 
SQL> 
SQL> declare
  2  v_deptno hr.employees.department_id%type;
  3  cursor c_emp is select * from hr.employees where department_id=v_deptno;
  4  v_emp c_emp%rowtype;
  5  begin
  6    v_deptno :=&x;
  7    open c_emp;
  8    loop
  9       fetch c_emp into v_emp;
 10       exit when c_emp%notfound;
 11       Dbms_Output.put_line(v_emp.employees_id||' '||v_emp.first_name||' '||v_emp.last_name||' '||v_emp.salary||' '||v_deptno);
 12       end loop;
 13       close c_emp;
 14  end;
 15  /
 
declare
v_deptno hr.employees.department_id%type;
cursor c_emp is select * from hr.employees where department_id=v_deptno;
v_emp c_emp%rowtype;
begin
  v_deptno :=100;
  open c_emp;
  loop
     fetch c_emp into v_emp;
     exit when c_emp%notfound;
     Dbms_Output.put_line(v_emp.employees_id||' '||v_emp.first_name||' '||v_emp.last_name||' '||v_emp.salary||' '||v_deptno);
     end loop;
     close c_emp;
end;
 
ORA-06550: 第 12 行, 第 33 列: 
PLS-00302: 必须声明 'EMPLOYEES_ID' 组件
ORA-06550: 第 12 行, 第 6 列: 
PL/SQL: Statement ignored
 
SQL> 
SQL> declare
  2    v_deptno hr.employees.department_id%type;
  3    cursor c_emp is select * from hr.employees where department_id=v_deptno;
  4    v_emp c_emp%rowtype;
  5  begin
  6    v_deptno :=&x;
  7    open c_emp;
  8    loop
  9      fetch c_emp into v_emp;
 10      exit when c_emp%notfound;
 11      dbms_output.put_line(v_emp.employee_id||' '||v_emp.first_name||' '||v_emp.last_name||' '||v_emp.salary||' '||v_deptno);
 12    end loop;
 13    close c_emp;
 14  end;
 15  /
 
108 Nancy Greenberg 12000 100
109 Daniel Faviet 9000 100
110 John Chen 8200 100
111 Ismael Sciarra 7700 100
112 Jose Manuel Urman 7800 100
113 Luis Popp 6900 100
 
PL/SQL procedure successfully completed
 
SQL> 
SQL> declare
  2  v_deptno hr.employees.department_id%type;
  3  cursor c_emp is select * from hr.employees where department_id=v_deptno;
  4  v_emp c_emp%rowtype;
  5  begin
  6    v_deptno :=&x;
  7    open c_emp;
  8    loop
  9       fetch c_emp into v_emp;
 10       exit when c_emp%notfound;
 11       Dbms_Output.put_line(v_emp.employee_id||' '||v_emp.first_name||' '||v_emp.last_name||' '||v_emp.salary||' '||v_deptno);
 12       end loop;
 13       close c_emp;
 14  end;
 15  
 16  /
 
PL/SQL procedure successfully completed
 
SQL> 
SQL> declare
  2   cursor c_dept_stat is
  3   select hr.employees.department_id,avg(hr.employees.salary) avgsal from hr.employees group by
  4   department_id;
  5   v_dept c_dept_stat%rowtype;
  6   begin
  7     open c_dept_stat;
  8     loop
  9       fetch c_dept_stat into  v_dept;
 10       exit when c_dept_stat%notfound;
 11       Dbms_Output.put_line(v_dept.department_id||' '||v_dept.avgsal);
 12       end loop;
 13       close c_dept_stat;
 14       end;
 15  /
 
100 8600
30 4150
 7000
20 9500
70 10000
90 19333.3333333333333333333333333333333333
110 10150
50 3475.555555555555555555555555555555555556
40 6500
80 8955.882352941176470588235294117647058824
10 4400
60 5760
 
PL/SQL procedure successfully completed
 
SQL> 
SQL> declare
  2   cursor c_dept_stat is
  3   select hr.employees.department_id,avg(hr.employees.salary) avgsal from hr.employees group by
  4   department_id;
  5   v_dept c_dept_stat%rowtype;
  6   begin
  7     open c_dept_stat;
  8       fetch c_dept_stat into  v_dept;
  9       while c_dept_stat%notfound;
 10       Dbms_Output.put_line(v_dept.department_id||' '||v_dept.avgsal);
 11       fetch c_dept_stat into  v_dept;
 12       end loop;
 13       close c_dept_stat;
 14       end;
 15  /
 
declare
 cursor c_dept_stat is
 select hr.employees.department_id,avg(hr.employees.salary) avgsal from hr.employees group by
 department_id;
 v_dept c_dept_stat%rowtype;
 begin
   open c_dept_stat;
     fetch c_dept_stat into  v_dept;
     while c_dept_stat%notfound;
     Dbms_Output.put_line(v_dept.department_id||' '||v_dept.avgsal);
     fetch c_dept_stat into  v_dept;
     end loop;
     close c_dept_stat;
     end;
 
ORA-06550: 第 10 行, 第 32 列: 
PLS-00103: 出现符号 ";"在需要下列之一时:
 . ( * @ % & = - + < / > at in
   is loop mod remainder not rem <an exponent (**)>
   <> or != or ~= >= <= <> and or like LIKE2_ LIKE4_ LIKEC_
   between || multiset member SUBMULTISET_
ORA-06550: 第 14 行, 第 6 列: 
PLS-00103: 出现符号 "CLOSE"在需要下列之一时:
 end not pragma final
   instantiable order overriding static member constructor map
ORA-06550: 第 17 行, 第 0 列: 
PLS-00103: 出现符号 "end-of-file"在需要下列之一时:
 pragma
 
SQL> 
SQL> declare
  2   cursor c_dept_stat is
  3   select hr.employees.department_id,avg(hr.employees.salary) avgsal from hr.employees group by
  4   department_id;
  5   v_dept c_dept_stat%rowtype;
  6   begin
  7     open c_dept_stat;
  8       fetch c_dept_stat into  v_dept;
  9       while c_dept_stat%found loop;
 10       Dbms_Output.put_line(v_dept.department_id||' '||v_dept.avgsal);
 11       fetch c_dept_stat into  v_dept;
 12     end loop;
 13     close c_dept_stat;
 14  end;
 15  /
 
declare
 cursor c_dept_stat is
 select hr.employees.department_id,avg(hr.employees.salary) avgsal from hr.employees group by
 department_id;
 v_dept c_dept_stat%rowtype;
 begin
   open c_dept_stat;
     fetch c_dept_stat into  v_dept;
     while c_dept_stat%found loop;
     Dbms_Output.put_line(v_dept.department_id||' '||v_dept.avgsal);
     fetch c_dept_stat into  v_dept;
   end loop;
   close c_dept_stat;
end;
 
ORA-06550: 第 10 行, 第 34 列: 
PLS-00103: 出现符号 ";"在需要下列之一时:
 begin case declare exit for
   goto if loop mod null pragma raise return select update while
   with <an identifier> <a double-quoted delimited-identifier>
   <a bind variable> << close current delete fetch lock insert
   open rollback savepoint set sql execute commit forall merge
   pipe
符号 "exit" 被替换为 ";" 后继续。
 
SQL> 
SQL> declare
  2   cursor c_dept_stat is
  3   select hr.employees.department_id,avg(hr.employees.salary) avgsal from hr.employees group by
  4   department_id;
  5   v_dept c_dept_stat%rowtype;
  6   begin
  7     open c_dept_stat;
  8       fetch c_dept_stat into  v_dept;
  9       while c_dept_stat%found loop
 10       Dbms_Output.put_line(v_dept.department_id||' '||v_dept.avgsal);
 11       fetch c_dept_stat into  v_dept;
 12     end loop;
 13     close c_dept_stat;
 14  end;
 15  /
 
100 8600
30 4150
 7000
20 9500
70 10000
90 19333.3333333333333333333333333333333333
110 10150
50 3475.555555555555555555555555555555555556
40 6500
80 8955.882352941176470588235294117647058824
10 4400
60 5760
 
PL/SQL procedure successfully completed
 
SQL> 
SQL> declare
  2   cursor c_dept_stat is
  3   select hr.employees.department_id,avg(hr.employees.salary) avgsal from hr.employees group by
  4   department_id;
  5   v_dept c_dept_stat%rowtype;
  6   begin
  7     FOR V_DEPT IN (
  8       select hr.employees.department_id,avg(hr.employees.salary) avgsal from hr.employees group by
  9   department_id;
 10       )LOOP
 11  
 12       Dbms_Output.put_line(v_dept.department_id||' '||v_dept.avgsal);
 13     end loop;
 14  end;
 15  /
 
declare
 cursor c_dept_stat is
 select hr.employees.department_id,avg(hr.employees.salary) avgsal from hr.employees group by
 department_id;
 v_dept c_dept_stat%rowtype;
 begin
   FOR V_DEPT IN (
     select hr.employees.department_id,avg(hr.employees.salary) avgsal from hr.employees group by
 department_id;
     )LOOP

     Dbms_Output.put_line(v_dept.department_id||' '||v_dept.avgsal);
   end loop;
end;
 
ORA-06550: 第 10 行, 第 15 列: 
PLS-00103: 出现符号 ";"在需要下列之一时:
 loop
 
SQL> 
SQL> declare
  2   cursor c_dept_stat is
  3   select hr.employees.department_id,avg(hr.employees.salary) avgsal from hr.employees group by
  4   department_id;
  5   v_dept c_dept_stat%rowtype;
  6   begin
  7     FOR V_DEPT IN (
  8       select hr.employees.department_id,avg(hr.employees.salary) avgsal from hr.employees group by
  9   department_id
 10       )LOOP
 11  
 12       Dbms_Output.put_line(v_dept.department_id||' '||v_dept.avgsal);
 13     end loop;
 14  end;
 15  /
 
declare
 cursor c_dept_stat is
 select hr.employees.department_id,avg(hr.employees.salary) avgsal from hr.employees group by
 department_id;
 v_dept c_dept_stat%rowtype;
 begin
   FOR V_DEPT IN (
     select hr.employees.department_id,avg(hr.employees.salary) avgsal from hr.employees group by
 department_id;
     )LOOP

     Dbms_Output.put_line(v_dept.department_id||' '||v_dept.avgsal);
   end loop;
end;
 
ORA-06550: 第 10 行, 第 15 列: 
PLS-00103: 出现符号 ";"在需要下列之一时:
 loop
 
SQL> 
SQL> declare
  2   cursor c_dept_stat is
  3   select hr.employees.department_id,avg(hr.employees.salary) avgsal from hr.employees group by
  4   department_id;
  5   v_dept c_dept_stat%rowtype;
  6   begin
  7     FOR V_DEPT IN (
  8       select hr.employees.department_id,avg(hr.employees.salary) avgsal from hr.employees group by
  9   department_id
 10       )LOOP
 11  
 12       Dbms_Output.put_line(v_dept.department_id||' '||v_dept.avgsal);
 13     end loop;
 14  end;
 15  /
 
declare
 cursor c_dept_stat is
 select hr.employees.department_id,avg(hr.employees.salary) avgsal from hr.employees group by
 department_id;
 v_dept c_dept_stat%rowtype;
 begin
   FOR V_DEPT IN (
     select hr.employees.department_id,avg(hr.employees.salary) avgsal from hr.employees group by
 department_id;
     )LOOP

     Dbms_Output.put_line(v_dept.department_id||' '||v_dept.avgsal);
   end loop;
end;
 
ORA-06550: 第 10 行, 第 15 列: 
PLS-00103: 出现符号 ";"在需要下列之一时:
 loop
 
SQL> 
SQL> declare
  2   cursor c_dept_stat is
  3   select hr.employees.department_id,avg(hr.employees.salary) avgsal from hr.employees group by
  4   department_id;
  5   v_dept c_dept_stat%rowtype;
  6   begin
  7     FOR v_dept IN (
  8       select hr.employees.department_id,avg(hr.employees.salary) avgsal from hr.employees group by
  9   department_id
 10       ) LOOP
 11       Dbms_Output.put_line(v_dept.department_id||' '||v_dept.avgsal);
 12     end loop;
 13  end;
 14  /
 
100 8600
30 4150
 7000
20 9500
70 10000
90 19333.3333333333333333333333333333333333
110 10150
50 3475.555555555555555555555555555555555556
40 6500
80 8955.882352941176470588235294117647058824
10 4400
60 5760
 
PL/SQL procedure successfully completed
 
SQL> 
SQL> declare
  2   cursor c_dept_stat is
  3   select hr.employees.department_id,avg(hr.employees.salary) avgsal from hr.employees group by
  4   department_id;
  5   v_dept c_dept_stat%rowtype;
  6  begin
  7    update hr.employees set hr.employees.salary=salary+100 where employee_id=1000;
  8    if sql%notfound then
  9      insert into hr.employees(emploee_id,first_name,last_name,email,hire_date,job_id,department_id)values (employees_seq.nextval,'san','zhang','zs@neusoft.edu.cn',sysdate,'AC_ACCOUNT',200);
 10      end if;
 11      end;
 12  /
 
declare
 cursor c_dept_stat is
 select hr.employees.department_id,avg(hr.employees.salary) avgsal from hr.employees group by
 department_id;
 v_dept c_dept_stat%rowtype;
begin
  update hr.employees set hr.employees.salary=salary+100 where employee_id=1000;
  if sql%notfound then
    insert into hr.employees(emploee_id,first_name,last_name,email,hire_date,job_id,department_id)values (employees_seq.nextval,'san','zhang','zs@neusoft.edu.cn',sysdate,'AC_ACCOUNT',200);
    end if;
    end;
 
ORA-06550: 第 10 行, 第 107 列: 
PL/SQL: ORA-02289: 序列不存在
ORA-06550: 第 10 行, 第 5 列: 
PL/SQL: SQL Statement ignored
 
SQL> 
SQL> begin
  2    update hr.employees set hr.employees.salary=salary+100 where employee_id=1000;
  3    if sql%notfound then
  4      insert into hr.employees(emploee_id,first_name,last_name,email,hire_date,job_id,department_id)values (employees_seq.nextval,'san','zhang','zs@neusoft.edu.cn',sysdate,'AC_ACCOUNT',200);
  5      end if;
  6      end;
  7  /
 
begin
  update hr.employees set hr.employees.salary=salary+100 where employee_id=1000;
  if sql%notfound then
    insert into hr.employees(emploee_id,first_name,last_name,email,hire_date,job_id,department_id)values (employees_seq.nextval,'san','zhang','zs@neusoft.edu.cn',sysdate,'AC_ACCOUNT',200);
    end if;
    end;
 
ORA-06550: 第 5 行, 第 107 列: 
PL/SQL: ORA-02289: 序列不存在
ORA-06550: 第 5 行, 第 5 列: 
PL/SQL: SQL Statement ignored
 
SQL> 

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.coloradmin.cn/o/1115709.html

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈,一经查实,立即删除!

相关文章

Redis在分布式场景下的应用

分布式缓存 缓存的基本作用是在高并发场景下对应服务的保护缓冲 – 基于Redis集群解决单机Redis存在的问题 单机的Redis存在四大问题&#xff1a; redis由于高强度性能采用内存 但是意味着丢失的风险单结点redis并发能力有限分布式服务中数据过多 依赖内存的redis 明显单机不…

【C语言进阶(14)】程序的编译与链接

文章目录 前言Ⅰ 程序的翻译环境1. 编译的过程2. 链接的过程 Ⅱ 程序的执行环境Ⅲ 预定义符号Ⅳ 预处理指令 #define1. #define 定义标识符2. #define 定义宏3. #define 替换规则 Ⅴ 预处理操作符 # 和1. # 操作符2. ## 操作符 Ⅵ 宏和函数的对比Ⅶ 预处理指令 #undefⅧ 条件编…

1.5状态压缩DP

1.小国王 在 n n nn nn的棋盘上放 k k k个国王&#xff0c;国王可攻击相邻的 8 8 8个格子&#xff0c;求使它们无法互相攻击的方案总数。 输入格式 共一行&#xff0c;包含两个整数 n n n和 k k k。 输出格式 共一行&#xff0c;表示方案总数&#xff0c;若不能够放置则输出…

RHEL 8.6 Kubespray 1.23.0 install kubernetes v1.27.5

文章目录 1. 预备条件2. download01 节点 安装 dockerdownload01 节点 介质下载下载 bastion01节点配置 yum 源bastion01 节点安装 docker5. 安装 docker insecure registrybastion01 部署 nginx 与 镜像入库13.1 配置 config.sh13.2 配置 setup-docker.sh13.3 配置 start-ngin…

18-spring 事务

文章目录 1. xml和注解配置方式的对象2.spring事务传播特性3. 注解事务的初始化流程4. 创建事务信息流程图5. 事务回滚流程图1. xml和注解配置方式的对象 2.spring事务传播特性 事务传播行为类型说明PROPAGATION_REQUIRED如果当前没有事务,就新建一个事务,如果已经存在一个事…

控制器连接Profinet转Modbus RTU网关与精密数显温控仪通讯配置案例

Profinet是一种用于工业自动化领域的通信协议&#xff0c;而Modbus RTU则是一种常见的串行通信协议。由于生产现场中的控制器与精密数显温控仪通常采用不同的通信协议&#xff0c;因此需要借助Profinet转Modbus RTU网关&#xff08;XD-MDPN100&#xff09;完成通信的桥接与转换…

SystemVerilog学习(1)——验证导论

写在最前 选课不慎&#xff0c;选修课选了个SystemVerilog&#xff0c;事情比必修还多&#xff0c;上课老师讲的一点用没有&#xff0c;但是学分还得修&#xff0c;只能自学了&#xff0c;既来之则安之。 一、什么是SystemVerilog SystemVerilog简称为SV语言&#xff0c;是一种…

攻防世界web篇-get_post

打开给出的地址 将浏览器上的地址http://61.147.171.105:58937/改为http://61.147.171.105:58937/?a1 输入?a1是完成了第一步&#xff0c;get请求&#xff0c;接下来要完成post的请求 这里&#xff0c;我使用的backbar quantum插件 得出flag值

【剑指Offer】32.从上往下打印二叉树

题目 不分行从上往下打印出二叉树的每个节点&#xff0c;同层节点从左至右打印。例如输入{8,6,10,#,#,2,1}&#xff0c;如以下图中的示例二叉树&#xff0c;则依次打印8,6,10,2,1(空节点不打印&#xff0c;跳过)&#xff0c;请你将打印的结果存放到一个数组里面&#xff0c;返…

深度强化学习 第 4 章 DQN 与 Q 学习

4.1 DQN 最优动作价值函数的用途 假如我们知道 Q ⋆ Q_⋆ Q⋆​&#xff0c;我们就能用它做控制。 我们希望知道 Q ⋆ Q_⋆ Q⋆​&#xff0c;因为它就像是先知一般&#xff0c;可以预见未来&#xff0c;在 t 时刻就预见 t 到 n时刻之间的累计奖励的期望。假如我们有 Q ⋆ Q…

【关于FPGA内部die到pin的延时数据,即pin delay获取方法】

首先&#xff0c;本文只介绍Xilinx的&#xff0c;Alteral的以后。。 第一&#xff0c;生成平台 Xilinx目前在用的是ISE,和Vivado&#xff1b;二者之间并不是可以互相替代的&#xff0c;或者说这两者不完全是迭代的关系。 第二&#xff0c;先介绍常用的–VIVADO 这里又有几种…

Linux系统之passwd命令的基本使用

Linux系统之passwd命令的基本使用 一、passwd命令介绍1.1 passwd命令简介1.2 passwd命令起源 二、passwd命令的使用帮助2.1 passwd命令的help帮助信息2.2 passwd命令的语法解释 三、查看passwd相关文件3.1 查看用户相关文件3.2 查看组相关文件 四、passwd命令的基本使用4.1 设置…

mysql MVC jsp实现表分页

mysql是轻量级数据库 在三层架构中实现简单的分页 在数据库sql编程中需要编写sql语句 SELECT * FROM sys.student limit 5,5; limit x,y x是开始节点&#xff0c;y是开始节点后的需要显示的长度。 在jdbc编程中需要给出x和y 一般是页数*页码&#xff0c;显示的长度。 代…

谷歌云:下一代开发者和企业解决方案的强力竞争者

自从2018年Oracle前研发总裁Thomas Kurian加入谷歌云&#xff08;Google Cloud&#xff09;并出任谷歌云CEO以来&#xff0c;业界对于谷歌云的发展就十分好奇。而谷歌云的前任CEO Diane Greene曾是VMware的创始人之一&#xff0c;那么两任企业级技术和解决方案出身的CEO&#x…

windows上下载github上的linux内核项目遇到的问题

问题一&#xff1a;clone的时候报错 Cloning into G:\github\linux... POST git-upload-pack (gzip 27925 to 14032 bytes) remote: Counting objects: 6012062, done. remote: Compressing objects: 100% (1031/1031), done. remote: Total 6012062 (delta 893), reused 342 (…

Android推送问题排查

针对MobPush智能推送服务在使用过程中可能出现的问题&#xff0c;本文为各位开发者们带来了针对MobPush安卓端推送问题的解决办法。 TCP在线推送排查 排查TCP在线收不到推送时&#xff0c;我们先通过客户端的RegistrationId接口获取设备的唯一标识 示例&#xff1a; MobPush…

【Reinforcement Learning】Ubuntu中mujoco210 mujoco_py D4RL安装及错误解决

Ubuntu中mujoco210 mujoco_py D4RL安装及错误解决 本文根据一篇知乎文章链接在此进行配置&#xff0c;记录在配置过程中遇到的一些问题&#xff0c;原文作者的教程很详细&#xff0c;在此对原作者表示感谢&#xff5e; 直接进行知乎原文的第2.2 有效安装过程(避坑) 2.注意上…

行业领先的三个企业正在利用聊天机器人变得更强

聊天机器人已成为客户服务领域的革命者&#xff0c;深刻地改变了企业与客户互动的方式。这些虚拟助手简化了交互&#xff0c;提供了24/7全天候高效和个性化的支持。凭借先进的技术和自然语言处理能力&#xff0c;聊天机器人擅长快速处理查询。 效率是聊天机器人的关键优势。它…

《数据结构、算法与应用C++语言描述》-队列的应用-图元识别问题

《数据结构、算法与应用C语言描述》-队列的应用-图元识别问题 图元识别 问题描述 数字化图像是一个 mxm 的像素矩阵。在单色图像中&#xff0c;每一个像素要么为0&#xff0c;要么为 1。值为0的像素表示图像的背景。值为1的像素表示图元上的一个点&#xff0c;称其为图元像素…

A_搜索(A Star)算法

A*搜索(A Star) 不同于盲目搜索&#xff0c;A算法是一种启发式算法(Heuristic Algorithm)。 上文提到&#xff0c;盲目搜索对于所有要搜索的状态结点都是一视同仁的&#xff0c;因此在每次搜索一个状态时&#xff0c;盲目搜索并不会考虑这个状态到底是有利于趋向目标的&#x…