Look for histroy of sql statement executed in database

is there a way to look for histroy or list of sql statement executed in database.?
similar to history command in linux or bash shell.

The newer <a href="http://download.oracle.com/docs/cd/B19306_01/server.102/b14237/dynviews_2131.htm">v$sqlstats</a> (10g) is recommended over v$sql as (according to the documentation) it's "faster, more scalable, and has a greater data retention (the statistics may still appear in this view, even after the cursor has been aged out of the shared pool)", although it's missing a couple of the columns v$sql has.
The history version (if you are licenced for AWR, which is part of the extra-cost Diagnostics Pack - you may not be licenced to use it even if the dictionary views are installed) is DBA_HIST_SQLSTAT.

Similar Messages

  • Log for all the sql statement executed

    Hi,
    I would like to know how to see the log for all the sql statement executed starting from connection to all the database related actions.
    Is it something that i need to set it up in the driver?
    I'm using Tomcat and JDBC driver.
    Please reply.
    Thanks,
    Anjana

    Make your own.
    Calendar cal = new GregorianCalendar();
    int year = cal.get(Calendar.YEAR);
    int month = cal.get(Calendar.MONTH) + 1;
    int day = cal.get(Calendar.DAY_OF_MONTH);
    //use calendar object to get other infos such as time of query
    //append your query string
    File f  =new File ("c:\\jakarta-tomcat-3.2.4\\webapps\\ASD\\LOGS\\log" + df.format(day) + df.format(month) + year + ".txt");
                   if (! f.exists())
                        f.createNewFile();
                   FileWriter fw = new FileWriter (f, true);
                   // append new log to end of file
                   fw.write(buf.toString());
                   fw.write("\n");
                   fw.flush();
                   fw.close();
              catch (IOException ioe)
                   System.out.println(ioe.toString());

  • Tracking SQL statements executed

    Hi,
    After obtaining a connection to my Oracle 10g database using JDBC, I would like to know if there is a way to track all SQL statements executed since the connection was made.
    This must be pretty easy, I'm just stumped.
    Thank you
    Tom

    Hi, and it's not that easy. The driver certainly doesn't
    keep track of what's been done, but look at the documentation
    regarding the logging the driver can be configured to do. It can
    print out everything it does, so some level of detail and degree,
    and that can be collected in a file and examined externally.
    That can be voluminous too... It might be more (or just as)
    practical to examine the DBMS-side session-auditing/logging
    features the DBMS may have to collect everything the session
    has done.
    HTH,
    Joe Weinstein at BEA Systems

  • SQL STATEMENT EXECUTES

    Hi All
    HOw oracle SQL statements executes ? Can anyone explain me for SELECT, INSERT,UPDATE and COMMIT statements works ?
    Regards
    Krishna

    Krishna,
    Search for SQL Statement Execution and see the Flow Chart.
    http://download-west.oracle.com/docs/cd/B19306_01/server.102/b14220/sqlplsql.htm
    -Anantha

  • Multiple Executions Plans for the same SQL statement

    Dear experts,
    awrsqrpt.sql is showing multiple executions plans for a single SQL statement. How is it possible that one SQL statement will have multiple Executions Plans within the same AWR report.
    Below is the awrsqrpt's output for your reference.
    WORKLOAD REPOSITORY SQL Report
    Snapshot Period Summary
    DB Name         DB Id    Instance     Inst Num Release     RAC Host
    TESTDB          2157605839 TESTDB1               1 10.2.0.3.0  YES testhost1
                  Snap Id      Snap Time      Sessions Curs/Sess
    Begin Snap:     32541 11-Oct-08 21:00:13       248     141.1
      End Snap:     32542 11-Oct-08 21:15:06       245     143.4
       Elapsed:               14.88 (mins)
       DB Time:               12.18 (mins)
    SQL Summary                            DB/Inst: TESTDB/TESTDB1  Snaps: 32541-32542
                    Elapsed
       SQL Id      Time (ms)
    51szt7b736bmg     25,131
    Module: SQL*Plus
    UPDATE TEST SET TEST_TRN_DAY_CL = (SELECT (NVL(ACCT_CR_BAL,0) + NVL(ACCT_DR_BAL,
    0)) FROM ACCT WHERE ACCT_TRN_DT = (:B1 ) AND TEST_ACC_NB = ACCT_ACC_NB(+)) WHERE
    TEST_BATCH_DT = (:B1 )
    SQL ID: 51szt7b736bmg                  DB/Inst: TESTDB/TESTDB1  Snaps: 32541-32542
    -> 1st Capture and Last Capture Snap IDs
       refer to Snapshot IDs witin the snapshot range
    -> UPDATE TEST SET TEST_TRN_DAY_CL = (SELECT (NVL(ACCT_CR_BAL,0) + NVL(AC...
        Plan Hash           Total Elapsed                 1st Capture   Last Capture
    #   Value                    Time(ms)    Executions       Snap ID        Snap ID
    1   2960830398                 25,131             1         32542          32542
    2   3834848140                      0             0         32542          32542
    Plan 1(PHV: 2960830398)
    Plan Statistics                        DB/Inst: TESTDB/TESTDB1  Snaps: 32541-32542
    -> % Total DB Time is the Elapsed Time of the SQL statement divided
       into the Total Database Time multiplied by 100
    Stat Name                                Statement   Per Execution % Snap
    Elapsed Time (ms)                            25,131       25,130.7     3.4
    CPU Time (ms)                                23,270       23,270.2     3.9
    Executions                                        1            N/A     N/A
    Buffer Gets                               2,626,166    2,626,166.0    14.6
    Disk Reads                                      305          305.0     0.3
    Parse Calls                                       1            1.0     0.0
    Rows                                        371,735      371,735.0     N/A
    User I/O Wait Time (ms)                         564            N/A     N/A
    Cluster Wait Time (ms)                            0            N/A     N/A
    Application Wait Time (ms)                        0            N/A     N/A
    Concurrency Wait Time (ms)                        0            N/A     N/A
    Invalidations                                     0            N/A     N/A
    Version Count                                     2            N/A     N/A
    Sharable Mem(KB)                                 26            N/A     N/A
    Execution Plan
    | Id  | Operation                    | Name            | Rows  | Bytes | Cost (%CPU)| Time     |
    |   0 | UPDATE STATEMENT             |                 |       |       |  1110 (100)|          |
    |   1 |  UPDATE                      | TEST            |       |       |            |          |
    |   2 |   TABLE ACCESS FULL          | TEST            |   116K|  2740K|  1110   (2)| 00:00:14 |
    |   3 |   TABLE ACCESS BY INDEX ROWID| ACCT            |     1 |    26 |     5   (0)| 00:00:01 |
    |   4 |    INDEX RANGE SCAN          | ACCT_DT_ACC_IDX |     1 |       |     4   (0)| 00:00:01 |
    Plan 2(PHV: 3834848140)
    Plan Statistics                        DB/Inst: TESTDB/TESTDB1  Snaps: 32541-32542
    -> % Total DB Time is the Elapsed Time of the SQL statement divided
       into the Total Database Time multiplied by 100
    Stat Name                                Statement   Per Execution % Snap
    Elapsed Time (ms)                                 0            N/A     0.0
    CPU Time (ms)                                     0            N/A     0.0
    Executions                                        0            N/A     N/A
    Buffer Gets                                       0            N/A     0.0
    Disk Reads                                        0            N/A     0.0
    Parse Calls                                       0            N/A     0.0
    Rows                                              0            N/A     N/A
    User I/O Wait Time (ms)                           0            N/A     N/A
    Cluster Wait Time (ms)                            0            N/A     N/A
    Application Wait Time (ms)                        0            N/A     N/A
    Concurrency Wait Time (ms)                        0            N/A     N/A
    Invalidations                                     0            N/A     N/A
    Version Count                                     2            N/A     N/A
    Sharable Mem(KB)                                 26            N/A     N/A
    Execution Plan
    | Id  | Operation                    | Name         | Rows  | Bytes | Cost (%CPU)| Time     |
    |   0 | UPDATE STATEMENT             |              |       |       |     2 (100)|          |
    |   1 |  UPDATE                      | TEST         |       |       |            |          |
    |   2 |   TABLE ACCESS BY INDEX ROWID| TEST         |     1 |    28 |     2   (0)| 00:00:01 |
    |   3 |    INDEX RANGE SCAN          | TEST_DT_IND  |     1 |       |     1   (0)| 00:00:01 |
    |   4 |   TABLE ACCESS BY INDEX ROWID| ACCT         |     1 |    26 |     4   (0)| 00:00:01 |
    |   5 |    INDEX RANGE SCAN          | INDX_ACCT_DT |     1 |       |     3   (0)| 00:00:01 |
    Full SQL Text
    SQL ID       SQL Text
    51szt7b736bm UPDATE TEST SET TEST_TRN_DAY_CL = (SELECT (NVL(ACCT_CR_BAL, 0) +
                  NVL(ACCT_DR_BAL, 0)) FROM ACCT WHERE ACCT_TRN_DT = (:B1 ) AND PB
                 RN_ACC_NB = ACCT_ACC_NB(+)) WHERE TEST_BATCH_DT = (:B1 )Your input is highly appreciated.
    Thanks for taking your time in answering my question.
    Regards

    Oracle Lover3 wrote:
    Dear experts,
    awrsqrpt.sql is showing multiple executions plans for a single SQL statement. How is it possible that one SQL statement will have multiple Executions Plans within the same AWR report.If you're using bind variables and you've histograms on your columns which can be created by default in 10g due to the "SIZE AUTO" default "method_opt" parameter of DBMS_STATS.GATHER__STATS it is quite normal that you get different execution plans for the same SQL statement. Depending on the values passed when the statement is hard parsed (this feature is called "bind variable peeking" and enabled by default since 9i) an execution plan is determined and re-used for all further executions of the same "shared" SQL statement.
    If now your statement ages out of the shared pool or is invalidated due to some DDL or statistics gathering activity it will be re-parsed and again the values passed in that particular moment will determine the execution plan. If you have skewed data distribution and a histogram in place that reflects that skewness you might get different execution plans depending on the actual values used.
    Since this "flip-flop" behaviour can sometimes be counter-productive if you're unlucky and the values used to hard parse the statement leading to a plan that is unsuitable for the majority of values used afterwards, 11g introduced the "adaptive" cursor sharing that attempts to detect such a situation and can automatically re-evaluate the execution plan of the statement.
    Regards,
    Randolf
    Oracle related stuff blog:
    http://oracle-randolf.blogspot.com/
    SQLTools++ for Oracle (Open source Oracle GUI for Windows):
    http://www.sqltools-plusplus.org:7676/
    http://sourceforge.net/projects/sqlt-pp/

  • Where to run SQL statements in Oracle Database 11gR1 ?

    Folks,
    Hello. I have just installed Oracle Database 11gR1 and login to Database Control page. There are 4 tabs on the top: Database, Setup, Preference, Help and Logout.
    I just create a table "table1" in "Database" tap. But I don't see anywhere to run SQL statement such as Select, Insert, Update.
    Can any folk tell me where to run SQL statements in Oracle Database 11gR1 ?
    Or
    Can any folk provide a User Manual for Oracle DB 11gR1 ?

    You can run from a terminal or install an SQL client and connect from there.
    http://www.articlesbase.com/databases-articles/how-to-install-oracle-11g-client-1793770.html
    Best Regards
    mseberg
    Assuming you have an oracle OS user on Linux you can try typing sqlplus at you OS command prompt. Generally you will have a .bash_profile with setting like this:
    # User specific environment and startup programs
    PATH=$PATH:$HOME/bin
    export PATH
    # Oracle Settings
    TMP=/tmp; export TMP
    TMPDIR=$TMP; export TMPDIR
    export ORACLE_BASE=/u01/app/oracle
    export ORACLE_HOME=/u01/app/oracle/product/11.2.0
    #export DISPLAY=localhost:0.0
    export TZ=CST6CDT 
    export ORACLE_SID=ORCL
    export ORACLE_TERM=xterm
    #export TNS_ADMIN= Set if sqlnet.ora, tnsnames.ora, etc. are not in $ORACLE_HOME/network/admin
    export NLS_LANG=AMERICAN;
    LD_LIBRARY_PATH=$ORACLE_HOME/lib:/lib:/usr/lib
    LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/lib
    export LD_LIBRARY_PATH
    # Set shell search paths
    PATH=/usr/sbin:$PATH; export PATH
    export PATH=$PATH:$ORACLE_HOME/bin
    # CLASSPATH:
    CLASSPATH=$ORACLE_HOME/JRE:$ORACLE_HOME/jlib:$ORACLE_HOME/rdbms/jlib
    CLASSPATH=$CLASSPATH:$ORACLE_HOME/network/jlib
    export EDITOR=vi
    set -o vi
    PS1='$PWD:$ORACLE_SID >'Edited by: mseberg on Jul 11, 2011 3:18 PM

  • Workspace to parse SQL statements from multiple database schema's

    Hi ,
    When go through the following link of workspace admin user :
    Home>HTML DB Workspace Administration>Manage Services>Schema Reports>Workspace Schemas there I saw "Your workspace has the privilege to parse SQL statements using the following database schemas. Note that the terms database schema and database user can be used interchangeably.
    " at the right pane.
    So how can i make my workspace to parse SQL statements from multiple database schema's ?That must be listed there .But i have only one schema in view ? Can i make it multiple ?If then How ?
    Anybody have an idea ?
    ROSY

    Assign as many schemas to your workspace as you want using the administration app. Read about it in the doc.
    Scott

  • Looking for a form in the VIS demo database with lots of data

    Hi all,
    I am looking for a form in the VIS demo database (that ships with Oracle Applications) that contains a lot (1 MB or more) of data. Specifically, when I perform some type of search in the form, I would like more than 1 MB of data to be transferred over the network to the client.
    With Oracle Applications 11i, I was using this form: CRM Resource Manager, Vision Enterprises &rarr; Resources
    This was nice because searching for all resources resulted in 4.6 MB of data being sent by the server. However, in Oracle Applications R12, the same query in the same form only sends about 100 KB of data. :-(
    Does anyone know any other forms that have lots of data in them?
    - Kyle

    Thanks for that - I found the form. However, it appears the database table is empty - when I perform a search for all jobs, no records are returned.Nevermind, after some trial and error I found a site that had lots of jobs defined. Thanks for the pointer!
    I'm still running into the same problem I was seeing with the previous form I was using. This is what I'm doing:
    1. Open the form.
    2. Search for all records.
    3. Jump to the very last record.
    In Oracle Applications 11i, this would cause a large amount of data to be transferred over the network (4.6 MB for the previous form I was using and 2.6 MB for this new "Discrete Jobs" form I'm trying). However, the behavior is different in Oracle Applications R12. When I perform the same steps in the same forms, only a fraction of the data is transferred over the network (~100 KB).
    Ideally, I would like a set of steps (and a form) that will produce the same results in both 11i and R12. More realistically, I just need a form (or a new test procedure) in R12 that will spit out more than 1 MB of data.

  • How to trace the SQL statements executed in a database

    I am using Oracle9i Enterprise Edition Release 9.2.0.7.0 - 64bit Production on a sun server and I am not familiar with Oracle but with MS SQL there is a tool called profiler, it allows you to monitor and see what is going on in a specific databases whether it is SQL statement executins or anything else. I have installed the oracle enterpise manager console at my windows client and I tried to look for a tool similar to the profiler in the MS SQL. I tried the TRACE DATA VIEWER and I inputed the login credentials but I don' t actually know the service name and I am getting an error ORA-12514 The TSN listener can not resolve the service name given in the connect descriptor. Therefore, am I on the right road so i have to look for the service name or are there any other ways i can trace the currently executing SQL statement in a specific database. I am really stuck there. I would appreciate if somebody help me out. Thanks
    Abdel Moalim

    Abdel Moalim wrote:
    I am using Oracle9i Enterprise Edition Release 9.2.0.7.0 - 64bit Production on a sun server and I am not familiar with Oracle but with MS SQL there is a tool called profiler, it allows you to monitor and see what is going on in a specific databases whether it is SQL statement executins or anything else. I have installed the oracle enterpise manager console at my windows client and I tried to look for a tool similar to the profiler in the MS SQL. I tried the TRACE DATA VIEWER and I inputed the login credentials but I don' t actually know the service name and I am getting an error ORA-12514 The TSN listener can not resolve the service name given in the connect descriptor. Therefore, am I on the right road so i have to look for the service name or are there any other ways i can trace the currently executing SQL statement in a specific database. I am really stuck there. I would appreciate if somebody help me out. Thanks
    Abdel MoalimHi
    I see others have answered the network connectivity issues, I'll try and address the tracing issue. Your best bet is to review http://www.petefinnigan.com/ramblings/how_to_set_trace.htm for the many ways in which a sessions SQL and indeed other activity can be traced. In version 7 (which I'm guessing is yours from the sid) the only profiler available was tkprof (Trace Kernel Profiler) which will do a good job of analysing your trace file. The trace files themselves are generated on the server in a protected directory so you may need to ask your dba for access to them. There are other profilers around now (I have one which runs in v9 and higher database at http://www.niall.litchfield.dial.pipex.com/SimpleProfiler/SimpleProfiler.html which will analyse your files for example) but tkprof is the start point - or else just reading the trace file in a text editor. There is also a utility written by the Oracle Apps guys trcanalyzer that will do a good job for you. In general the interface is poor compared with the ms utility but the information is deeper and more helpful
    Niall Litchfield
    http://www.orawin.info/

  • One SQL Statement executed abnormally in Oracle10g Database

    One programmer sent the following SQL to me, and ask why no result was returned. I knew that the SQL Statement was not good in writting and designing.
    So, first we don't focus on it. we only focus on why no result was returned.
    SELECT 'other Accts', 'Other Accts', TO_NUMBER(''),TO_DATE('2010-10-9', 'yyyy-MM-dd')
    FROM dual
    WHERE *0 = (SELECT COUNT(*)*
    FROM (SELECT 'other Accts', 'Other Accts',SUM(a.qty_invoiced), a.sell_week_date
    FROM sales_in_oracle_data a
    WHERE NOT EXISTS
    (SELECT pa.partner_number
    FROM partner pa
    WHERE pa.partner_number = a.customer_number)
    AND a.sell_week_date >=TO_DATE('2010-10-9', 'yyyy-MM-dd')
    AND a.sell_week_date <=TO_DATE('2011-1-1', 'yyyy-MM-dd')
    AND a.qty_invoiced >= 0
    AND EXISTS
    (SELECT pp.product_id
    FROM product_pn pp, product p
    WHERE pp.magellan_pn = a.material
    AND pp.product_id = p.product_id )
    GROUP BY a.sell_week_date
    the SQL sub Statement:
    SELECT COUNT(*)*
    FROM (SELECT 'other Accts', 'Other Accts',SUM(a.qty_invoiced), a.sell_week_date
    FROM sales_in_oracle_data a
    WHERE NOT EXISTS
    (SELECT pa.partner_number
    FROM partner pa
    WHERE pa.partner_number = a.customer_number)
    AND a.sell_week_date >=TO_DATE('2010-10-9', 'yyyy-MM-dd')
    AND a.sell_week_date <=TO_DATE('2011-1-1', 'yyyy-MM-dd')
    AND a.qty_invoiced >= 0
    AND EXISTS
    (SELECT pp.product_id
    FROM product_pn pp, product p
    WHERE pp.magellan_pn = a.material
    AND pp.product_id = p.product_id )
    GROUP BY a.sell_week_date
    it returned 0 truely. But the entire SQL didn't return any data.
    why can it execute like above description?  I guess that it maybe go against oracle basic rule.
    Any one give me some suggestion?
    Edited by: [email protected] on 2010/7/19 下午 6:09

    I managed to track down a 10.2.0.4 instance and can confirm that this statement does not return the correct results.
    Connected to:
    Oracle Database 10g Enterprise Edition Release 10.2.0.4.0 - 64bit Production
    With the Partitioning, OLAP, Data Mining and Real Application Testing options
    SQL> select *
      2  from   dual
      3  where  0 = (select count(*)
      4              from  (select dummy, sum(1)
      5                     from   dual
      6                     where  dummy = 'z'
      7                     group  by dummy
      8                    )
      9             );
    no rows selected
    SQL> explain plan for
      2  select *
      3  from   dual
      4  where  0 = (select count(*)
      5              from  (select dummy, sum(1)
      6                     from   dual
      7                     where  dummy = 'z'
      8                     group  by dummy
      9                    )
    10             );
    Explained.
    | Id  | Operation           | Name | Rows  | Bytes | Cost (%CPU)| Time     |
    |   0 | SELECT STATEMENT    |      |     1 |     2 |     4   (0)| 00:00:01 |
    |*  1 |  FILTER             |      |       |       |            |          |
    |   2 |   TABLE ACCESS FULL | DUAL |     1 |     2 |     2   (0)| 00:00:01 |
    |   3 |   SORT AGGREGATE    |      |     1 |     2 |            |          |
    |*  4 |    TABLE ACCESS FULL| DUAL |     1 |     2 |     2   (0)| 00:00:01 |
    Predicate Information (identified by operation id):
       1 - filter( NOT EXISTS (SELECT /*+ */ 0 FROM "SYS"."DUAL" "DUAL"
                  WHERE "DUMMY"='z'))
       4 - filter("DUMMY"='z')
    Connected to:
    Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - 64bit Production
    With the Partitioning, Real Application Clusters, OLAP, Data Mining
    and Real Application Testing options
    SQL> select *
      2  from   dual
      3  where  0 = (select count(*)
      4              from  (select dummy, sum(1)
      5                     from   dual
      6                     where  dummy = 'z'
      7                     group  by dummy
      8                    )
      9             );
    D
    X
    SQL> explain plan for
      2  select *
      3  from   dual
      4  where  0 = (select count(*)
      5              from  (select dummy, sum(1)
      6                     from   dual
      7                     where  dummy = 'z'
      8                     group  by dummy
      9                    )
    10             );
    Explained.
    | Id  | Operation          | Name | Rows  | Bytes | Cost (%CPU)| Time     |
    |   0 | SELECT STATEMENT   |      |     1 |     2 |     6   (0)| 00:00:01 |
    |*  1 |  FILTER            |      |       |       |            |          |
    |   2 |   TABLE ACCESS FULL| DUAL |     1 |     2 |     3   (0)| 00:00:01 |
    |*  3 |   TABLE ACCESS FULL| DUAL |     1 |     2 |     3   (0)| 00:00:01 |
    Predicate Information (identified by operation id):
       1 - filter( NOT EXISTS (SELECT 0 FROM "SYS"."DUAL" "DUAL" WHERE
                  "DUMMY"='z'))
       3 - filter("DUMMY"='z')
    17 rows selected.Notice that the explain plan is a bit different compared to the 11.2.0.1 release. My guess is that the optimizer is doing something weird.

  • Looking for Sendmail PL/SQL Package

    Hi All,
    I am looking for a way to call Sendmail directly from a PL/SQL
    Procedure. Can someone point me in a direction where I can find
    some PL/SQL or Pro*C Code that could do this? Thanks,
    Scott Walton
    null

    Scott Walton (guest) wrote:
    : Hi All,
    : I am looking for a way to call Sendmail directly from a PL/SQL
    : Procedure. Can someone point me in a direction where I can
    find
    : some PL/SQL or Pro*C Code that could do this? Thanks,
    : Scott Walton
    PL/SQL does not have a package that allows a PL/SQL program to
    make a System call to execute a command on the OS. It can be
    done in Pro*C, however, and Oracle has a couple of app notes
    that talk about this. You create a Pro*C program that runs -
    sort of like a daemon - that waits for commands sent from a
    PL/SQL program via DBMS_PIPES. One is a Bulletin called "How to
    Generate E-Mail within PL/SQL Routines", ID= "<Note:66347.1>".
    The other is from the Problem Repository called "DYNAMIC SQL AND
    SYSTEM COMMANDS USING DBMS_PIPE", Problem ID= 1005666.6
    Hope that helps.
    null

  • Looking for good pl/sql case studies/hands on exercises

    Hi there,
    I am new to plsql. Looking for some good pl/sql case studies/hands on exercises/small prototype project etc to learn the basic nitty-gritty.
    Can anybody please help?
    Many Thanks,
    Avishek

    this page http://itcareershift.com/blog1/2010/11/15/plsql-exercises/ contains different types of sql statements used inside pl/sql..when you say case studies do you mean examples for each and every concept of pl/sql starting from stored procedures , packages , functions, triggers , collections etc?

  • RFC for remote Open SQL statement

    I'm looking for the SAP delivered RFC that will allow me to perform an SQL statement (select) onto another server.
    I've used this before (years ago) but can't remember the FM name.
    Please help!
    Thanks,
    Andre

    Did you try [RemoteOpenSQL|http://remoteopensql.codeplex.com/] ?
    Filippo

  • Procedure creation for 2 different sql statement

    Hi all,
    When I run a procedure with the below line:
    cursor c1 is select object_name from user_objects where object_type='VIEW' and status='VALID';
    procedure gets created successfully
    But for the below line , oracle throws error
    cursor c1 is select object_name from dba_objects where object_type='VIEW' and status='VALID';
    Error Message:
    Warning: Procedure created with compilation errors.
    3/14 PL/SQL: SQL Statement ignored
    3/38 PL/SQL: ORA-00942: table or view does not exist
    Thanks for all your help.

    The below procedure gets created successfully:
    CREATE OR REPLACE PROCEDURE P_TEST (schema_name in varchar2,new_usr in varchar2)
    is
    str varchar2(1000);
    str_syn varchar2(1000);
    v_obj_name varchar2(200);
    begin
    for z in ( select object_name from user_objects where object_type in ('VIEW') and status='VALID')
    loop
    v_obj_name:=schema_name||'.'|| z.object_name;
    str :='grant select on '||v_obj_name||' to '|| new_usr ;
    EXECUTE IMMEDIATE str;
    end loop;
    end;
    where as below one throws error difference being "user_objects" replaced with
    "dba_objects"
    CREATE OR REPLACE PROCEDURE P_TEST (schema_name in varchar2,new_usr in varchar2)
    is
    str varchar2(1000);
    str_syn varchar2(1000);
    v_obj_name varchar2(200);
    begin
    for z in ( select object_name from dba_objects where object_type in ('VIEW') and status='VALID')
    loop
    v_obj_name:=schema_name||'.'|| z.object_name;
    str :='grant select on '||v_obj_name||' to '|| new_usr ;
    EXECUTE IMMEDIATE str;
    end loop;
    end;

  • Transaction or standard program for testing Open SQL statements

    Hi experts,
    Is there a standard program or transaction that can be used to test Open SQL statements?, I was thinking in something similar to a SQL client like sqlcli, but for Open SQL and within SAP GUI.
    I know i can write a test ABAP program for this matter but I rather a standard testing facily in this case
    Thank you for any help
    regards

    Hi Ozcan
    I tried DB02 -> Diagnosis -> SQL Command editor , but I couldn't made it work. It is for Open SQL or for Native SQL?
    I tried the following simple Open SQL statements inside the SQL Code tab there were erros
    SELECT *
    FROM /BI0/PCOMP_CODE
    error was: Incorrect syntax near '/'.
    SELECT * FROM DD03L
    error was: Invalid object name 'DD03L'.
    Where is the mistake?
    regards

Maybe you are looking for