简体   繁体   中英

Command not properly ended PL SQL

I'm trying to implement a pl sql program that export the content of all tables of a particular user in a file but i'm getting 'command not properly ended' problem whenever i run it. here is my code:

create or replace procedure userTable(name dba_tables.owner%type)
is
cursor cur1 is select table_name from dba_tables where owner = upper(name);
cursor cur(tabName in varchar2) is select column_name from dba_tab_columns where owner = upper(name) and table_name = upper(tabName);

V$FILEP UTL_FILE.FILE_TYPE;

type dyncursor is ref cursor;
dyn dyncursor;
req varchar2(32767):='select to_char(';
lig Varchar2(32767);
i integer:=1;

begin
  if existUser(name) = true then
    V$FILEP := UTL_FILE.FOPEN('DIRT001','TEST09.UTL','W');
    for vc1 in cur1 loop
      for vc in cur(to_char(vc1.table_name)) loop
        if (i=1) then
          req:=req||vc.column_name||')';
          i:=0;
        else
          req:=req||'||'||''','''||'||'||'to_char('||vc.column_name||')';
        end if;
      end loop;
      req:=req||' from '||name||'.'||'to_char('||vc1.table_name||')';
      open dyn for req;
      loop
        fetch dyn into lig;
        exit when dyn%notfound;
        dbms_output.put_line(lig);
        UTL_FILE.PUT_LINE(V$FILEP,lig );
      end loop;
      close dyn;
    end loop;
    UTL_FILE.FCLOSE(V$FILEP);
  else
    dbms_output.put_line('user invalid');
  end if;
end;
/
create or replace function existUser(name dba_users.username%type)
return boolean is
  nb number :=0;
begin
  select count(*) into nb from dba_users where username = upper(name);
  if nb = 0 then
    return false;
  else
    return true;
  end if;
end;
/

Expanding on what has been mentioned in the comments, adding a DBMS_OUTPUT is going to show you that you have ' from schema.to_char(table_name) '.....

vc1.table_name & vc.column_name are already character (varchar2) so there is no need to do a to_char on them in the first place so just removing to_char from around all these is a good first step.

Then if it still does not work add the DBMS_OUTPUT as suggested by Arkadiusz Łukasiewicz in the comments to see what other issues you may have.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM