Sql 无法使我的循环使用行更新行

Sql 无法使我的循环使用行更新行,sql,oracle,plsql,Sql,Oracle,Plsql,试图学习循环,并希望从此查询中输出所有行,但计数器工作,变量没有存储数据 我已经声明了所有内容以及我认为已分配给列的内容,但没有得到我需要的输出 SET SERVEROUTPUT ON SIZE 1000000; DECLARE n_counter NUMBER := 0; v_site is_spool_dir.site%TYPE; v_client is_spool_dir.client%TYPE; v_name IS_PRINTS_NAME.name_co

试图学习循环,并希望从此查询中输出所有行,但计数器工作,变量没有存储数据

我已经声明了所有内容以及我认为已分配给列的内容,但没有得到我需要的输出

SET SERVEROUTPUT ON SIZE 1000000;
DECLARE 
    n_counter NUMBER := 0;
    v_site is_spool_dir.site%TYPE;
    v_client is_spool_dir.client%TYPE;
    v_name IS_PRINTS_NAME.name_comment%TYPE;
    v_id is_spool_dir.identification%TYPE;
    v_date is_spool_dir.last_print%TYPE;
BEGIN
    FOR item IN (
        SELECT
            s.site
            ,s.client
            ,p.name_comment
            ,s.identification
            ,to_char(s.last_print, 'DD/MM/RRRR HH24:MM:SS') INTO v_site, v_client, v_name, v_id, v_date
        FROM
            is_spool_dir s
            ,is_prints_name p
        WHERE
           to_char(s.last_print, 'DD/MM/YYYY') like '18/01/2019'
           and s.site = '7'
           and s.client = 'BREV'
           and s.identification like 'BREZ%'
           and p.id = s.report_id
        ORDER BY
           to_char(s.last_print, 'DD/MM/YYYY'))
    LOOP 
    n_counter := n_counter + 1;
    DBMS_OUTPUT.PUT_LINE(n_counter);
    DBMS_OUTPUT.PUT_LINE(v_site ||','|| v_client ||','|| v_name ||','|| v_id ||','|| v_date);
    IF n_counter = 1000 THEN
      EXIT;
    END IF;
  END LOOP;
END;
/
输出

1
,,,,
2
,,,,
3
,,,,
4
,,,,
5
,,,,
6
,,,,
7
,,,,
8
,,,,
9
,,,,
10
,,,,
11
,,,,
12
,,,,
13
,,,,
14
,,,,
15
,,,,
16
,,,,
17
,,,,
18
,,,,
19
,,,,
20
,,,,
21
,,,,
22
,,,,
23
,,,,
24
,,,,
25
,,,,
26
,,,,
27
,,,,
28
,,,,
29
,,,,
30 etc

为循环声明游标时,不使用into子句

如果你真的想把它们放入变量中,你可以在循环中做这样的赋值

v_site := item.site; 
否则,只需使用循环中声明的item变量,如下所示

SET SERVEROUTPUT ON SIZE 1000000;
DECLARE 
    n_counter NUMBER := 0;
BEGIN
    FOR item IN (
        SELECT
            s.site
            ,s.client
            ,p.name_comment
            ,s.identification
            ,to_char(s.last_print, 'DD/MM/RRRR HH24:MM:SS')
        FROM
            is_spool_dir s
            ,is_prints_name p
        WHERE
           to_char(s.last_print, 'DD/MM/YYYY') like '18/01/2019'
           and s.site = '7'
           and s.client = 'BREV'
           and s.identification like 'BREZ%'
           and p.id = s.report_id
        ORDER BY
           to_char(s.last_print, 'DD/MM/YYYY'))
    LOOP 
    n_counter := n_counter + 1;
    DBMS_OUTPUT.PUT_LINE(n_counter);
    DBMS_OUTPUT.PUT_LINE(item.v_site ||','|| item.v_client ||','|| item.v_name ||','|| item.v_id ||','|| item.v_date);
    IF n_counter = 1000 THEN
      EXIT;
    END IF;
  END LOOP;
END;

为循环声明游标时,不使用into子句

如果你真的想把它们放入变量中,你可以在循环中做这样的赋值

v_site := item.site; 
否则,只需使用循环中声明的item变量,如下所示

SET SERVEROUTPUT ON SIZE 1000000;
DECLARE 
    n_counter NUMBER := 0;
BEGIN
    FOR item IN (
        SELECT
            s.site
            ,s.client
            ,p.name_comment
            ,s.identification
            ,to_char(s.last_print, 'DD/MM/RRRR HH24:MM:SS')
        FROM
            is_spool_dir s
            ,is_prints_name p
        WHERE
           to_char(s.last_print, 'DD/MM/YYYY') like '18/01/2019'
           and s.site = '7'
           and s.client = 'BREV'
           and s.identification like 'BREZ%'
           and p.id = s.report_id
        ORDER BY
           to_char(s.last_print, 'DD/MM/YYYY'))
    LOOP 
    n_counter := n_counter + 1;
    DBMS_OUTPUT.PUT_LINE(n_counter);
    DBMS_OUTPUT.PUT_LINE(item.v_site ||','|| item.v_client ||','|| item.v_name ||','|| item.v_id ||','|| item.v_date);
    IF n_counter = 1000 THEN
      EXIT;
    END IF;
  END LOOP;
END;

您可以通过轮询方式使用光标:

FOR CUR IN (  SELECT
        s.site
        ,s.client
        ,p.name_comment
        ,s.identification
        ,to_char(s.last_print, 'DD/MM/RRRR HH24:MM:SS')
    FROM
        is_spool_dir s
        ,is_prints_name p
    WHERE
       to_char(s.last_print, 'DD/MM/YYYY') like '18/01/2019'
       and s.site = '7'
       and s.client = 'BREV'
       and s.identification like 'BREZ%'
       and p.id = s.report_id
    ORDER BY
       to_char(s.last_print, 'DD/MM/YYYY'))

       LOOP

      NULL;
      --use CUR.site HERE FOR YOUR OPERATIONS ...

      END LOOP;

您可以通过轮询方式使用光标:

FOR CUR IN (  SELECT
        s.site
        ,s.client
        ,p.name_comment
        ,s.identification
        ,to_char(s.last_print, 'DD/MM/RRRR HH24:MM:SS')
    FROM
        is_spool_dir s
        ,is_prints_name p
    WHERE
       to_char(s.last_print, 'DD/MM/YYYY') like '18/01/2019'
       and s.site = '7'
       and s.client = 'BREV'
       and s.identification like 'BREZ%'
       and p.id = s.report_id
    ORDER BY
       to_char(s.last_print, 'DD/MM/YYYY'))

       LOOP

      NULL;
      --use CUR.site HERE FOR YOUR OPERATIONS ...

      END LOOP;

这个答案并没有说明OP想要做什么。您评论的位--use CUR.site HERE FOR YOUR operation是OP遇到困难的位。此答案没有说明OP试图做什么。您注释的位--use CUR.site HERE FOR YOUR operation就是OP遇到困难的位。