Procedure to execute dynamic DDL

If I have table T below, and I need to create partitions based on the year (YR), but I need to create partitions for each quarter of the year. How can I write a procedure to do that?
WITH T AS
(SELECT 2001 YR FROM DUAL
UNION ALL SELECT 2002 YR FROM DUAL
select * From t;
Here is what I need to have executed as part of the procedure:
ALTER TABLE T ADD PARTITION (PARTITION P2001_01 VALUES LESS THAN (TO_DATE('2001-01-01', 'YYYY-MM-DD' ));
ALTER TABLE T ADD PARTITION (PARTITION P2001_02 VALUES LESS THAN (TO_DATE('2001-04-01', 'YYYY-MM-DD' ));
ALTER TABLE T ADD PARTITION (PARTITION P2001_03 VALUES LESS THAN (TO_DATE('2001-07-01', 'YYYY-MM-DD' ));
ALTER TABLE T ADD PARTITION (PARTITION P2001_04 VALUES LESS THAN (TO_DATE('2001-10-01', 'YYYY-MM-DD' ));
ALTER TABLE T ADD PARTITION (PARTITION P2002_01 VALUES LESS THAN (TO_DATE('2002-01-01', 'YYYY-MM-DD' ));
ALTER TABLE T ADD PARTITION (PARTITION P2002_02 VALUES LESS THAN (TO_DATE('2002-04-01', 'YYYY-MM-DD' ));
ALTER TABLE T ADD PARTITION (PARTITION P2002_03 VALUES LESS THAN (TO_DATE('2002-07-01', 'YYYY-MM-DD' ));
ALTER TABLE T ADD PARTITION (PARTITION P2002_04 VALUES LESS THAN (TO_DATE('2002-10-01', 'YYYY-MM-DD' ));

If you want to run alter command manually then you can simply avoid execute immediate and create one table function to print the alter command like below.
CREATE OR REPLACE TYPE nt_tab IS TABLE OF VARCHAR2(2000);
CREATE OR REPLACE FUNCTION func_addpartition
RETURN nt_tab
AS
v_nttab nt_tab := nt_tab();
v_entrydate DATE;
v_incr NUMBER := 0;
v_incr1 NUMBER := 0;
BEGIN
FOR i IN (SELECT TRUNC(entry_date,'YYYY') date_entry,TO_CHAR(TRUNC(entry_date,'YYYY'),'YYYY') part_date FROM t GROUP BY TRUNC(entry_date,'YYYY'))
  LOOP
   v_incr := v_incr+1;
   v_incr1 := v_incr1+1;
   v_nttab.EXTEND;
   v_nttab(v_incr1) := 'ALTER TABLE T ADD PARTITION (PARTITION P'||i.part_date||'_0'||v_incr||' VALUES LESS THAN (TO_DATE('||''''||i.date_entry||''''||','||'''DD-MON-YYYY'''||'));';
   v_entrydate := i.date_entry;
  FOR j IN v_incr..3
   LOOP
    v_incr := v_incr+1;
    v_incr1 := v_incr1+1;
    v_entrydate := ADD_MONTHS(v_entrydate,3);
    v_nttab.EXTEND;
    v_nttab(v_incr1) := 'ALTER TABLE T ADD PARTITION (PARTITION P'||i.part_date||'_0'||v_incr||' VALUES LESS THAN (TO_DATE('||''''||v_entrydate||''''||','||'''DD-MON-YYYY'''||'));';
   END LOOP;
v_incr := 0;
END LOOP;
RETURN v_nttab;
EXCEPTION WHEN OTHERS THEN
RAISE;
END;
SELECT * FROM TABLE(FUNC_ADDPARTITION);
OUTPUT:-
SCOTT@orcl>SELECT * FROM TABLE(FUNC_ADDPARTITION);
COLUMN_VALUE
ALTER TABLE T ADD PARTITION (PARTITION P2001_01 VALUES LESS THAN (TO_DATE('01-JAN-01','DD-MON-YYYY'));
ALTER TABLE T ADD PARTITION (PARTITION P2001_02 VALUES LESS THAN (TO_DATE('01-APR-01','DD-MON-YYYY'));
ALTER TABLE T ADD PARTITION (PARTITION P2001_03 VALUES LESS THAN (TO_DATE('01-JUL-01','DD-MON-YYYY'));
ALTER TABLE T ADD PARTITION (PARTITION P2001_04 VALUES LESS THAN (TO_DATE('01-OCT-01','DD-MON-YYYY'));
ALTER TABLE T ADD PARTITION (PARTITION P2003_01 VALUES LESS THAN (TO_DATE('01-JAN-03','DD-MON-YYYY'));
ALTER TABLE T ADD PARTITION (PARTITION P2003_02 VALUES LESS THAN (TO_DATE('01-APR-03','DD-MON-YYYY'));
ALTER TABLE T ADD PARTITION (PARTITION P2003_03 VALUES LESS THAN (TO_DATE('01-JUL-03','DD-MON-YYYY'));
ALTER TABLE T ADD PARTITION (PARTITION P2003_04 VALUES LESS THAN (TO_DATE('01-OCT-03','DD-MON-YYYY'));
ALTER TABLE T ADD PARTITION (PARTITION P2006_01 VALUES LESS THAN (TO_DATE('01-JAN-06','DD-MON-YYYY'));
ALTER TABLE T ADD PARTITION (PARTITION P2006_02 VALUES LESS THAN (TO_DATE('01-APR-06','DD-MON-YYYY'));
ALTER TABLE T ADD PARTITION (PARTITION P2006_03 VALUES LESS THAN (TO_DATE('01-JUL-06','DD-MON-YYYY'));
ALTER TABLE T ADD PARTITION (PARTITION P2006_04 VALUES LESS THAN (TO_DATE('01-OCT-06','DD-MON-YYYY'));
12 rows selected.

Similar Messages

  • Executing multiple DDL statements with OracleCommand

    hi..
    im having trouble executing multiple ddl statements with the the oracle command object. i have tried to enclose them within Begin.. End; block but with no use.
    this problem seems to occur only with DDL statements,.. as my DML like update, delete and Inserts seem to work fine when enclosed within the PL /SQL block.
    single DDL statements also seem to work fine. so im guessing this has nothing to do with priviledges. any ideas?
    my code as follows
    OracleCommand command = new OracleCommand();
    command.CommandType = CommandType.Text;
    command.CommandText = string.Format(@"{0}",script);
    conn.Open();
    command.Connection = conn;
    command.ExecuteNonQuery();
    the script is read from a file, and looks like this. (note : i have removed any line breaks or any other characters)
    BEGIN ALTER TABLE SYSTEMUSER DISABLE CONSTRAINT FK_USER_CLIENT; ALTER TRIGGER SET_SUBSCRIPTION_SUB_I DISABLE; END;
    this is the error i get.
    Oracle.DataAccess.Client.OracleException: ORA-06550: line 1, column 7:
    PLS-00103: Encountered the symbol "ALTER" when expecting one of the following:
    begin case declare exit for goto if loop mod null pragma
    raise return select update while with <an identifier>
    <a double-quoted delimited-identifier> <a bind variable> <<
    close current delete fetch lock insert open rollback
    savepoint set sql execute commit forall merge pipe.

    If I'm not mistaken, we're not allowed to issue DDL inside anonymoue block (or stored procedure) since DDL has implicit commit in it. But you still can execute DDL using EXECUTE IMMEDIATE or using DBMS_SQL package. Try changing your CommandText like this,
    BEGIN
       EXECUTE IMMEDIATE 'ALTER TABLE SYSTEMUSER DISABLE CONSTRAINT FK_USER_CLIENT';
       EXECUTE IMMEDIATE 'ALTER TRIGGER SET_SUBSCRIPTION_SUB_I DISABLE';
    END;Hope this helps,
    [Nur Hidayat|http://nur-hidayat.net/]

  • How can I execute Dynamic SQL statement in Forms?

    Hi All,
    I have to execute dynamic SQL statement from Forms
    Below statement I have to execute
    "EXECUTE IMMEDIATE v_stmt INTO v_return;".
    Googled for the same got results saying, Better use Database function or procedures to execute these Dynamic Statements but We want to execute in forms only.
    Can any one help me..
    Thanks,
    Madhu

    So in short you are trading code obfuscation for maintainability and the ability to share code between tools? If from somewhere else you need a procedure already implemented in database PL/SQL (and now ported to forms) this would mean you'd need to implement it in every other tool. In times where you might want to integrate your forms with $other_technology and putting stuff on the database is the first step to share functionality you just go the opposite way? And all that because someone is afraid that somebody might steal your source code? I am sorry to be blunt, but this is just plain stupid.
    Leaving aside that some things like Analytic Functions, Bulk processing or execute immediate are not even available in forms your software consists of how many LOC? How long does it take to bring a new developer up to speed with your source code? Imagine how long that would take for a developer who doesn't have coleagues who know their way around.
    And just so you know: I work for a ISV selling a closed-source product as well. We have 200+ customers all over the planet. We are well aware that wrapped packages can be reverse engineered. The premise is: stored procedures can be reused in every tool we have, if it makes sense to put stuff on the database by all means do it. If someone would want to reverse engineer our software I'd wish him good luck as some parts are implemented in such a hilarious complicated way I have troubles understanding them (and quite frankly I refuse to understand certain parts, but that's another story). I do work for almost 10 years for that ISV.
    In any case the possible solutions have already been mentioned: you have exec_sql, create_group_from_query and forms_ddl to execute dynamic SQL in forms whereas forms_ddl is a one way street and most certainly not the thing you need or want. Take a look at the documentation for the other 2 things.
    cheers

  • Java Stored Procedure in EXECUTE IMMEDIATE

    Hi,
    I need advice for the following.
    I'm on Oracle 11g R2. I'm testing application in Oracle 11gR1 and R2 and Oracle Express.
    Purpose is to generate XML reports.
    I have PLSQL Stored Procedure which does that, but since there is bug in Oracle11gR2 related to XMLTRANSFORM I have and Java Stored Procedure which is workaround. They are both compiled, valid etc.
    Java class is :
    import java.io.PrintWriter;
    import java.io.Writer;
    import oracle.xml.parser.v2.DOMParser;
    import oracle.xml.parser.v2.XMLDocument;
    import oracle.xml.parser.v2.XSLProcessor;
    import oracle.xml.parser.v2.XSLStylesheet;
    * This class is used as Java stored procedure
    * There is a bug on Oracle11gR2, related to the limitation on the number of style sheet instructions
    * This stored procedure is workaround when PLSQL code can not be used.
    * File must not have package, otherwise is wrongly compiled in DB
    public class JavaXslt {
         public static void XMLTtransform(oracle.sql.CLOB xmlInput,oracle.sql.CLOB xslInput,oracle.sql.CLOB output) throws Exception{
              DOMParser parser;
              XMLDocument xml;
              XMLDocument xsldoc;
              try{
                   parser = new DOMParser();
                   parser.parse(xmlInput.getCharacterStream());
                   xml = parser.getDocument();
                   parser.parse(xslInput.getCharacterStream());
                   xsldoc = parser.getDocument();
                   XSLProcessor processor = new XSLProcessor();
                   XSLStylesheet xsl = processor.newXSLStylesheet(xsldoc);
                   Writer w = output.setCharacterStream(1L);
                   PrintWriter pw = new PrintWriter(w);
                   processor.processXSL(xsl, xml, pw);
              }catch (Exception ex){
                   throw ex;
    PROCEDURE Java_XmlTransform (xml CLOB, xslt CLOB, output CLOB) AS LANGUAGE JAVA
    NAME 'JavaXslt.XMLTtransform(oracle.sql.CLOB, oracle.sql.CLOB, oracle.sql.CLOB)';
    I'm calling Java stored procedure from PLSQL Stored procedure (if it is Oracle11gR2) like that :
    Java_Proc.Java_XmlTransform(inputXML, xslt, res);
    So till here everything works ok. XSLT as applied and output XML (res) is OK.
    But when Oracle Express is used Java is out of the question, so there is no Java stored procedure. Howewer PLSQL Stored procedure is still needed.
    So I had to put call to Java Stored procedure in EXECUTE IMMEDIATE statement in order to compile to PLSQL package.
    But when I do that :
    EXECUTE IMMEDIATE 'BEGIN Java_Proc.Java_XmlTransform (:1, :2, :3); END;' USING inputXML, xslt, res;
    result value CLOB (res) has zero length...
    What am I missing? Should i set return value to Java class?
    Hope my explanations are clear though.
    Thanks

    Hi odie_63,
    Thanks for quick response.
    I didn't clearly explained.
    When using Oracle 11gR1 and Oracle Express I'm using only PLSQL Procedure.
    When using Oracle 11gR2 i have to use Java Stored procedure because there is documented bug in R2.
    That's why i have to use EXECUTE IMMEDIATE. I don't know which version is the client DB and whether there is or no Java procedures.
    I did tried
    EXECUTE IMMEDIATE 'BEGIN Java_Proc.Java_XmlTransform (:1, :2, :3); END;' USING IN inputXML, IN xslt, OUT res; and the result was ORA-06537: OUT bind variable bound to an IN position
    When using IN OUT for last parameter i.e.
    EXECUTE IMMEDIATE 'BEGIN Java_Proc.Java_XmlTransform (:1, :2, :3); END;' USING IN inputXML, IN xslt, IN OUT res;
    there is no exception, but still DBMS_LOB.getlength(res) = 0
    Thanks

  • Procedure in Execute Immedite block

    Hi, all.
    I need to execute pl/sql procedure from Execute Immedite block.
    I am trying to do it with exec but getting error:
    begin
    EXECUTE IMMEDIATE '
    exec FillTestForOperation';
    end;
    begin
    ERROR at line 1:
    ORA-00900: invalid SQL statement
    ORA-06512: at line 2
    Is there any way to do it?

    JustasVred wrote:
    Hi, all.
    I need to execute pl/sql procedure from Execute Immedite block.
    I am trying to do it with exec but getting error:
    begin
    EXECUTE IMMEDIATE '
    exec FillTestForOperation';
    end;
    begin
    ERROR at line 1:
    ORA-00900: invalid SQL statement
    ORA-06512: at line 2
    Is there any way to do it?Try :
    declare
    vstring varchar2(10);
    begin
    vstring := FillTestForOperation';';
    execute immediate('begin '||vstring||' end;');
    end;
    Kamran Agayev A. (10g OCP)
    http://kamranagayev.wordpress.com
    [Step by Step install Oracle on Linux and Automate the installation using Shell Script |http://kamranagayev.wordpress.com/2009/05/01/step-by-step-installing-oracle-database-10g-release-2-on-linux-centos-and-automate-the-installation-using-linux-shell-script/]

  • Error in executing dynamic SQL

    i am getting error in executing dynamic SQL
    declare
    vr_RenewService NUMBER(10,0);
    vr_sql VARCHAR2(50);
    begin
    vr_sql:='Select Case
    when 5 <= 365 Then 1
    When 1= 0 Then 1
    else 0 end into' || TO_CHAR(vr_RenewService) || 'from dual;';
    execute immediate vr_sql;
    --dbms_output.put_line(vr_RenewService);
    end;
    ERROR
    ORA-06502: PL/SQL: numeric or value error: character string buffer too small
    ORA-06512: at line 6
    06502. 00000 - "PL/SQL: numeric or value error%s"
    *Cause:   
    *Action:                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   

    i too have tried this before you posted this solution but getting error message
    declare
    vr_RenewService NUMBER(10,0);
    vr_sql VARCHAR2(100);
    begin
    vr_sql:='Select Case
    when 5 <= 365 Then 1
    When 1= 0 Then 1
    else 0 end from dual;';
    execute immediate vr_sql into vr_RenewService;
    --dbms_output.put_line(vr_RenewService);
    end;
    ORA-06512: at line 11
    00911. 00000 - "invalid character"
    *Cause:    identifiers may not start with any ASCII character other than
    letters and numbers. $#_ are also allowed after the first
    character. Identifiers enclosed by doublequotes may contain
    any character other than a doublequote. Alternative quotes
    (q'#...#') cannot use spaces, tabs, or carriage returns as
    delimiters. For all other contexts, consult the SQL Language
    Reference Manual.
    *Action:                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           

  • What happens to the report if the underlying stored procedure to execute the report take atleast 3 hrs to run

    Hi,
    I have a report which is calling a stored procedure..
    Stored procedure exceutes 4-5 stored procedure and then returns the count each procedure it ran using union all statement... The stored procedure takes around 3-4 hrs to run because it is looking at quarterly data and YTD data.
    So once the report is kicked off and the procedure behind it runs and runs how will communicate to the report to show the final data... the final data will just be 5 rows with counts.
    I think we are running into a issue where the stored procedure runs and runs and then the report goes into la la land and has no clue what to do...
    Can you please shed some light on this..
    Thanks
    Karen

    Hi Karen,
    When we render a report, the report would process the following procedures:
    Open connections to data source and reading data rows from data extensions for all datasets, means retrieve data. Then process the engine requests, including the tablix, grouping, sorting, filtering, aggregations and subreport processing, means process report.
    Finally, render the report, including the pagination modules and on-demand expression evaluations.
    So the report rending has to wait until the stored procedure is executed. To improve the performance, we can consider the three aspects:
    Improve the performance of the stored procedures. Such as index and join. For better support, I suggest you can post a new thread about this issue in Transact-SQL forum at:
    http://social.msdn.microsoft.com/Forums/sqlserver/en-US/home?forum=transactsql. It is appropriate and more experts will assist you.
    Simplify the report. For example, avoid including a reference to [&TotalPages] or any complex expressions in the page header and page footer. For more details, please see the following document:
    http://technet.microsoft.com/en-us/library/bb522806(v=sql.105).aspx
    Using cashing if you have a long-running query that cannot be tuned further. For more details, please refer to the following article:
    http://msdn.microsoft.com/en-us/library/ms159241(v=sql.110).aspx
    Hope this helps.
    Thanks,
    Katherine Xiong
    Katherine Xiong
    TechNet Community Support

  • Executing a DDL statement from java code

    Hi all,
    this is code from jdev11.1.1.3 version. I am trying to execute a DDL statement in oracle db from java code, but "ORA-00900: invalid SQL statement" error is coming.
    I am trying to create a table in same schema in same db by using 'Copy' command.
    Same DDL command is executing from sql command prompt & table is being created. Plz help me , as how to do from java?
            public String cmb_action() {
            // Add event code here...
            try {
                //getting source db connection
                InitialContext initialContext = new InitialContext();
                DataSource ds = (DataSource) initialContext.lookup("java:comp/env/jdbc/SourceConnDS");
                Connection sourceconn = ds.getConnection();
                sourceconn.setAutoCommit(false);
                String sql = "Copy from myschema/mypass@DB insert t_dept using select * from dept;"                       
                Statement stat = sourceconn.createStatement();
                stat.executeUpdate(sql);
                sourceconn.commit();
                System.out.println("done");
              catch (Exception ne) {
                // TODO: Add catch code
                ne.printStackTrace();
            return null;
        }

    I have a requirement to transfer data from one db to another db from Java Application Layer.Maybe, maye not. We get all sorts of weird "requirements" - which are nothing but thoughts or proposed solutions.
    But,
    Did the "requirement" mention whether the table existed already or not in the target database? - If not, did it tell you to create it - drop/create it?
    Did the "requirement" deliver some explanation to why this copying was neeeded? - Are we talking replication? - Or a one time cloning?
    Etc, etc,
    Personally I would always argue against a "reuirement" like that. - It just isn't the way to do it. Period.
    Regards
    Peter
    P.S: If you are satisfied with what COPY does, then you could let Java make an OS call and do it from there?

  • How to know which user has executed which ddl statement

    Hi All,
    Last week i faced some problem, like some one has truncated the table , so luckily i have the schema backup so i restored it till the last backup taken.
    but i want to know who has executed this ddl statement.
    i know there are some utilities are avaible with oracle, so please describe me the easiest and quickest way to get this.
    Regards
    Asif

    In order of descending simplicity
    - Use the principle of least privilege to restrict the privileges users have in the database to ensure that they cannot do things like truncating a table
    - Enable auditing of potentially problematic statements. This has to be done before the damage is done, though
    - Create a DDL trigger that logs when users issue DDL. This also must be done before the damage is done.
    - Use LogMiner to go through the archived log files that were generated at the time the table was truncated. This assumes that the database is in ARCHIVELOG mode and that you have the archived logs from last week. Using LogMiner to track down the culprit is also likely to be relatively time-intensive
    Justin

  • How to create a stored procedure in a dynamic schema

    Hi,
    I want to create a stored procedure in a dynamic shcema (schema name will be known at run time). Can any one guide me on this.
    I tried using define var1=schema1; and then in create or replace procedure &var1.porcName( ) but it is not working
    Thanks

    SQL> alter session set current_schema=<my schema>;
    Now create the stored procedure. It will be created in the session's current schema.

  • How do I merge data from table1 on server 1 to final table on server 2 with a stored procedure to execute every so many hours.

    How do I merge data from table1 on server 1 to final table on server 2 with a stored procedure to execute every so
    many hours.

    How big is the table on server B? Is that possible to bring the all data into a server A and merge the data locally?
    Best Regards,Uri Dimant SQL Server MVP,
    http://sqlblog.com/blogs/uri_dimant/
    MS SQL optimization: MS SQL Development and Optimization
    MS SQL Consulting:
    Large scale of database and data cleansing
    Remote DBA Services:
    Improves MS SQL Database Performance
    SQL Server Integration Services:
    Business Intelligence

  • How do I merge data from table1 on server 1 to final table on server 2 with a stored procedure to execute every 4 hours.

    How do I merge data from table1 on server 1 to final table on server 2 with a stored procedure to execute every so many hours.

    Hello,
    If you had configure server2 as
    linked server on the server1, you can run the following statement inside stored proceduce to copy table data. And then create a job to the run stored proceduce every 4 hours.
    Insert Into Server2.Database2.dbo.Table2
    (Cols)
    Select Cols From Server1.Database1.dbo.Table1
    Or you can use the SQL Server Import and Export Wizard to export the data from server1 to server2, save the SSIS package created by the wizard on the SQL Server, create a job to run the SSIS package. 
    Reference:http://technet.microsoft.com/en-us/library/ms141209.aspx
    Regards,
    Fanny Liu
    Fanny Liu
    TechNet Community Support

  • How to execute dynamic if statement...

    Hi All,
    My PL/SQL Blocks looks like this
    declare
    i_string :='if 3>20 then 1 else 2 end if;' varchar2(100);
    begin
    end;
    Between begin and end i want a piece of code which executes that if statement and sends 2 as output in dbms_output.put_line since 3 is not >20 .Basically i want to know how to execute dynamic if statement.Please help
    Thanks,
    Preethi

    Hi,
    i agree with Cyn. Dynamic SQL is often a bad idea. Try to avoid it.
    Dynamic PL/SQL is even worse. If you really must do something dynamic, at least try to cast it as SQL rather than PL/SQL.
    Does this do what you want?
    CREATE OR REPLACE FUNCTION     eval_case
    (     in_txt     IN     VARCHAR2
    RETURN     NUMBER
    DETERMINISTIC
    IS
         return_val     NUMBER;
         sql_txt          VARCHAR2 (1000);
    BEGIN
         sql_txt := 'SELECT  CASE '
              ||           in_txt
              || '         END'
              || '  FROM  dual';
         EXECUTE IMMEDIATE sql_txt INTO return_val;
         RETURN     return_val;
    END     eval_case;
    SHOW ERRORSYou might use the function above like this:
    declare
         i_string  varchar2(100) :='WHEN 3>20 THEN 1 ELSE 2';
    begin
         dbms_output.put_line (  TO_CHAR (eval_case (i_string))
                        || ' = results of eval_case ('''
                        || i_string
                        || ''')'
    end;
    /

  • Finding Stored Procedure(s) Executed

    Hi,
    I need to find which stored procedure got executed when I run my application.
    My application is in .NET and I am using Oracle 9.2.0.5
    Thanks in advance.
    Pravin Pawar

    You can use SQL trace and TKPROF for that.
    1. Creation of PL/SQL and execution of procedures:
    bas002>
    bas002>
    bas002> create or replace procedure p2
      2  is
      3  d date;
      4  begin
      5  select sysdate into d from dual;
      6  end;
      7  /
    Procedure created.
    bas002> show errors
    No errors.
    bas002>
    bas002> create or replace procedure p1
      2  is
      3  n number;
      4  begin
      5  p2;
      6  select count(*) into n from dual;
      7  end;
      8  /
    Procedure created.
    bas002> show errors
    No errors.
    bas002>
    bas002> create or replace procedure p0
      2  is
      3  begin
      4  null;
      5  end;
      6  /
    Procedure created.
    bas002> show errors
    No errors.
    bas002>
    bas002>
    bas002> alter session set sql_trace=true;
    Session altered.
    bas002>
    bas002> exec p1;
    PL/SQL procedure successfully completed.
    bas002>
    bas002> exec p0;
    PL/SQL procedure successfully completed.
    bas002>
    bas002> alter session set sql_trace=false;
    Session altered.2. use TKPROF to get formated trace file:
    tkprof bas002_ora_892.trc output=test.trctest.trc contains:
    TKPROF: Release 10.2.0.2.0 - Production on Wed Jan 30 15:03:54 2008
    Copyright (c) 1982, 2005, Oracle.  All rights reserved.
    Trace file: bas002_ora_892.trc
    Sort options: default
    count    = number of times OCI procedure was executed
    cpu      = cpu time in seconds executing
    elapsed  = elapsed time in seconds executing
    disk     = number of physical reads of buffers from disk
    query    = number of buffers gotten for consistent read
    current  = number of buffers gotten in current mode (usually for update)
    rows     = number of rows processed by the fetch or execute call
    alter session set sql_trace=true
    call     count       cpu    elapsed       disk      query    current        rows
    Parse        0      0.00       0.00          0          0          0           0
    Execute      1      0.00       0.00          0          0          0           0
    Fetch        0      0.00       0.00          0          0          0           0
    total        1      0.00       0.00          0          0          0           0
    Misses in library cache during parse: 0
    Optimizer mode: ALL_ROWS
    Parsing user id: 55 
    BEGIN p1; END;
    call     count       cpu    elapsed       disk      query    current        rows
    Parse        1      0.00       0.00          0          0          0           0
    Execute      1      0.03       0.03          0          0          0           1
    Fetch        0      0.00       0.00          0          0          0           0
    total        2      0.03       0.03          0          0          0           1
    Misses in library cache during parse: 1
    Optimizer mode: ALL_ROWS
    Parsing user id: 55 
    SELECT SYSDATE
    FROM
    DUAL
    call     count       cpu    elapsed       disk      query    current        rows
    Parse        1      0.00       0.01          0          0          0           0
    Execute      1      0.00       0.00          0          0          0           0
    Fetch        1      0.00       0.00          0          0          0           1
    total        3      0.00       0.02          0          0          0           1
    Misses in library cache during parse: 1
    Optimizer mode: ALL_ROWS
    Parsing user id: 55     (recursive depth: 1)
    SELECT COUNT(*)
    FROM
    DUAL
    call     count       cpu    elapsed       disk      query    current        rows
    Parse        1      0.00       0.00          0          0          0           0
    Execute      1      0.00       0.00          0          0          0           0
    Fetch        1      0.00       0.00          0          0          0           1
    total        3      0.00       0.00          0          0          0           1
    Misses in library cache during parse: 1
    Optimizer mode: ALL_ROWS
    Parsing user id: 55     (recursive depth: 1)
    BEGIN p0; END;
    call     count       cpu    elapsed       disk      query    current        rows
    Parse        1      0.00       0.00          0          0          0           0
    Execute      1      0.00       0.00          0          0          0           1
    Fetch        0      0.00       0.00          0          0          0           0
    total        2      0.00       0.00          0          0          0           1
    Misses in library cache during parse: 0
    Optimizer mode: ALL_ROWS
    Parsing user id: 55 
    alter session set sql_trace=false
    call     count       cpu    elapsed       disk      query    current        rows
    Parse        1      0.00       0.00          0          0          0           0
    Execute      1      0.00       0.00          0          0          0           0
    Fetch        0      0.00       0.00          0          0          0           0
    total        2      0.00       0.00          0          0          0           0
    Misses in library cache during parse: 0
    Optimizer mode: ALL_ROWS
    Parsing user id: 55 
    OVERALL TOTALS FOR ALL NON-RECURSIVE STATEMENTS
    call     count       cpu    elapsed       disk      query    current        rows
    Parse        3      0.00       0.00          0          0          0           0
    Execute      4      0.03       0.03          0          0          0           2
    Fetch        0      0.00       0.00          0          0          0           0
    total        7      0.03       0.03          0          0          0           2
    Misses in library cache during parse: 1
    OVERALL TOTALS FOR ALL RECURSIVE STATEMENTS
    call     count       cpu    elapsed       disk      query    current        rows
    Parse        2      0.00       0.01          0          0          0           0
    Execute      2      0.00       0.00          0          0          0           0
    Fetch        2      0.00       0.00          0          0          0           2
    total        6      0.00       0.02          0          0          0           2
    Misses in library cache during parse: 2
        6  user  SQL statements in session.
        0  internal SQL statements in session.
        6  SQL statements in session.
    Trace file: bas002_ora_892.trc
    Trace file compatibility: 10.01.00
    Sort options: default
           1  session in tracefile.
           6  user  SQL statements in trace file.
           0  internal SQL statements in trace file.
           6  SQL statements in trace file.
           6  unique SQL statements in trace file.
          60  lines in trace file.
           0  elapsed seconds in trace file.I don't know if it's possible to get with TKPROF all procedures called by top level procedures (in this example p2 call is missing).
    I made this test with 10.2.0.2 but it should work the same for 9.2.0.5.
    Message was edited by:
    Pierre Forstmann

  • How pass date parametet in procedure while executing

    I am written procerdure in which I have to pass parameter the datatype is date how can I am able to pass the date while executing
    please help me

    ya its from the cient application but I am checking that procedure is executing properly or not so I passing it through prompt.
    I am executing in tha same format given by u, its displaying following error
    BEGIN HANGER_FAILURE_PROCEDURE (to_date('01-jan-05','dd-mon-yy') ); END;
    ERROR at line 1:
    ORA-01001: invalid cursor
    ORA-06512: at "SYSTEM.HANGER_FAILURE_PROCEDURE", line 62
    ORA-06512: at line 1
    ===============================
    And my procedure is
    CREATE OR REPLACE PROCEDURE HANGER_FAILURE_PROCEDURE (startDate IN FRIT_HANGER.AGING_START_TIME%TYPE ) IS
    shiftDescription SHIFT.DESCRIPTION%TYPE;
    failure_number HANGER_FAILURE.FAILURE_NUMBER%TYPE;
    failure HANGER_FAILURE.FAILURE_NUMBER%TYPE;
    fritID LVT_TEST.FRIT_ID%TYPE ;
    lvt_description LVT.DESCRIPTION%TYPE;
    test_time LVT_TEST.TEST_TIME%TYPE ;
    mikr LVT_TEST.MIKR%TYPE;
    mikr_res LVT_TEST.MIKR_PASSED%TYPE;
    mikg LVT_TEST.MIKG%TYPE;
    mikg_res LVT_TEST.MIKG_PASSED%TYPE;
    mikb LVT_TEST.MIKB%TYPE;
    mikb_res LVT_TEST.MIKB_PASSED%TYPE;
    coe2r LVT_TEST.COE2R%TYPE;
    coe2r_res LVT_TEST.COE2R_PASSED%TYPE;
    coe2g LVT_TEST.COE2G%TYPE;
    coe2g_res LVT_TEST.COE2G_PASSED%TYPE;
    coe2b LVT_TEST.COE2B%TYPE;
    coe2b_res LVT_TEST.COE2B_PASSED%TYPE;
    grparameter AGING_TEST.GR%TYPE;
    ccr VTS_TEST.CCR%TYPE;
    ccg VTS_TEST.CCG%TYPE;
    ccb VTS_TEST.CCB%TYPE;
    aging_hangerId AGING_HANGER.AGING_HANGER_ID%TYPE;
    aging_start_time FRIT_HANGER.AGING_START_TIME%TYPE;
    failure_type HANGER_FAILURE_TYPE.HANGER_FAILURE_TYPE_ID%TYPE;
    CURSOR result_lvt(sdate FRIT_HANGER.AGING_START_TIME%TYPE) IS
    SELECT
    AGING_HANGER.AGING_HANGER_ID,
    LVT.DESCRIPTION,
    FRIT_HANGER.AGING_START_TIME,
    LVT_TEST.FRIT_ID,
    LVT_TEST.TEST_TIME,
    LVT_TEST.MIKR,
    LVT_TEST.MIKR_PASSED,
    LVT_TEST.MIKG,
    LVT_TEST.MIKG_PASSED,
    LVT_TEST.MIKB,
    LVT_TEST.MIKB_PASSED,
    LVT_TEST.COE2R,
    LVT_TEST.COE2R_PASSED,
    LVT_TEST.COE2G,
    LVT_TEST.COE2G_PASSED,
    LVT_TEST.COE2B,
    LVT_TEST.COE2B_PASSED
    FROM LVT_TEST,LVT,FRIT_HANGER,AGING_HANGER
    WHERE LVT_TEST.LVT_ID=LVT.LVT_ID
    AND
    FRIT_HANGER.AGING_HANGER_ID=AGING_HANGER.AGING_HANGER_ID
    AND LVT_TEST.FRIT_ID=FRIT_HANGER.FRIT_ID
    AND FRIT_HANGER.AGING_START_TIME>sdate
    ORDER BY FRIT_HANGER.AGING_START_TIME;
    BEGIN
    IF result_lvt%ISOPEN THEN
    OPEN result_lvt(startDate);
    END IF;
    LOOP
    FETCH result_lvt
    INTO aging_hangerId, lvt_description, aging_start_time, fritID, test_time, mikr, mikr_res, mikg, mikg_res, mikb, mikb_res, coe2r, coe2r_res, coe2g, coe2g_res, coe2b, coe2b_res;
    exit when result_lvt%NOTFOUND;
    SELECT GR INTO grparameter
    FROM AGING_TEST
    WHERE
    TEST_TIME = (SELECT MAX(TEST_TIME) FROM AGING_TEST WHERE FRIT_ID = fritID);
    SELECT CCR, CCG, CCB INTO ccr,ccg,ccb
    FROM VTS_TEST
    WHERE TEST_TIME = (SELECT MAX(TEST_TIME) FROM VTS_TEST WHERE FRIT_ID = fritID);
    SELECT DESCRIPTION INTO shiftDescription
    FROM SHIFT
    WHERE START_TIME=TRUNC( aging_start_time);
    IF( mikr_res=0 OR mikg_res = 0 OR mikb_res = 0 )
    THEN
    SELECT MAX(FAILURE_NUMBER) INTO failure
    FROM HANGER_FAILURE
    WHERE AGING_HANGER_ID=aging_hangerId
    AND TO_DATE(AGING_START_TIME) = TO_DATE(aging_start_time)
    AND
    SHIFT_DESCRIPTION = shiftDescription;
    failure_number:=failure+1;
    SELECT HANGER_FAILURE_TYPE_ID INTO failure_type
    FROM HANGER_FAILURE_TYPE
    WHERE DESCRIPTION='MIK';
    INSERT INTO HANGER_FAILURE (HANGER_FAILURE_ID, HANGER_FAILURE_TYPE_ID, AGING_HANGER_ID,
    SHIFT_DESCRIPTION, AGING_START_TIME, FAILURE_NUMBER, LVT_DESCRIPTION,FRIT_ID,TEST_TIME, MIKR, MIKG, MIKB, COE2R, COE2G, COE2B, GR,CCR, CCG ,CCB ) VALUES(HANGER_FAILURE_ID_GENERATOR.NEXTVAL, failure_type, aging_hangerId, shiftDescription,aging_start_time,failure_number ,lvt_description, fritID,test_time, mikr,mikg,mikb,coe2r,coe2g,coe2b,grparameter,ccr,ccg,ccb);
    ELSE
    DBMS_OUTPUT.PUT_LINE('Doesn''t occur any MIK failure');
    END IF;
    IF (coe2r_res = 0 OR coe2g_res = 0 OR coe2b_res = 0)
    THEN
    SELECT MAX(FAILURE_NUMBER) INTO failure
    FROM HANGER_FAILURE
    WHERE AGING_HANGER_ID=aging_hangerId
    AND TO_DATE(AGING_START_TIME) = TO_DATE(aging_start_time)
    AND
    SHIFT_DESCRIPTION = shiftDescription;
    failure_number :=failure+1;
    SELECT HANGER_FAILURE_TYPE_ID INTO failure_type
    FROM HANGER_FAILURE_TYPE
    WHERE DESCRIPTION='COE2';
    INSERT INTO HANGER_FAILURE (HANGER_FAILURE_ID,HANGER_FAILURE_TYPE_ID,AGING_HANGER_ID,
    SHIFT_DESCRIPTION,AGING_START_TIME ,FAILURE_NUMBER, LVT_DESCRIPTION,FRIT_ID,TEST_TIME,MIKR,MIKG,MIKB,COE2R,COE2G,
    COE2B,GR ,CCR,CCG ,CCB ) VALUES(HANGER_FAILURE_ID_GENERATOR.NEXTVAL, failure_type, aging_hangerId, shiftDescription,aging_start_time,failure_number ,lvt_description, fritID,test_time, mikr,mikg,mikb,coe2r,coe2g,coe2b,grparameter,ccr,ccg,ccb);
    ELSE
    DBMS_OUTPUT.PUT_LINE('Doesn''t occur any COE2 failure');
    END IF;
    END LOOP;
    CLOSE result_lvt;
    END;
    plz help me

Maybe you are looking for