如何在 SQL*Plus 中使用开始/结束运行 Oracle 查询?

发布于 2024-10-04 00:06:45 字数 1119 浏览 7 评论 0原文

我已经创建了一个带有开始/结束的查询块,并希望在 SQL*Plus 中运行它。但是如何在命令行中运行它呢?

实际上该代码来自一些博客,用于在数据库中搜索文本。 ABC 是要搜索的文本。

set serveroutput on size 1000000
declare
TYPE QueryCurType is REF CURSOR;
query1 QueryCurType ;

cursor c1 is select owner,table_name from dba_tables where owner not in ('SYS','SYSTEM') and table_name not like '%$%';
cursor c2(t1 varchar2) is select column_name from dba_tab_columns where table_name=t1 and DATA_TYPE in ('NVARCHAR2','VARCHAR2','CHAR');
temp_var varchar2(3000);
query varchar2(3000);

begin
for tab1 in c1 loop
  for col in c2(tab1.table_name) loop
    query:='select '||col.column_name||' from '||tab1.owner||'.'||tab1.table_name||' where '||col.column_name||' like "ABC"';
    --dbms_output.put_line('executing..'||query);
    open query1 for query;
    loop
      fetch query1 into temp_var;
      if concat('a',temp_var) != 'a' then
      dbms_output.put_line('Found String: "'||temp_var||'"# Column:'||col.column_name||'# Table:'||tab1.table_name);
      end if;
      exit when query1%NOTFOUND;
    end loop;
  end loop;
end loop;
end;

但这永远不会运行。我怎样才能运行代码?

I have created a query block with begin/end and want to run that in SQL*Plus. But how can I run it in the command line?

Actually the code is from some blog and it is used for searching text in the database. ABC is the texts to be searched.

set serveroutput on size 1000000
declare
TYPE QueryCurType is REF CURSOR;
query1 QueryCurType ;

cursor c1 is select owner,table_name from dba_tables where owner not in ('SYS','SYSTEM') and table_name not like '%$%';
cursor c2(t1 varchar2) is select column_name from dba_tab_columns where table_name=t1 and DATA_TYPE in ('NVARCHAR2','VARCHAR2','CHAR');
temp_var varchar2(3000);
query varchar2(3000);

begin
for tab1 in c1 loop
  for col in c2(tab1.table_name) loop
    query:='select '||col.column_name||' from '||tab1.owner||'.'||tab1.table_name||' where '||col.column_name||' like "ABC"';
    --dbms_output.put_line('executing..'||query);
    open query1 for query;
    loop
      fetch query1 into temp_var;
      if concat('a',temp_var) != 'a' then
      dbms_output.put_line('Found String: "'||temp_var||'"# Column:'||col.column_name||'# Table:'||tab1.table_name);
      end if;
      exit when query1%NOTFOUND;
    end loop;
  end loop;
end loop;
end;

but this never gets run. How can I run the codes?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

本宫微胖 2024-10-11 00:06:45

你需要在它后面加上斜线,例如

begin
  dbms_output.put_line('Hello World');
end;
/

You need to follow it with a slash like

begin
  dbms_output.put_line('Hello World');
end;
/
鹿童谣 2024-10-11 00:06:45

您可能只需要在末尾单独添加一个“/”即可使其执行。

You probably just need a "/" on a line by itself at the end to make it execute.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文