sql >> Database teknologi >  >> RDS >> Oracle

Oracle PL/SQL:Hjælp til at løse PLS-00103:Stødte på symbolet LOOP, da man forventede et af følgende:hvis

DECLARE
    update_count integer := 0;
    prjt_name varchar2(100) := 'tttt';
    mysql varchar2(100);
                   tablename  varchar2(100);

    cursor my_cur is 
         select 'DUAL' 
            from dual
           where 'PROJECT_ID' = 'PROJECT_ID' and 'SANDBOX' = 'SANDBOX';

begin
    open my_cur;
    LOOP
    FETCH  my_cur into tablename;
      EXIT WHEN my_cur%NOTFOUND;
        update_count := 0;
        mysql := 'select count(*)  ' || ' from '
        || tablename
        || ' where  ''TTTT'' = upper('''
        || prjt_name
        || ''')' ;
      Execute immediate mysql INTO update_count;
        dbms_output.put_line (mysql);

  dbms_output.put_line (update_count);
  END LOOP;
CLOSE my_cur;
end;

Jeg prøvede en som din. Dette udføres med succes

declare
    query varchar2(10000);
    update_count integer := 0;
    prjt_name varchar2(100) := '01213264B';
    cursor my_cur is 
           select table_name 
             from [email protected]_pos15 
             where column_name = 'PROJECT_ID' and owner = 'SANDBOX';
    tableName  varchar2(100);
begin
  open my_cur;
    loop
    fetch my_cur into tableName;
    exit when my_cur%NOTFOUND;
        update_count := 0;
        query := 'select count(t.project_id) as ''CNT'' from sandbox.'
        || tableName
        || '@adhoc_pos15 t'
        || ' where  t.project_id = (select project_id from [email protected]_pos15 where project_name = ''' || prjt_name || ''') ' ;
   execute immediate query into update_count;
     dbms_output.put_line (query);
     dbms_output.put_line (update_count);
  end loop;
close my_cur;
end;


  1. MySQL:Indsæt i flere tabeller i samme forespørgsel med BEGIN&COMMIT

  2. Migrer SQL Server DateTime-kolonnen til DateTimeOffset

  3. Ukendt fejl:MySQLTransactionRollbackException 1213

  4. MySQL sammenkæder værdier fra en tabel til en post i en anden