Select   from all_tables inside a procedure brings a different result set

Hi all,
There are two cases.. both are the same, but gives different out put.
CASE 1 pulls few for SYS and all for current user.
CASE 2 Pulls data for ALL USERS.
Why the same code in side a procedure brings a different result ?
SQL>
--CASE 1
CREATE OR REPLACE procedure test_t_owner as
cursor cur1 is select table_name,owner from all_Tables;
begin
for rec1 in cur1
loop
dbms_output.put_line(rec1.table_name||'--'||rec1.owner);
end loop;
end;
set serveroutpu on;
exec test_t_owner
--CASE 2
Declare
cursor cur1 is select table_name,owner from all_Tables;
begin
for rec1 in cur1
loop
dbms_output.put_line(rec1.table_name||'--'||rec1.owner);
end loop;
end;
- regards
sk

i create one new user
create user test identified by test;
grant connect, select any table to test;
grant dba to test;according to you then i run the procedure test_t_owner it should be give error
and i case of AB it should return all rows from all_tables.
But give output same in but sames.
Regards
Singh

Similar Messages

  • DiscoverSQL2005DBEngineDiscovery.vbs : The Query 'select * from __NAMESPACE where Name ='ComputerManagement'' returned an invalid result set.

    hi
    I am keep receiving this message in central administration running server in event viewer
    DiscoverSQL2005DBEngineDiscovery.vbs : The Query 'select * from __NAMESPACE where Name ='ComputerManagement'' returned an invalid result set.  Please check to see if this is a valid WMI Query.. Object required
    adil

    Hi adil,
    It seems to be not related to SharePoint issue, I find a similar error post from Operations Manager forum you can take a look
    Also another below article of basic troubleshooting of discovery scripts for your reference.
    And for the further better assistance regarding this issue, you may want to post Operations Manager forum here.
    http://social.technet.microsoft.com/Forums/systemcenter/en-US/21e9de85-5cbc-4217-8d9b-921e13dc88dc/sql-mp-issues-with-discovery-vbs-scripts?forum=operationsmanagermgmtpacks
    http://blogs.technet.com/b/kevinholman/archive/2010/03/09/basic-troubleshooting-of-discovery-scripts.aspx
    Thanks
    Daniel Yang
    TechNet Community Support

  • How to Create a new column from two different result sets

    How to Create a new column from two different result sets, both the result set uses the different date dimensions.

    i got solutions for this is apply filters in column formula it self, based on the requirement.

  • Design a procedure which returns a result set of a select Query

    Hi...
    Can some one help me out with a brief design or work around for creating a stored procedure which runs a select Query and Returns a result set...
    If not a stored procedure, at least a function which makes the job simple....
    Awaiting help in this regard ........

    Hi...
    I am sorry for providing insufficient Info...
    Actually I am using Oracle 10G DB...
    I have a select Query..
    Since I am a part of team which is building a Complete Data Driven site, Even an SQL Query and a PL/SQL function body was stored in the Table itself to bring in some kind of Dynamism in the site.... But the master table was loaded with a lot of data and hence Now we decided to Store everythin in a generic package..
    I used REF CURSORS to store a result set of a simple SELECT Query.... and declaring it as an out parameter in my Procedure body so that the JAVA team can directly access the Procedure from the JAVA layer....
    Now I want to know can I do anything more efficient to carry out the above operation....

  • JDBC SQL Server Channel Calling Stored Procedure Won't Return Result Set

    Good afternoon, Experts
    We're calling a stored procedure in a sender communcation channel.  I can perform any SQL SELECT statement here, but for some reason when I execute the SP (EXECUTE StoredProcedureName) The Adapter Engine returns the following:
    Database-level error reported by JDBC driver while executing statement 'DECLARE @UpdateRecords bit SET @UpdateRecords = 0 EXECUTE ExportToSAP @UpdateRecords'. The JDBC driver returned the following error message: 'com.microsoft.sqlserver.jdbc.SQLServerException: The statement did not return a result set.'. For details, contact your database server vendor.
    Even stranger yet is is that this works just fine on our PI-DEV system.  I created an identical communication channel connecting to the same database with the same UID and PWD and it won't work in PI-QAS.
    Any help/ideas you could share would be greatly appreciated!!!
    Thanks,
    Chad

    Hi Chad.
    Normally, itu2019s a problem with your procedure. The Store Procedure is wrong and something is different between your DEV environment and QAS environment.
    Try to ask to DB team check it.
    Regards,
    Bruno

  • Stored Procedure in Universe - Multi-result set

    I have been trying to get more information on stored procedures as a source for universes. Business Objects designer 3.1 documentation says the following
    Stored procedures with multi-result set
    Example: A stored procedure that returns more than one result set. At design
    time, several tables are created in the universe structure based on the same
    stored procedure.
    Does this mean?
    1. These result sets are shown as multiple tables in designer?
    2. if so, can these result sets be used as regular tables in designer to build joins and contexts.
    I searched the forum for relevant threads before posting but could not find any. I tried posting this thread earlier - internet connection timed out. Please forgive me if this is a duplicate post.
    Thanks

    DROP TABLE #DescendantsMS SQL Server - right?
    Then don't drop the table.
    From the MS docs for "create table"
    Local temporary tables are visible only in the current session;
    A local temporary table created in a stored procedure is dropped automatically when the stored procedure completes. The table can be referenced by any nested stored procedures executed by the stored procedure that created the table. The table cannot be referenced by the process which called the stored procedure that created the table.

  • Stored procedure call returns null result set when using temp table in sp!

    Here's a really odd problem...
    SQL Server stored procedure called sp_Test takes 1 input INT. Here is the code I call it with
    cStmt = connection.prepareCall("{call sp_Test(?)}");
    cStmt.setInt(1, 44);
    cStmt.execute();
    rs = cStmt.getResultSet();When the body of the stored proc is
    CREATE PROCEDURE sp_Test(@i_NodeID INT)
    AS
    BEGIN
      SELECT node_id FROM tbl_NavTree
    END
    GOthe query works and I get all node_id back in rs
    BUT when the body of the stored proc is
    CREATE PROCEDURE sp_Test(@i_NodeID INT)
    AS
    BEGIN
      CREATE TABLE #Descendants(
        descendant_id INT
      SELECT node_id FROM tbl_NavTree
      DROP TABLE #Descendants
    END
    GOThe rs comes back as NULL. Really really weird if you ask me. I also tried removing the DROP TABLE line just in case the SELECT had to be the last statement but still NULL.
    Final note is that BOTH the above stored proc bodies work when executed within SQL Server query analyser.
    Must be JDBC .. what can it be!??

    DROP TABLE #DescendantsMS SQL Server - right?
    Then don't drop the table.
    From the MS docs for "create table"
    Local temporary tables are visible only in the current session;
    A local temporary table created in a stored procedure is dropped automatically when the stored procedure completes. The table can be referenced by any nested stored procedures executed by the stored procedure that created the table. The table cannot be referenced by the process which called the stored procedure that created the table.

  • SELECT with and without for all entries giving different results

    Hi All,
    For some reason unknown to me ,
    There is a difference in result between the below mentioned query however the logic is same.
    1 .  lw_ebeln-EBELN = '0000366416'.
         APPEND lw_ebeln to lt_ebeln. 
          SELECT    ebeln
         FROM     ekbe
         INTO TABLE lt_ekbe
         FOR ALL ENTRIES IN lt_ebeln
         WHERE ebeln = lt_ebeln-ebeln
    2. SELECT ebeln from ekbe into table lt_ekbe where
    ebeln = '0000366416'..
    I have tried a lot to find the reason but unable to.
    Thanks,
    Faiz

    Hi faizur,
    Hope it help ful.
    If you add the EBELP in Internal table,  you will be getting same number of entries in both query.
    For all entries Removes the Duplicate key.
    Regards,
    Venkat.

  • Keyword Filters bring 3 different results

    Hello,
    I have a Problem with filtering Keywords.
    I set up a smart collection with one single criteria - search for a single Keyword: Number of pictures= 453
    When I use the Metadata Filter for the same Keyword: Number of pictures= 405
    When using the right hand Keyword List in the library: Number of pictures= 421
    One thing is, that the smart collection filter shows also pictures with the keyword in the file name -> Bug?
    thanks for listening.

    Depends upon who you ask.
    There are are those of us who believe items should propagate through a stack and others who do not. There are also some who think that component images (HDRs, Panos, etc) where multiple images are used to make a final, behave one way and other stacks behave another.

  • Procedure with select from mysql db link problem

    Hi,
    first of all Oracle is new to me so if there are better ways to do this every suggestion would help.
    My problem is simple i cant use select from dblink inside a procedure.
    In Oralce SQL Developer 1.5.5:
    Im using oracle 11g and mysql 5.5.13 with mysql odbc 5.1
    in both db the user is root
    CREATE PUBLIC DATABASE LINK "MYSQL"
    CONNECT TO "root" IDENTIFIED BY "****"
    AUTHENTICATED BY "root" IDENTIFIED BY "****"
    USING 'mysql';
    select * from t1@mysql;
    run; -> result OK
    select "MAXID" from t1@mysql where "TNAME"='first';
    run; -> result OK
    create or replace
    PROCEDURE T1_IDS_PROC AS
    maxi number;
    BEGIN
    select "MAXID" into maxi from t1@mysql where "TNAME"='first';
    END T1_IDS_PROC;
    compile -> not working:
    Fehler(7,3): PL/SQL: SQL Statement ignored
    Fehler(7,47): PL/SQL: ORA-00904: "TNAME": unknown identifier
    How to solve this?

    Thanks for replay,
    yes the owner of the procedure can acces the remote table.
    I can use
    select count(*) into i from t1@mysql
    inside the procedure, but if i use specific columns inside the select i cant compile.
    Why i need double quote?
    I dont know if i need them but i read some tutorial for dblink to mysql and there was explanied
    Oracle use upercase names and Mysql is case sensitive for odbc 5.1 so i have to double qoute mysql names.
    But with or without double qoute it dont work inside procedures ;(

  • Disconnected rowset CachedRowSet from a select inside stored procedure?

    Hello everyone
    I am using CachedRowSet returning it from a parameterised select statement and it works fine.
    If I put the same select statement into a simple read-only stored procedure then I get this exception: "A result set was generated for update".
    I am not trying to update the rowset in my code.
    I tried to make the CachedRowSet to be read-only but it does not help, same error.
    Question 1 : can a stored procedure returning a single result-set be called to populate a read-only CachedRowSet? (in a similar fashion to a CallableStatement prepareCall method with input/output parameters).
    Question 2: in general is using CachedRowSet, WebRowSet, FilteredRowSet (disconnected) and JDBCRowSet (connected) something to be encouraged for future develpment or are they deprecated, or replaced by something else/better??
    thank you very much in advance

    Thank you for the initial bite.
    This is for Microsoft SQL Server 2008 using Microsoft JDBC driver, type 4.0.
    The T-SQL stored procedure has a single select statement in it - see inside code.
    Below is the Java 6 source code (including the Java import statements, many unused at the moment), apologies for poor indendation, its a cut and paste problem.
    // start of Java code
    import java.io.*;
    import java.sql.*;
    import java.text.ParseException;
    import java.text.SimpleDateFormat;
    import com.microsoft.sqlserver.jdbc.*;
    import com.microsoft.sqlserver.jdbc.SQLServerDriver.*;
    import com.microsoft.sqlserver.jdbc.SQLServerDriver;
    import java.math.BigDecimal;
    import com.sun.rowset.CachedRowSetImpl;
    import java.net.MalformedURLException;
    import java.net.URL;
    import java.sql.Connection;
    import java.sql.Date;
    import java.sql.ResultSet;
    import java.sql.SQLException;
    import java.sql.Statement;
    import java.sql.Timestamp;
    import java.util.Calendar;
    import java.util.GregorianCalendar;
    import java.util.HashMap;
    import javax.sql.rowset.CachedRowSet;
    import javax.sql.rowset.spi.SyncProviderException;
    import javax.sql.rowset.spi.SyncResolver;
    public class JdbcRowSetTesting
    public static void main(String[] args)
      String connectionUrl =
      "jdbc:sqlserver://ABCDE-SERVER:1433;" +
       "databaseName=SecurityTransaction;integratedSecurity=false;user=somedbuser;password=somesortofpassword";
      Connection conn = null;
      Statement sqlstmt = null;
      ResultSet rs = null;
      CachedRowSet crs = null;
       try
      conn = DriverManager.getConnection(connectionUrl);
      System.out.println("inside try block, connected");
      conn.setAutoCommit(false);
      crs = new CachedRowSetImpl();
      crs.setUrl(connectionUrl);
      crs.setReadOnly(true);
      crs.setType(ResultSet.TYPE_FORWARD_ONLY);
      crs.setConcurrency(ResultSet.CONCUR_READ_ONLY);
      System.out.println("inside try block, connected to CachedRowSet URL"); 
    // this works fine:
      crs.setCommand("select ADDRESSID, COUNTRY, POSTCODE, STATE, ADDRESS1, ADDRESS2, ADDRESS3, ADDRESS4, CREATEDBY, CREATEDDATE, UPDATEDBY, UPDATEDDATE from dbo.address where ADDRESSID > ?;");
    -- this does not work - the SP has  the same SELECT as above inside it:
      crs.setCommand("{ call dbo.p_testCachedJDBCRowSet (?) }");
      crs.setInt(1, 10);
      crs.execute();
       while (crs.next())
      System.out.println("" + crs.getInt("ADDRESSID") + " " +
      crs.getString("ADDRESS1"));
       catch (Exception e)
      System.out.println("inside catch block, calling Exception printStackTrace(); method now:");
      e.printStackTrace();
       finally
      System.out.println("inside finally block");
       if (rs != null) try { rs.close(); } catch(Exception e) { e.printStackTrace(); }
       if (sqlstmt != null) try { sqlstmt.close(); } catch(Exception e) { e.printStackTrace(); }
       if (conn != null) try { conn.close(); } catch(Exception e) { e.printStackTrace(); }
    return;
    // end of Java source code

  • How do you report from a multiple-result-set stored procedure?

    Team,
    I am writing a report against a canned stored procedure which returns eight result sets.  That is, inside the stored procedure, there are eight SELECT statements which pump to the output. In ADO, you would read the first one, then use SqlDataReader.NextResult to advance the reader to the next one until you have done all eight.
    Q1: Have you ever written a Crystal Report against such a sproc? How?
    Q2: I see that I could pull this data using ADO.NET if I knew this: Have you ever read such a sproc into a dataset? When I drag-and-drop the sproc into the dataset designer, it only makes a table schema for the first result set. I desire to have a table schema for all eight.
    Thanks,
    ~ Shaun

    Q1: Have you ever written a Crystal Report against such a sproc? How?
    - best answered in the Crystal Reports Design forum, so please post there:
    SAP Crystal Reports
    Q2: I see that I could pull this data using ADO.NET if I knew this: Have you ever read such a sproc into a dataset? When I drag-and-drop the sproc into the dataset designer, it only makes a table schema for the first result set. I desire to have a table schema for all eight.
    - not a Crystal reports question. Perhaps better posted to some MS / .NET developer forum(?)
    Ludek

  • Returning result set from procedure out parameter, display with anon block

    I'm trying to do something pretty simple (I think it should be simple at least). I want to use a pl/sql procedure to return a result set in an OUT parameter. If I run this code by itself (in the given anonymous block at the end, without trying to display any results), toad says that the PL/SQL procedure successfully completed.
    How can I display the results from this procedure? I am assuming that the result set should be stored in the O_RETURN_REDEEM_DTL, but how can I get anything out of it?
    I have this package with the following procedure:
    /* FUNCTION - REDEEM_DTL_READ                          */
         PROCEDURE REDEEM_DTL_READ(
              ZL_DIVN_NBR_IN     IN     REDEEM_DTL.ZL_DIVN_NBR%TYPE,
              GREG_DATE_IN     IN     REDEEM_DTL.GREG_DATE%TYPE,
              ZL_STORE_NBR_IN     IN     REDEEM_DTL.ZL_STORE_NBR%TYPE,
              REGISTER_NBR_IN     IN     REDEEM_DTL.REGISTER_NBR%TYPE,
              TRANS_NBR_IN     IN     REDEEM_DTL.TRANS_NBR%TYPE,
              O_RETURN_REDEEM_DTL OUT REDEEM_DTL_TYPE,
              o_rtrn_cd       OUT NUMBER,
              o_err_cd        OUT NUMBER,
              o_err_msg       OUT VARCHAR2
         IS
         BEGIN
              o_rtrn_cd := 0;
              o_err_msg := ' ';
              o_err_cd := 0;
              --OPEN REDEEM_DTL_READ_CUR(ZL_DIVN_NBR_IN, GREG_DATE_IN, ZL_STORE_NBR_IN, REGISTER_NBR_IN, TRANS_NBR_IN);
              OPEN O_RETURN_REDEEM_DTL FOR SELECT * FROM REDEEM_DTL;
    --           LOOP
    --                FETCH REDEEM_DTL_READ_CUR INTO O_RETURN_REDEEM_DTL;
    --                EXIT WHEN REDEEM_DTL_READ_CUR%NOTFOUND;
    --           END LOOP;
    --           CLOSE REDEEM_DTL_READ_CUR;
         EXCEPTION
          WHEN OTHERS
          THEN
               o_rtrn_cd := 7;
                 o_err_msg := SUBSTR (SQLERRM, 1, 100);
                 o_err_cd  := SQLCODE;
         END REDEEM_DTL_READ;and call it in an anonymous block with:
    DECLARE
      ZL_DIVN_NBR_IN NUMBER;
      GREG_DATE_IN DATE;
      ZL_STORE_NBR_IN NUMBER;
      REGISTER_NBR_IN NUMBER;
      TRANS_NBR_IN NUMBER;
      O_RETURN_REDEEM_DTL PSAPP.CY_SALESPOSTING.REDEEM_DTL_TYPE;
      O_RETURN_REDEEM_DTL_OUT PSAPP.CY_SALESPOSTING.REDEEM_DTL_READ_CUR%rowtype;
      O_RTRN_CD NUMBER;
      O_ERR_CD NUMBER;
      O_ERR_MSG VARCHAR2(200);
    BEGIN
      ZL_DIVN_NBR_IN := 71;
      GREG_DATE_IN := TO_DATE('07/21/2008', 'MM/DD/YYYY');
      ZL_STORE_NBR_IN := 39;
      REGISTER_NBR_IN := 1;
      TRANS_NBR_IN := 129;
      -- O_RETURN_REDEEM_DTL := NULL;  Modify the code to initialize this parameter
      O_RTRN_CD := NULL;
      O_ERR_CD := NULL;
      O_ERR_MSG := NULL;
      PSAPP.CY_SALESPOSTING.REDEEM_DTL_READ ( ZL_DIVN_NBR_IN, GREG_DATE_IN, ZL_STORE_NBR_IN,
    REGISTER_NBR_IN, TRANS_NBR_IN, O_RETURN_REDEEM_DTL, O_RTRN_CD, O_ERR_CD, O_ERR_MSG );
      FOR item IN O_RETURN_REDEEM_DTL
      LOOP
        DBMS_OUTPUT.PUT_LINE('ZL_DIVN_NBR = ' || item.ZL_DIVN_NBR);
      END LOOP;
    END; And end up with an error:
    ORA-06550: line 25, column 15:
    PLS-00221: 'O_RETURN_REDEEM_DTL' is not a procedure or is undefined
    ORA-06550: line 25, column 3:
    PL/SQL: Statement ignoredMessage was edited by:
    user607908

    Aha, I knew I forgot something!
    I actually had it defined as a REF CURSOR in PSAPP.CY_SALESPOSTING package spec:
    TYPE REDEEM_DTL_TYPE IS REF CURSOR;since I wasn't sure what to make it.
    Cursor used in procedure:
    CURSOR REDEEM_DTL_READ_CUR (
      zl_divn_nbr_in IN NUMBER,
      greg_date_in IN DATE,
      zl_store_nbr_in IN NUMBER,
      register_nbr_in IN NUMBER,
      trans_nbr_in IN NUMBER)
    IS
    SELECT ZL_DIVN_NBR, GREG_DATE, ZL_STORE_NBR, REGISTER_NBR, TRANS_NBR, PAYMENT_TYP_NBR
    FROM REDEEM_DTL
    WHERE ZL_DIVN_NBR = zl_divn_nbr_in AND GREG_DATE = greg_date_in AND
       ZL_STORE_NBR = zl_store_nbr_in AND REGISTER_NBR = register_nbr_in AND
       TRANS_NBR = trans_nbr_in;Updated code:
    /* PROCEDURE - REDEEM_DTL_READ                          */
         PROCEDURE REDEEM_DTL_READ(
              ZL_DIVN_NBR_IN     IN     REDEEM_DTL.ZL_DIVN_NBR%TYPE,
              GREG_DATE_IN     IN     REDEEM_DTL.GREG_DATE%TYPE,
              ZL_STORE_NBR_IN     IN     REDEEM_DTL.ZL_STORE_NBR%TYPE,
              REGISTER_NBR_IN     IN     REDEEM_DTL.REGISTER_NBR%TYPE,
              TRANS_NBR_IN     IN     REDEEM_DTL.TRANS_NBR%TYPE,
              O_RETURN_REDEEM_DTL OUT REDEEM_DTL_TYPE,
              o_rtrn_cd       OUT NUMBER,
              o_err_cd        OUT NUMBER,
              o_err_msg       OUT VARCHAR2
         IS
         BEGIN
              o_rtrn_cd := 0;
              o_err_msg := ' ';
              o_err_cd := 0;
              OPEN REDEEM_DTL_READ_CUR(ZL_DIVN_NBR_IN, GREG_DATE_IN, ZL_STORE_NBR_IN,
                   REGISTER_NBR_IN, TRANS_NBR_IN);
              --OPEN O_RETURN_REDEEM_DTL FOR SELECT * FROM REDEEM_DTL;
              LOOP
                  FETCH REDEEM_DTL_READ_CUR INTO O_RETURN_REDEEM_DTL;
                   EXIT WHEN REDEEM_DTL_READ_CUR%NOTFOUND;
                   DBMS_OUTPUT.PUT_LINE('ZL_DIVN_NBR = ' || O_RETURN_REDEEM_DTL.ZL_DIVN_NBR);
                END LOOP;
               CLOSE REDEEM_DTL_READ_CUR;
    --           LOOP
    --                FETCH REDEEM_DTL_READ_CUR INTO O_RETURN_REDEEM_DTL;
    --                EXIT WHEN REDEEM_DTL_READ_CUR%NOTFOUND;
    --           END LOOP;
    --           CLOSE REDEEM_DTL_READ_CUR;
         EXCEPTION
          WHEN OTHERS
          THEN
               o_rtrn_cd := 7;
                 o_err_msg := SUBSTR (SQLERRM, 1, 100);
                 o_err_cd  := SQLCODE;
         END REDEEM_DTL_READ;the updated anon block:
    DECLARE
      ZL_DIVN_NBR_IN NUMBER;
      GREG_DATE_IN DATE;
      ZL_STORE_NBR_IN NUMBER;
      REGISTER_NBR_IN NUMBER;
      TRANS_NBR_IN NUMBER;
      O_RETURN_REDEEM_DTL PSAPP.CY_SALESPOSTING.REDEEM_DTL_TYPE;
      O_RTRN_CD NUMBER;
      O_ERR_CD NUMBER;
      O_ERR_MSG VARCHAR2(200);
    BEGIN
      ZL_DIVN_NBR_IN := 71;
      GREG_DATE_IN := TO_DATE('07/21/2008', 'MM/DD/YYYY');
      ZL_STORE_NBR_IN := 39;
      REGISTER_NBR_IN := 1;
      TRANS_NBR_IN := 129;
      -- O_RETURN_REDEEM_DTL := NULL;  Modify the code to initialize this parameter
      O_RTRN_CD := NULL;
      O_ERR_CD := NULL;
      O_ERR_MSG := NULL;
      PSAPP.CY_SALESPOSTING.REDEEM_DTL_READ ( ZL_DIVN_NBR_IN, GREG_DATE_IN, ZL_STORE_NBR_IN,
         REGISTER_NBR_IN, TRANS_NBR_IN, O_RETURN_REDEEM_DTL, O_RTRN_CD, O_ERR_CD, O_ERR_MSG );
      FOR item IN 1..O_RETURN_REDEEM_DTL.COUNT
      LOOP
        DBMS_OUTPUT.PUT_LINE('ZL_DIVN_NBR = ' || O_RETURN_REDEEM_DTL(item).ZL_DIVN_NBR);
      END LOOP;
    END;and the new error:
    ORA-06550: line 25, column 38:
    PLS-00487: Invalid reference to variable 'O_RETURN_REDEEM_DTL'
    ORA-06550: line 25, column 3:
    PL/SQL: Statement ignoredAlso, it would be nice if the forums would put a box around code so that it would be easy to
    distinguish between what is supposed to be code and what should be regular text...
    Message was edited by:
    user607908

  • Select from many tables of the same type

    Hi everybody!
    My problem is the next:
    I have many tables with big account of data (millions regs), so I did something like that:
    The regs dated 1999 are in the table XXX_1999, those dated 2000 - in XXX_2000, and so on.
    Now, if I want to make query from date1 to date2 (could be some years of difference), I don't know the number of tables I have to query in execution time.
    I want to make a procedure that returns 1 recordset (or cursor) with all the data in it without using temporary tables.
    Is it possible and how?
    Thanks

    SQL> r
      1  declare
      2    c_CRLF constant varchar2(2) := chr(13)||chr(10);
      3
      4    v_date1 date := to_date('15.03.2001', 'DD.MM.YYYY');
      5    v_date2 date := to_date('17.08.2003', 'DD.MM.YYYY');
      6
      7    cursor c_years is
      8      select to_number(to_char(v_date1, 'YYYY')) + rownum-1 year
      9      from user_tables
    10      where rownum <= to_number(to_char(v_date2, 'YYYY')) -to_number(to_char(v_date1, 'YYYY')) +1;
    11
    12    v_stmnt varchar2(2000);
    13  begin
    14    for rec in c_years loop
    15      if c_years%ROWCOUNT > 1 then
    16        v_stmnt := v_stmnt || c_CRLF ||'UNION ALL' || c_CRLF;
    17      end if;
    18      v_stmnt := v_stmnt || 'select * from XXX_'||rec.year;
    19    end loop;
    20    dbms_output.put_line(v_stmnt);
    21* end;
    select * from XXX_2001
    UNION ALL
    select * from XXX_2002
    UNION ALL
    select * from XXX_2003
    PL/SQL procedure successfully completed.
    SQL>You will need to add some bounds checking to avoid "table or view does not exist'
    if date1 < 2001 -> date1=2001
    if date2 > current year -> date2=current year
    Message was edited by:
    Jens Petersen

  • Multiple result sets from stored procedure into CachedRowSet

    How can you obtain multiple sets of data from a stored procedure that returns multiple result sets, when you'd like to use CachedRowSet rather than ResultSet?
    My database's stored procedures return multiple result sets, but I'm not sure how to manipulate that using CallableStatements and CachedRowSets... I read the RowSet tutorial from java.sun.com but that didn't cover the case of multiple result sets and CallablStatements.
    How might I do this? Thanks a lot.

    SELECT columns..
    FROM table
    FOR XML PATH('NodeName'),('Rootname')
    Thank you for replying.
    I dont have to generate XML from a query. I have to generate from a SP and that too without modifying it.
    Thanks,
    Tauhid
    thats ok you can do like this
    1. Create a table with structure same as SP resultset
    2. Populate table with SP result as per below
    INSERT table
    EXEC SPName param1value,...
    3. Add a query like below
    SELECT columns..
    FROM tablename
    FOR XML PATH('NodeName'),('RootName')
    see
    http://visakhm.blogspot.com/2014/05/t-sql-tips-fun-with-for-xml-path.html
    4. Use sp_send_dbmail to sent it through mail
    http://msdn.microsoft.com/en-IN/library/ms190307.aspx
    Please Mark This As Answer if it helps to solve the issue Visakh ---------------------------- http://visakhm.blogspot.com/ https://www.facebook.com/VmBlogs

Maybe you are looking for

  • Print quality in Aperture 3 and layout export

    I searched, but did not find recent information on print quality of books ordered through Aperture 3. So, my questions are: 1. How is the quality of the books ordered through Aperture 3? Few years ago I heard that the pictures are a bit darken. Is th

  • I need the patch #2376472 from Metalink - Can anyone tell me  how 2 get it

    Please note I have a CSI # which I was told has expired. I need to obtain this patch and am disparately trying to obtain it with little success thus far You would think Oracle would let third party support people download and distribute as is such a

  • Need help connecting safari, entourage, ichat etc to wireless internet

    My macbook is my first apple, I've never used Mac OS X before, and I'm finding all the new terminology intimidating, so I would greatly appreciate any help you can give me, but please talk down to me like I'm 10 years old, or I won't understand. Here

  • Hiding R/3 Header in Portal SAP Transactional iView

    Hi , I created an SAP Transactional iView with GUI Type as "SAP GUI for HTML". But when I am accessing the iView, then it is displaying properly. What I want is hiding the R/3 header in that Transaction iView. I have read several Threads given below.

  • How to add Javascript action to buttons and text (hyperlink style)

    Hello. Please need help urgently! I need to link let's say to a text in Muse that reads "ADD TO CART" following javascript: <a href="javascript:;" onclick="wazala_widget.addtocart('177217');" If i do it like: <a href="javascript:;" onclick="wazala_wi