Solved

Call a procedure on command line

Posted on 2014-11-24
8
179 Views
Last Modified: 2014-12-24
I have the below procedure. how can i call it on the command line with sqlplus
0
Comment
Question by:gaurav sharma
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
  • 2
8 Comments
 

Author Comment

by:gaurav sharma
ID: 40463106
CREATE OR REPLACE PROCEDURE recomp IS
BEGIN
   FOR cur IN (SELECT object_name,
                      object_type,
                      owner
               FROM   all_objects
               WHERE  object_type IN ('PACKAGE',
                                      'PACKAGE BODY')
               AND    owner = 'TRON2000'
               --                 AND object_name like 'EM%'
               ORDER  BY object_name)
   LOOP
      BEGIN
         IF cur.object_type = 'PACKAGE BODY' THEN
            EXECUTE IMMEDIATE 'alter package "' || cur.owner || '"."' ||
                              cur.object_name || '" compile body';
         ELSE
            EXECUTE IMMEDIATE 'alter ' || cur.object_type || ' "' || cur.owner ||
                              '"."' || cur.object_name || '" compile';
         END IF;
      EXCEPTION
         WHEN OTHERS THEN
            NULL;
      END;
      --dbms_output.put_line('Recompiled: ' || cur.OBJECT_TYPE || ' ' ||
   --                   cur.owner || '.' || cur.OBJECT_NAME);
   END LOOP;
END;
/
0
 
LVL 35

Assisted Solution

by:johnsone
johnsone earned 250 total points
ID: 40463161
From SQL*Plus, it would be:

exec recomp;
0
 

Author Comment

by:gaurav sharma
ID: 40463173
If I were to put this call in a file would it be .sql ? and what would be the contents of a file ?
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 35

Expert Comment

by:johnsone
ID: 40463242
It would be one line:

exec recomp;

Then from within SQL*Plus, you would run that using

@<path_to_script>/<script_name>
0
 

Author Comment

by:gaurav sharma
ID: 40463455
This is the error I get:

 Failed to execute:  EXEC RECOMP
java.sql.SQLException: ORA-00900: invalid SQL statement
0
 
LVL 13

Assisted Solution

by:Alexander Eßer [Alex140181]
Alexander Eßer [Alex140181] earned 250 total points
ID: 40464155
0
 
LVL 35

Assisted Solution

by:johnsone
johnsone earned 250 total points
ID: 40464238
You stated multiple times that you were running from SQL*Plus, not java.

If you are really running from Java and not SQL*Plus, then use the documentation link provided by Alexander.
0
 
LVL 13

Accepted Solution

by:
Alexander Eßer [Alex140181] earned 250 total points
ID: 40464310
I agree with johnsone: please clarify whether you run this within SQLPLUS or Java! Otherwise we might not be able to help you and this could get quite confusing!

I assumed, you got this error upon a Java execution based on the Java exception:
java.sql.SQLException: ORA-00900: invalid SQL statement
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Why doesn't the Oracle optimizer use my index? Querying too much data Most Oracle developers know that an index is useful when you can use it to restrict your result set to a small number of the total rows in a table. So, the obvious side…
From implementing a password expiration date, to datatype conversions and file export options, these are some useful settings I've found in Jasper Server.
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.
This video shows how to Export data from an Oracle database using the Original Export Utility.  The corresponding Import utility, which works the same way is referenced, but not demonstrated.

705 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question