cursor giving error

306 views Asked by At

hi we are trying to execute following script we are getting errors as

ERROR at line 1:
ORA-20000: Unknown Exception Raised: -933 ORA-00933: SQL command not properly
ended
ORA-06512: at line 23

DECLARE
        l_cursor INTEGER;
        l_output  VARCHAR2(20);
        l_rows   INTEGER;
        l_sql   VARCHAR2(1000);
      BEGIN
        l_cursor := DBMS_SQL.OPEN_CURSOR;
        l_sql := 'SELECT wk_units1 FROM cnt_sls_dm.fct_sales.summary UNION SELECT wk_units2 FROM cnt_sls_dm.fct_sales.summary';  
       DBMS_SQL.PARSE(l_cursor, l_sql, DBMS_SQL.NATIVE);
       DBMS_SQL.DEFINE_COLUMN_CHAR(l_cursor, 1, l_output, 20);
       l_rows := DBMS_SQL.EXECUTE(l_cursor);
       loop
          if DBMS_SQL.FETCH_ROWS(l_cursor) = 0 then
             exit;
          end if;
          DBMS_SQL.COLUMN_VALUE_CHAR(l_cursor, 1, l_output);
          DBMS_OUTPUT.PUT_LINE('Output Text '||l_output);
       end loop;
       DBMS_SQL.CLOSE_CURSOR(l_cursor);
      EXCEPTION
       when others then
             DBMS_SQL.CLOSE_CURSOR(l_cursor);
             raise_application_error(-20000, 'Unknown Exception Raised: '||sqlcode||' '||sqlerrm);
      END;
2

There are 2 answers

1
APC On

What is this?

cnt_sls_dm.fct_sales.summary

It's not a valid table declaration.

0
Juergen Hartelt On

When encountering an error in a dynamic SQL statement, it often helps to output the actual SQL statement and try it in SQLplus.