Skip to Main Content

SQL & PL/SQL

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Missing keyword error

DevguyJun 19 2012 — edited Jun 19 2012
Hi all,
I am getting missing keyword error when trying to execute the below function,it doesn't give an error while compiling though.Tried to debug but to vain,can't understand what i am missing.
   FUNCTION reprint_file (p_format          VARCHAR2,
                          p_printer_number  VARCHAR2,
                          p_request_id      VARCHAR2,
                          p_order_no_from   VARCHAR2 DEFAULT NULL,
			  p_order_no_to     VARCHAR2 DEFAULT NULL,
			  p_order_date_from VARCHAR2 DEFAULT NULL,
			  p_order_date_to   VARCHAR2 DEFAULT NULL
			  )
   RETURN VARCHAR2 IS
      CURSOR c_format(p_format VARCHAR2) IS
         SELECT *
         FROM   rgl_lookup_data
         WHERE  format_name = p_format;

      TYPE c_ref IS REF CURSOR;

      c_rec              c_ref;
      l_info             VARCHAR2(32767);
      l_stmt             VARCHAR2(6000);
      l_order_by         VARCHAR2(200):='';
      l_exec_stmt        VARCHAR2(8000);
      l_fp               UTL_FILE.FILE_TYPE;
      l_filename         VARCHAR2(200);
      --p_dir_name         VARCHAR2(200) := '/usr/tmp';
      p_dir_name VARCHAR2(200) := '/d02/oracle/edi/in';
      l_order_by_clause  VARCHAR2(240);
      l_cursor           PLS_INTEGER;
      l_return           NUMBER;

   BEGIN

      UPDATE rgl_mcy_line_data
      SET    printer_info = p_printer_number
      WHERE  header_id = p_request_id;

      l_stmt := 'SELECT ''"''||printer_info||''"'''; -- ||''","''||printer_info ';
      FOR curr_format IN c_format(p_format)
      LOOP

         IF curr_format.quantity IS NOT NULL THEN
            l_stmt := l_stmt || ' ||'',''||DECODE(quantity, NULL, NULL,''"''||'||'quantity||''"'')';
         END IF;
         IF curr_format.field_25 IS NOT NULL THEN
            l_stmt := l_stmt || ' ||'',''||DECODE(field_25, NULL, NULL,''"''||'||'field_25||''"'')';
         END IF;
      END LOOP curr_format;

      l_exec_stmt := l_stmt
                  || ' FROM rgl_lookup_data '
                  || ' WHERE format_name = :format_b';

      l_filename := 'Reprint_'||'ASP'||'_'||p_request_id||'_'||TO_CHAR(SYSDATE, '_DDMMYYYY_hh24MISS')||'.csv';


      l_fp := UTL_FILE.FOPEN(p_dir_name, l_filename, 'w');

      OPEN c_rec FOR l_exec_stmt USING p_format;
      FETCH c_rec INTO l_info;
      CLOSE c_rec;

      write_line(l_fp, l_info);

      l_exec_stmt := l_stmt
                  || ' FROM  rgl_mcy_line_data '
                  || ' WHERE header_id = :header_id_b '
                  || ' AND   format = :format_b '
                  || ' AND   printer_info = :printer_number_b ';

      IF p_order_no_from IS NOT NULL AND p_order_no_to IS NOT NULL THEN
         l_exec_stmt := l_exec_stmt
                     || ' AND order_number BETWEEN :order_no_from_b TO :order_no_from_to ';
      ELSIF p_order_no_from IS NOT NULL THEN
         l_exec_stmt := l_exec_stmt
                     || ' AND order_number >= :order_no_from_b ';
      ELSIF p_order_no_to IS NOT NULL THEN
         l_exec_stmt := l_exec_stmt
                     || ' AND order_number <= :order_no_from_to ';
      END IF;

      IF p_order_date_from IS NOT NULL AND p_order_date_to IS NOT NULL THEN
         l_exec_stmt := l_exec_stmt
                     || ' AND order_date BETWEEN :order_date_from_b TO :order_date_from_to ';
      ELSIF p_order_date_from IS NOT NULL THEN
         l_exec_stmt := l_exec_stmt
                     || ' AND order_date >= :order_date_from_b ';
      ELSIF p_order_date_to IS NOT NULL THEN
         l_exec_stmt := l_exec_stmt
                     || ' AND order_date <= :order_date_from_to ';
      END IF;

      --log_mesg(l_exec_stmt);
dbms_output.put_line('Entered');
      l_cursor := DBMS_SQL.OPEN_CURSOR;
      DBMS_SQL.PARSE(l_cursor, l_exec_stmt, DBMS_SQL.NATIVE); --Error is showing at this line
      DBMS_SQL.DEFINE_COLUMN(l_cursor, 1, l_info, 32767);
      DBMS_SQL.BIND_VARIABLE(l_cursor, 'header_id_b', p_request_id);
      DBMS_SQL.BIND_VARIABLE(l_cursor, 'format_b', p_format);
      DBMS_SQL.BIND_VARIABLE(l_cursor, 'printer_number_b', p_printer_number);
dbms_output.put_line('Exit');
      --log_mesg('req:'||p_request_id);
      --log_mesg('for:'||p_format);
      --log_mesg('pno:'||p_printer_number);


      IF p_order_no_from IS NOT NULL THEN
         --log_mesg('onf:'||p_order_no_from);
         DBMS_SQL.BIND_VARIABLE(l_cursor, 'order_no_from_b', p_order_no_from);
      END IF;

      IF p_order_no_to IS NOT NULL THEN
         --log_mesg('ont:'||p_order_no_to);
         DBMS_SQL.BIND_VARIABLE(l_cursor, 'order_no_to_b', p_order_no_to);
      END IF;

      IF p_order_date_from IS NOT NULL THEN
         --log_mesg('odf:'||p_order_date_from);
         DBMS_SQL.BIND_VARIABLE(l_cursor, 'order_date_from_b', p_order_date_from);
      END IF;

      IF p_order_date_to IS NOT NULL THEN
         --log_mesg('odt:'||p_order_date_to);
         DBMS_SQL.BIND_VARIABLE(l_cursor, 'order_date_to_b', p_order_date_to);
      END IF;

      l_return := DBMS_SQL.EXECUTE(l_cursor);
      LOOP
      --log_mesg('inside the loop')
         EXIT WHEN DBMS_SQL.FETCH_ROWS(l_cursor) = 0; --curr_rec%NOTFOUND;
         DBMS_SQL.COLUMN_VALUE(l_cursor, 1, l_info);
         write_line(l_fp, l_info);
      END LOOP;
      DBMS_SQL.CLOSE_CURSOR(l_cursor);

      UTL_FILE.FCLOSE(l_fp);

      UPDATE rgl_header_data
      SET    last_print_date = SYSDATE,
             reprint_count = NVL(reprint_count, 0) + 1
      WHERE  header_id = p_request_id;
      COMMIT;

      EXCEPTION
WHEN OTHERS THEN
    DBMS_OUTPUT.PUT_LINE('An error was encountered - '||SQLCODE||' -ERROR- '||SQLERRM);


      RETURN l_filename;
   END rePrint_File;
Function Call
DECLARE
v_result VARCHAR2(1000);
BEGIN
v_result := REGAL_MCY_PRINT_PKG.reprint_file('Macys.lwl','hp4000','6473482927','1213049','1213049',NULL,NULL);
END;
DBMS Messages
Entered
An error was encountered - -905 -ERROR- ORA-00905: missing keyword


Any suggestions,
Thanks in advance!!
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Jul 17 2012
Added on Jun 19 2012
12 comments
1,280 views