Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to run Oracle query with begin/end in SQL*Plus?

Tags:

oracle

sqlplus

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?

like image 351
newguy Avatar asked Nov 19 '10 03:11

newguy


People also ask

Why do we use (+) in SQL query?

You use this to assure that the table you're joining doesn't reduce the amount of records returned. So it's handy when you're joining to a table that may not have a record for every key you're joining on.

Which is an iSQL * Plus command in SQL?

SQL*Plus is a command-line tool that provides access to the Oracle RDBMS. SQL*Plus enables you to: Enter SQL*Plus commands to configure the SQL*Plus environment. Startup and shutdown an Oracle database.

What does (+) mean in Oracle query?

The plus sign is Oracle syntax for an outer join. There isn't a minus operator for joins. An outer join means return all rows from one table. Also return the rows from the outer joined where there's a match on the join key. If there's no matching row, return null.


1 Answers

You need to follow it with a slash like

begin   dbms_output.put_line('Hello World'); end; / 
like image 57
Gary Myers Avatar answered Nov 06 '22 23:11

Gary Myers