Sql query to grant TRUNCATE permission to a table

Need help to write sql query to grant TRUNCATE permission to a table

sujnan wrote:
Need help to write sql query to grant TRUNCATE permission to a tableThis would require DROP ANY TABLE privilege.
However, this is a rather powerful privilege and should not be granted to non admin users.
Alternatively you can create a stored procedure in table owner's schema which would truncate specified table.
Grant execute rights on this SP only to required users.
See an example below:
http://asktom.oracle.com/pls/asktom/f?p=100:11:0::::P11_QUESTION_ID:1458414958491
You could(rather should) put in more validations in this SP to prevent users from truncating tables that they are not supposed to.

Similar Messages

  • Can we implement the custom sql query in CR for joining the two tables

    Hi All,
    Is there anyway to implement the custom sql query in CR for joining the two tables?
    My requirement here is I need to write sql logics for joining the two tables...
    Thanks,
    Gana

    In the Database Expert, expand the Create New Connection folder and browse the subfolders to locate your data source.
    Log on to your data source if necessary.
    Under your data source, double-click the Add Command node.
    In the Add Command to Report dialog box, enter an appropriate query/command for the data source you have opened.
    For example:
    SELECT
        Customer.`Customer ID`,
        Customer.`Customer Name`,
        Customer.`Last Year's Sales`,
        Customer.`Region`,
        Customer.`Country`,
        Orders.`Order Amount`,
        Orders.`Customer ID`,
        Orders.`Order Date`
    FROM
        Customer Customer INNER JOIN Orders Orders ON
            Customer.`Customer ID` = Orders.`Customer ID`
    WHERE
        (Customer.`Country` = 'USA' OR
        Customer.`Country` = 'Canada') AND
        Customer.`Last Year's Sales` < 10000.
    ORDER BY
        Customer.`Country` ASC,
        Customer.`Region` ASC
    Note: The use of double or single quotes (and other SQL syntax) is determined by the database driver used by your report. You must, however, manually add the quotes and other elements of the syntax as you create the command.
    Optionally, you can create a parameter for your command by clicking Create and entering information in the Command Parameter dialog box.
    For more information about creating parameters, see To create a parameter for a command object.
    Click OK.
    You are returned to the Report Designer. In the Field Explorer, under Database Fields, a Command table appears listing the database fields you specified.
    Note:
    To construct the virtual table from your Command, the command must be executed once. If the command has parameters, you will be prompted to enter values for each one.
    By default, your command is called Command. You can change its alias by selecting it and pressing F2.

  • PLEASE SEND ME SQL query to list ALL CONSTRAINTS ON EMPLOYEES TABLE FROM OU

    PLEASE SEND ME SQL query to list ALL CONSTRAINTS ON EMPLOYEES TABLE FROM OUTSIDE PP SCHEMA INCLUDING SCHEMA NAME AND CONSTraint NAME
    Username : PP
    Table : Employees

    I think you are looking for below query :
    SQL> SHOW USER;
    USER is "SCOTT"
    SQL> select owner,constraint_name,constraint_type,table_name,r_owner,r_constraint_name
      2    from all_constraints
      3    where constraint_type='R'
      4   and r_constraint_name in (select constraint_name from all_constraints
      5    where constraint_type in ('P','U') and table_name='EMP');
    OWNER                          CONSTRAINT_NAME                C TABLE_NAME                     R_OWNER                        R_CONSTRAINT_NAME
    TEST1                          ERL_EMP_FK_1                   R EMPLOYEE                       SCOTT                          PK_EMP
    1 row selected.Means, TEST1 user is having a constraint ERL_EMP_FK_1 on his table EMPLOYEE. Which is using PK_EMP (primary key of SCOTT user's 'EMP' [in the query])
    Regards
    Girish Sharma

  • Help Required -- Can we use SQL Query to READ data from SAP MDM Tables

    Hi All,
    Please help.........
    Can we use SQL Query to READ(No Creation/Updation/Deletion  just Read) Data from SAP MDM tables directly, without using MDM Syndicator.
    Or direct SQL access to SAP MDM tables is not possible. Only through MDM Syndicator can we export data.
    Thanks in Advance
    Regards

    All the tables you create in Repository comes under A2i_CM_Tables in Database named as your repository name. So the tables names are fields of table A2i_CM_Tables. Now i tried it but cant make it.
    Now, I dont think its possible to extract all fields in tables and there values using select query. May be pure sql guy can do that or not.
    But there is no relation of data extraction and syndicator. Data is viewed in Data Manager. and you can also store data in a file from DM also.
    BR,
    Alok

  • Excel ADODB Sql Query Execution taking hours when manipulate excel tables

    Hello All 
    I have 28000 records with 8 column in an sheet. When I convert the sheet into ADODB database and copy to new
    excel using below code it is executing in less than a min
    Set Tables_conn_obj = New ADODB.Connection
    Tables_conn_str = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" & Table_Filename & ";Extended Properties=""Excel 12.0;ReadOnly=False;HDR = Yes;IMEX=1"""
    Tables_conn_obj.Open Tables_conn_str
    First_Temp_sqlqry = "Select * INTO [Excel 12.0;DATABASE=C:\Prod Validation\Database\Second Acat Table.xlsb].[Sheet1] Table [first - Table$];" Tables_conn_obj.Execute First_Temp_sqlqry
    But when I change the query to manipulate one column in current table based on another table in the same excel
    and try to copy the results in another excel, it is taking more than one hour.. why it is taking this much time when both the query results returns the same number of rows and column. I almost spend one week and still not able to resolve this issue.
    Even I tried copyfromrecordset, getrows(), getstring(), Looping each recordset fields options all of them taking
    same amount of time. Why there is huge difference in execution time.
    Important note: Without into statement even below query is executing in few seconds.
    select ( ''''''manipulating first column based on other table data''''''''''''''
    iif(
    [Second - Table$].[Policy Agent] = (select max([ACAT$].[new_Agent_number]) from [ACAT$] where [ACAT$].[new_Agent_number] = [Second - Table$].[Policy Agent] and [ACAT$].[ACAT_EffectiveDate] = ( select MAX([ACAT$].[ACAT_EffectiveDate] ) from [ACAT$] where [ACAT$].[new_Agent_number] = [Second - Table$].[Policy Agent]and [ACAT$].[ACAT_EffectiveDate] > '2014-10-01') ) , (select max([ACAT$].[Old_Agent_number]) from [ACAT$] where [ACAT$].[new_Agent_number] = [Second - Table$].[Policy Agent] and [ACAT$].[ACAT_EffectiveDate] = ( select MAX([ACAT$].[ACAT_EffectiveDate] ) from [ACAT$] where [ACAT$].[new_Agent_number] = [Second - Table$].[Policy Agent]and [ACAT$].[ACAT_EffectiveDate] > '2014-10-01')) ,
    iif( [Second - Table$].[Policy Agent] = (select max([ACAT$].[Old_Agent_number]) from [ACAT$] where [ACAT$].[Old_Agent_number] = [Second - Table$].[Policy Agent] and [ACAT$].[ACAT_EffectiveDate] = ( select MAX([ACAT$].[ACAT_EffectiveDate] ) from [ACAT$]where [ACA T$].[Old_Agent_number] = [Second - Table$].[Policy Agent]and [ACAT$].[ACAT_EffectiveDate] <= '2014-10-01') ), (select max([ACAT$].[new_Agent_number]) from [ACAT$] where [ACAT$].[Old_Agent_number] = [Second - Table$].[Policy Agent] and [ACAT$].[ACAT_EffectiveDate] = ( select MAX([ACAT$].[ACAT_EffectiveDate] ) from [ACAT$] where [ACAT$].[Old_Agent_number] = [Second - Table$].[Policy Agent]and [ACAT$].[ACAT_EffectiveDate] <= '2014-10-01')) ,
    [Second - Table$].[Policy Agent] ))) as [Policy Agent],
    ''''''summing up all other columns''''''''''''''
    (iif(isnull(sum([Second - Table$].[Auto BW-Line Of Business Detail])),0,sum([Second - Table$].[Auto BW-Line Of Business Detail]))) as [Auto BW-Line Of Business Detail],(iif(isnull(sum([Second - Table$].[Auto Farmers])),0,sum([Second - Table$].[Auto Farmers]))) as [Auto Farmers],(iif(isnull(sum([Second - Table$].[MCA])),0,sum([Second - Table$].[MCA]))) as [MCA],(iif(isnull(sum([Second - Table$].[CEA])),0,sum([Second - Table$].[CEA]))) as [CEA],(iif(isnull(sum([Second - Table$].[Commercial P&C])),0,sum([Second - Table$].[Commercial P&C]))) as [Commercial P&C],(iif(isnull(sum([Second - Table$].[Comm WC])),0,sum([Second - Table$].[Comm WC]))) as [Comm WC],(iif(isnull(sum([Second - Table$].[Fire Farmers])),0,sum([Second - Table$].[Fire Farmers]))) as [Fire Farmers],(iif(isnull(sum([Second - Table$].[Flood])),0,sum([Second - Table$].[Flood]))) as [Flood],(iif(isnull(sum([Second - Table$].[Kraft Lake])),0,sum([Second - Table$].[Kraft Lake]))) as [Kraft Lake],(iif(isnull(sum([Second - Table$].[Life])),0,sum([Second - Table$].[Life]))) as [Life],(iif(isnull(sum([Second - Table$].[Foremost])),0,sum([Second - Table$].[Foremost]))) as [Foremost],(iif(isnull(sum([Second - Table$].[Umbrella])),0,sum([Second - Table$].[Umbrella]))) as [Umbrella],(iif(isnull(sum([Second - Table$].[MCNA])),0,sum([Second - Table$].[MCNA]))) as [MCNA]
    INTO [Excel 12.0;DATABASE=C:\Prod Validation\Database\Second Acat Table.xlsb].[Sheet1]
    from [Second - Table$] group by [Second - Table$].[Policy Agent] ;

    Hi Fei,
      Thank you so much for the reply post. I just executed the same above SQL without INTO Statement and assigned the SQL result to ADODB recordset as below. If the time difference is due to the SQL query then below statements also should execute for hours
    right, but it gets executed in seconds. But to copy the recordset to excel again it is taking hours. I tried copyfromrecordset,
    getrows(), getstring(), Looping each recordset fields options and all of them taking same amount of time. Please let me know there is delay in time for this much small data
    Even I tried to typecast all columns to double, string in SQL and still the execution time  is not reduced. 
    First_Temp_Recordset.Open sql_qry, Tables_conn_obj, adOpenStatic, adLockOptimistic ''' OR SET First_Temp_Recordset = Tables_conn_obj.Execute sql_qry

  • Excel ADODB Sql Query Execution taking hours when manipulate excel tables why?

    I have 28000 records with 8 column in an sheet. When I convert the sheet into ADODB database and copy to new excel using below code it is executing in less than a min
    Set Tables_conn_obj = New ADODB.Connection Tables_conn_str = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" & Table_Filename & ";Extended Properties=""Excel 12.0;ReadOnly=False;HDR = Yes;IMEX=1""" Tables_conn_obj.Open
    Tables_conn_str First_Temp_sqlqry = "Select * INTO [Excel 12.0;DATABASE=C:\Prod Validation\Database\Second Acat Table.xlsb].[Sheet1] Table [first - Table$];" Tables_conn_obj.Execute First_Temp_sqlqry
    But when I change the query to manipulate one column in current table based on another table in the same excel and try to copy the results in another excel, it is taking more than one hour.. why it is taking this much time when both the query results returns
    the same number of rows and column. I almost spend one week and still not able to resolve this issue.
    Even I tried copyfromrecordset, getrows(), getstring(), Looping each recordset fields options all of them taking same amount of time. Appreciate any inputs...
    select ( ''''''manipulating first column based on other table data''''''''''''''
    iif( [Second - Table$].[Policy Agent] = (select max([ACAT$].[new_Agent_number]) from [ACAT$] where [ACAT$].[new_Agent_number] = [Second - Table$].[Policy Agent] and [ACAT$].[ACAT_EffectiveDate] = ( select MAX([ACAT$].[ACAT_EffectiveDate] ) from [ACAT$] where
    [ACAT$].[new_Agent_number] = [Second - Table$].[Policy Agent]and [ACAT$].[ACAT_EffectiveDate] > '2014-10-01') ) , (select max([ACAT$].[Old_Agent_number]) from [ACAT$] where [ACAT$].[new_Agent_number] = [Second - Table$].[Policy Agent] and [ACAT$].[ACAT_EffectiveDate]
    = ( select MAX([ACAT$].[ACAT_EffectiveDate] ) from [ACAT$] where [ACAT$].[new_Agent_number] = [Second - Table$].[Policy Agent]and [ACAT$].[ACAT_EffectiveDate] > '2014-10-01')) ,
    iif( [Second - Table$].[Policy Agent] = (select max([ACAT$].[Old_Agent_number]) from [ACAT$] where [ACAT$].[Old_Agent_number] = [Second - Table$].[Policy Agent] and [ACAT$].[ACAT_EffectiveDate] = ( select MAX([ACAT$].[ACAT_EffectiveDate] ) from [ACAT$]where
    [ACA T$].[Old_Agent_number] = [Second - Table$].[Policy Agent]and [ACAT$].[ACAT_EffectiveDate] <= '2014-10-01') ), (select max([ACAT$].[new_Agent_number]) from [ACAT$] where [ACAT$].[Old_Agent_number] = [Second - Table$].[Policy Agent] and [ACAT$].[ACAT_EffectiveDate]
    = ( select MAX([ACAT$].[ACAT_EffectiveDate] ) from [ACAT$] where [ACAT$].[Old_Agent_number] = [Second - Table$].[Policy Agent]and [ACAT$].[ACAT_EffectiveDate] <= '2014-10-01')) ,
    [Second - Table$].[Policy Agent] ))) as [Policy Agent],
    ''''''summing up all other columns''''''''''''''
    (iif(isnull(sum([Second - Table$].[Auto BW-Line Of Business Detail])),0,sum([Second - Table$].[Auto BW-Line Of Business Detail]))) as [Auto BW-Line Of Business Detail],(iif(isnull(sum([Second - Table$].[Auto Farmers])),0,sum([Second - Table$].[Auto Farmers])))
    as [Auto Farmers],(iif(isnull(sum([Second - Table$].[MCA])),0,sum([Second - Table$].[MCA]))) as [MCA],(iif(isnull(sum([Second - Table$].[CEA])),0,sum([Second - Table$].[CEA]))) as [CEA],(iif(isnull(sum([Second - Table$].[Commercial P&C])),0,sum([Second
    - Table$].[Commercial P&C]))) as [Commercial P&C],(iif(isnull(sum([Second - Table$].[Comm WC])),0,sum([Second - Table$].[Comm WC]))) as [Comm WC],(iif(isnull(sum([Second - Table$].[Fire Farmers])),0,sum([Second - Table$].[Fire Farmers]))) as [Fire
    Farmers],(iif(isnull(sum([Second - Table$].[Flood])),0,sum([Second - Table$].[Flood]))) as [Flood],(iif(isnull(sum([Second - Table$].[Kraft Lake])),0,sum([Second - Table$].[Kraft Lake]))) as [Kraft Lake],(iif(isnull(sum([Second - Table$].[Life])),0,sum([Second
    - Table$].[Life]))) as [Life],(iif(isnull(sum([Second - Table$].[Foremost])),0,sum([Second - Table$].[Foremost]))) as [Foremost],(iif(isnull(sum([Second - Table$].[Umbrella])),0,sum([Second - Table$].[Umbrella]))) as [Umbrella],(iif(isnull(sum([Second - Table$].[MCNA])),0,sum([Second
    - Table$].[MCNA]))) as [MCNA]
    INTO [Excel 12.0;DATABASE=C:\Prod Validation\Database\Second Acat Table.xlsb].[Sheet1]
    from [Second - Table$] group by [Second - Table$].[Policy Agent] ;

    Hi Fei,
      Thank you so much for the reply post. I just executed the same above SQL without INTO Statement and assigned the SQL result to ADODB recordset as below. If the time difference is due to the SQL query then below statements also should execute for hours
    right, but it gets executed in seconds. But to copy the recordset to excel again it is taking hours. I tried copyfromrecordset,
    getrows(), getstring(), Looping each recordset fields options and all of them taking same amount of time. Please let me know there is delay in time for this much small data
    Even I tried to typecast all columns to double, string in SQL and still the execution time  is not reduced. 
    First_Temp_Recordset.Open sql_qry, Tables_conn_obj, adOpenStatic, adLockOptimistic ''' OR SET First_Temp_Recordset = Tables_conn_obj.Execute sql_qry

  • Need of SQL query in selecting distinct values from two tables

    hi,
    I need a query for selecting distinct values from two tables with one condition.
    for eg:
    there are two tables a & b.
    in table a there are values like age,sex,name,empno and in table b valuses are such as age,salary,DOJ,empno.
    here what i need is with the help of empno as unique field,i need to select distinct values from two tables (ie) except age.
    can anybody please help me.
    Thanks in advance,
    Ratheesh

    Not sure what you mean either, but perhaps this will start a dialog:
    SELECT DISTINCT a.empno,
                    a.name,
                    a.sex,
                    b.salary,
                    b.doj
    FROM    a,
            b
    WHERE   a.empno = b.empno;Greg

  • Populating item using a sql query based on other item of diff table

    Hi,
    It would be great if someone could help.
    I have two items on my form page .
    My first item P1_sub_prog is of select list with submit, it fetches values from table prog "mv_cap_prog_subprog" of the same schema whihc I am using for teh current application.
    I want my second item P1_PROGRAM to be populated with value corresponding to my first item value, after being fetched from the same table on the basis of the first item value (P1_SUB_PROG)
    Both the item values have a relation.
    I tried by creating sql as well as LOV for the second item but its not working.
    It displays nulll in the second item field.
    While using sql I tried the following query
    in the source request of second item i.e P1_PROGRAM
    SELECT DISTINCT a.program_id d,a.program_id r FROM
    mv_cap_prog_subprog
    WHERE SUB_PROGRAM_ID = :P1_sub_prog

    Hi,
    Search this forum for "cascading select list".
    You will find lots of help.
    Cheers,
    Patrick

  • SQL Query to Read each record in a table

    Can you please share any T-SQL block of statement, that reads reach record row by row
    for example
    Table1
    Row_1 a b c
    Row_2 d e f
    I need to call an stored proc which takes record values as parameters(row by row)
    Equalent logic in c#
    foreach row in Table1
          Sp(row)

    Try
    --Create table
    CREATE TABLE Test1 (
    id INT identity(1, 1)
    ,Val INT
    ,flag CHAR(1) DEFAULT 'F'
    --Feed value
    INSERT INTO Test1
    VALUES (
    1
    ,'F'
    2
    ,'F'
    3
    ,'F'
    SELECT *
    FROM Test1
    --Create SP
    CREATE PROCEDURE yourSp @param INT
    AS
    BEGIN
    SELECT 'Yes'
    ,@param
    END
    DECLARE @i INT = 1
    ,@count INT = 0
    ,@val INT = 0
    SELECT @count = count(1)
    FROM Test1
    WHILE (@i <= @count)
    BEGIN
    SELECT @val = Val
    FROM Test1
    WHERE id = @i
    EXEC YourSP @val
    SET @i = @i + 1
    END
    Thanks
    Manish
    Please click Mark as Answer if my post solved your problem and click
    Vote as Helpful if this post was useful.

  • Need suggestions for improving sql query.

    Hi,
    There is an sql query which loads data into a single table from 80 other tables which are loaded with data from different sites.The sql query to load from these 80 tables into single table is taking almost 40 min everyday with 6-7 million records.
    The notation followed
    the table is truncated first and then the constraints are disabled.
    insert into single table (column1,column2,column3)
    ( select * from table1
    union all
    select * from table2
    union all
    select * from table3
    union all
    select * from table80);
    enable the constraints.
    The database is 10.2.0.3.Is there any other way that can be implemented or modified this to get a better response time to load the data faster.
    Thanks

    A lot of IFs, but
    if you have a licence for the partitioning option, and
    if the data has some convenient partitioning column - such as a 'site' column which could be used for list partitioning, and
    if you don't need the separate tables to exist after you have consolidated the data
    if you can create all other necessary constraints on the base tables,
    you could:
    create main table as empty, but partitioned with 80 empty partitions
    exchange partition with table 80 times in a row.
    Regards
    Jonathan Lewis
    http://jonathanlewis.wordpress.com
    http://www.jlcomp.demon.co.uk

  • XML Generation using a sql query in an efficient way -Help needed urgently

    Hi
    I am facing the following issue while generating xml using an sql query. I get the below given table using a query.
         CODE      ID      MARK
    ==================================
    1 4 2331 809
    2 4 1772 802
    3 4 2331 845
    4 5 2331 804
    5 5 2331 800
    6 5 2210 801
    I need to generate the below given xml using a query
    <data>
    <CODE>4</CODE>
    <IDS>
    <ID>2331</ID>
    <ID>1772</ID>
    </IDS>
    <MARKS>
    <MARK>809</MARK>
    <MARK>802</MARK>
    <MARK>845</MARK>
    </MARKS>
    </data>
    <data>
    <CODE>5</CODE>
    <IDS>
    <ID>2331</ID>
    <ID>2210</ID>
    </IDS>
    <MARKS>
    <MARK>804</MARK>
    <MARK>800</MARK>
    <MARK>801</MARK>
    </MARKS>
    </data>
    Can anyone help me with some idea to generate the above given CLOB message

    not sure if this is the right way to do it but
    /* Formatted on 10/12/2011 12:52:28 PM (QP5 v5.149.1003.31008) */
    WITH data AS (SELECT 4 code, 2331 id, 809 mark FROM DUAL
                  UNION
                  SELECT 4, 1772, 802 FROM DUAL
                  UNION
                  SELECT 4, 2331, 845 FROM DUAL
                  UNION
                  SELECT 5, 2331, 804 FROM DUAL
                  UNION
                  SELECT 5, 2331, 800 FROM DUAL
                  UNION
                  SELECT 5, 2210, 801 FROM DUAL)
    SELECT TO_CLOB (
                 '<DATA>'
              || listagg (xml, '</DATA><DATA>') WITHIN GROUP (ORDER BY xml)
              || '</DATA>')
              xml
      FROM (  SELECT    '<CODE>'
                     || code
                     || '</CODE><IDS><ID>'
                     || LISTAGG (id, '</ID><ID>') WITHIN GROUP (ORDER BY id)
                     || '</ID><IDS><MARKS><MARK>'
                     || LISTAGG (mark, '</MARK><MARK>') WITHIN GROUP (ORDER BY id)
                     || '</MARK></MARKS>'
                        xml
                FROM data
            GROUP BY code)

  • How to build sql query for view object at run time

    Hi,
    I have a LOV on my form that is created from a view object.
    View object is read-only and is created from a SQL query.
    SQL query consists of few input parameters and table joins.
    My scenario is such that if input parameters are passed, i have to join extra tables, otherwise, only one table can fetch the results I need.
    Can anyone please suggest, how I can solve this? I want to build the query for view object at run time based on the values passed to input parameters.
    Thanks
    Srikanth Addanki

    As I understand you want to change the query at run time.
    If this is what you want, you can use setQuery Method then use executeQuery.
    http://download.oracle.com/docs/cd/B14099_19/web.1012/b14022/oracle/jbo/server/ViewObjectImpl.html#setQuery_java_lang_String_

  • Help needed in Exporting tables data through SQL query

    Hi All,
    I need to write a shell script(ksh) to take some of the tables data backup.
    The tables list is not static, and those are selecting through dynamic sql
    query.
    Can any body tell help me how to write the export command to export tables
    which are selected dynamically through SQL query.
    I tried like this
    exp ------ tables = query \" select empno from emp where ename\= \'SSS\' \"
    but its throws the following error
    EXP-00035: QUERY parameter valid only for table mode exports
    Thanks in advance,

    Hi,
    You can dynamically generate parameter file for export utility using shell script. This export parameter file can contain any table list you want every time. Then simply run the command
    $ exp parfile=myfile.txt

  • Sql query/function problem??

    Hi ,
    I have problems writing a difficult sql query, please help me
    I have a table t in which there are 50000 records
    the table has columns like
    create table t
    (MATCH_ID     NUMBER(4) NOT NULL,
    TEAM_ID NUMBER(4),
    PLAYER_ID     NUMBER(4),
    RUNS     NUMBER(3))
    here match_id, player_id and team_id are jointly primary key
    SQL> SELECT * FORM T WHERE MATCH_ID < 10
    MATCH_ID    TEAM_ID      PL_ID RUNS
            1          2       1228 8
            1          2       1203 82
            1          2       1316 24
            1          1       1150 27
            1          1       1278 13
            1          1       1243 60
            2          1       1278 37
            2          1       1291 0
            2          1       1243 53
            2          2       1228 25
            2          2       1285 103
            2          2       1316 60
            3          2       1228 8
            3          2       1285 25
            3          2        858 43
            3          1       1278 52
            3          1       1394 6
            3          1       1243 31
            4          1       1278 61
            4          1       1394 6
            4          1       1243 3
            4          2       1228 41
            4          2       1285 40
            4          2        858 5
            6          2       1228 20
            6          2       1285 100
            6          2       1408 0
            7          2       1228 15
            7          2       1285 34
            7          2       1408 44
            8          2       1228 0
            8          2       1420 31
            8          2       1340 66
            9          2       1420 19
            9          2       1385 28
            9          2       1340 0
    .....so on upto 50000 records..
    the problem is that I want to extract how many times each player_id in each
    match exists in the table, prior to that match_id (or current_match_id)
    along with that in another column, I also want the sum of 'RUNS' for each
    player_id  prior to that match_id (or current_match_id)
    my disired output is:
    MATCH_ID    TEAM_ID   player_ID RUNS   NO_OF_OCCURENCES    SUM(RUNS)
                                           BEFORE_THIS_MATCH   BEFORE_THIS_MATCH
                                           FOR_THIS_PLAYER_ID  FOR_THIS_PLAYER_ID
            1          2       1228 8      0                   0
            1          2       1203 82     0                   0
            1          2       1316 24     0                   0
            1          1       1150 27     0                   0
            1          1       1278 13     0                   0
            1          1       1243 60     0                   0
            2          1       1278 37     1                   13
            2          1       1291 0      0                   0
            2          1       1243 53     1                   60
            2          2       1228 25     1                   8
            2          2       1285 103    0                   0
            2          2       1316 60     1                   24
            3          2       1228 8      2                   33
            3          2       1285 25     1                   103
            3          2        858 43     0                   0
            3          1       1278 52     2                   50
            3          1       1394 6      0                   0
            3          1       1243 31     2                   113
            4          1       1278 61     3                   102
            4          1       1394 6      1                   6
            4          1       1243 3      3                   144
            4          2       1228 41     3                   41
            4          2       1285 40     2                   128
            4          2        858 5      1                   43
            6          2       1228 20     4                   82
            6          2       1285 100    3                   168
            6          2       1408 0      0                   0
            7          2       1228 15     5                   102
            7          2       1285 34     4                   268
            7          2       1408 44     1                   0
            8          2       1228 0      6                   117
            8          2       1420 31     0                   0
            8          2       1340 66     0                   0
            9          2       1420 19     1                   31
            9          2       1385 28     0                   0
            9          2       1340 0      1                   66
    as you can see from the above data (5TH COLUMN), i have mentioned the
    existance of each player_id in each match prior to the current_match_id
    since match_id = 1 is the 1st match in the table so no player_id comes in the
    table before match number 1.   
    In match number 2 , player_id = 1278 was also present in match_id = 1 so
    thats why Number_OF_OCCURENCES = 1 for  player_id = 1278 in match_id = 2
    and so on..
    same is the case with 'RUNS' column but here RUNS are the SUM of each
    player_id's 'RUNS' before the current match
    Note: if some player_id does not exist in the table before the current
    match_ID then the query should return zero for that player_id ( as in 4th and
    5th columns of no_of_occurances and sum(runs) respectively)
    for example: in above data
    MATCH_ID    TEAM_ID  PLayer_ID RUNS   NO_OF_OCCURENCES    SUM(RUNS)
                                          BEFORE_THIS_MATCH   BEFORE_THIS_MATCH
                                          FOR_THIS_PLAYER_ID  FOR_THIS_PLAYER_ID
           9          2       1385 28     0                   0
    I hope this will clear my problem
    i would be extremely grateful if someone helps me out??
    here is sample ddl of the above data
    create table t
    (MATCH_ID     NUMBER(4) NOT NULL,
    TEAM_ID         NUMBER(4),
    PLAYER_ID     NUMBER(4),
    RUNS     NUMBER(3))
    insert into t (MATCH_ID, TEAM_ID, PLAYER_ID, RUNS) values (1, 2, 1228, 8);
    insert into t (MATCH_ID, TEAM_ID, PLAYER_ID, RUNS) values (1, 2, 1203, 82);
    insert into t (MATCH_ID, TEAM_ID, PLAYER_ID, RUNS) values (1, 2, 1316, 24);
    insert into t (MATCH_ID, TEAM_ID, PLAYER_ID, RUNS) values (1, 1, 1150, 27);
    insert into t (MATCH_ID, TEAM_ID, PLAYER_ID, RUNS) values (1, 1, 1278, 13);
    insert into t (MATCH_ID, TEAM_ID, PLAYER_ID, RUNS) values (1, 1, 1243, 60);
    insert into t (MATCH_ID, TEAM_ID, PLAYER_ID, RUNS) values (2, 1, 1278, 37);
    insert into t (MATCH_ID, TEAM_ID, PLAYER_ID, RUNS) values (2, 1, 1291, 0);
    insert into t (MATCH_ID, TEAM_ID, PLAYER_ID, RUNS) values (2, 1, 1243, 53);
    insert into t (MATCH_ID, TEAM_ID, PLAYER_ID, RUNS) values (2, 2, 1228, 25);
    insert into t (MATCH_ID, TEAM_ID, PLAYER_ID, RUNS) values (2, 2, 1285, 103);
    insert into t (MATCH_ID, TEAM_ID, PLAYER_ID, RUNS) values (2, 2, 1316, 60);
    insert into t (MATCH_ID, TEAM_ID, PLAYER_ID, RUNS) values (3, 2, 1228, 8);
    insert into t (MATCH_ID, TEAM_ID, PLAYER_ID, RUNS) values (3, 2, 1285, 25);
    insert into t (MATCH_ID, TEAM_ID, PLAYER_ID, RUNS) values (3, 2, 858, 43);
    insert into t (MATCH_ID, TEAM_ID, PLAYER_ID, RUNS) values (3, 1, 1278, 52);
    insert into t (MATCH_ID, TEAM_ID, PLAYER_ID, RUNS) values (3, 1, 1394, 6);
    insert into t (MATCH_ID, TEAM_ID, PLAYER_ID, RUNS) values (3, 1, 1243, 31);
    insert into t (MATCH_ID, TEAM_ID, PLAYER_ID, RUNS) values (4, 1, 1278, 61);
    insert into t (MATCH_ID, TEAM_ID, PLAYER_ID, RUNS) values (4, 1, 1394, 6);
    insert into t (MATCH_ID, TEAM_ID, PLAYER_ID, RUNS) values (4, 1, 1243, 3);
    insert into t (MATCH_ID, TEAM_ID, PLAYER_ID, RUNS) values (4, 2, 1228, 41);
    insert into t (MATCH_ID, TEAM_ID, PLAYER_ID, RUNS) values (4, 2, 1285, 40);
    insert into t (MATCH_ID, TEAM_ID, PLAYER_ID, RUNS) values (4, 2, 858, 5);
    insert into t (MATCH_ID, TEAM_ID, PLAYER_ID, RUNS) values (6, 2, 1228, 20);
    insert into t (MATCH_ID, TEAM_ID, PLAYER_ID, RUNS) values (6, 2, 1285, 100);
    insert into t (MATCH_ID, TEAM_ID, PLAYER_ID, RUNS) values (6, 2, 1408, 0);
    insert into t (MATCH_ID, TEAM_ID, PLAYER_ID, RUNS) values (7, 2, 1228, 15);
    insert into t (MATCH_ID, TEAM_ID, PLAYER_ID, RUNS) values (7, 2, 1285, 34);
    insert into t (MATCH_ID, TEAM_ID, PLAYER_ID, RUNS) values (7, 2, 1408, 44);
    insert into t (MATCH_ID, TEAM_ID, PLAYER_ID, RUNS) values (8, 2, 1228, 0);
    insert into t (MATCH_ID, TEAM_ID, PLAYER_ID, RUNS) values (8, 2, 1420, 31);
    insert into t (MATCH_ID, TEAM_ID, PLAYER_ID, RUNS) values (8, 2, 1340, 66);
    insert into t (MATCH_ID, TEAM_ID, PLAYER_ID, RUNS) values (9, 2, 1420, 19);
    insert into t (MATCH_ID, TEAM_ID, PLAYER_ID, RUNS) values  (9, 2, 1385, 28);
    insert into t (MATCH_ID, TEAM_ID, PLAYER_ID, RUNS) values (9, 2, 1340, 0);regards
    ramis.

    Ramis,
    SQL> select * from tt;
      MATCH_ID    TEAM_ID  PLAYER_ID       RUNS
             1          2       1228          8
             1          2       1203         82
             1          2       1316         24
             1          1       1150         27
             1          1       1278         13
             1          1       1243         60
             2          1       1278         37
             2          1       1291          0
             2          1       1243         53
             2          2       1228         25
             2          2       1285        103
             2          2       1316         60
             3          2       1228          8
             3          2       1285         25
             3          2        858         43
             3          1       1278         52
             3          1       1394          6
             3          1       1243         31
             4          1       1278         61
             4          1       1394          6
             4          1       1243          3
             4          2       1228         41
             4          2       1285         40
             4          2        858          5
             6          2       1228         20
             6          2       1285        100
             6          2       1408          0
             7          2       1228         15
             7          2       1285         34
             7          2       1408         44
             8          2       1228          0
             8          2       1420         31
             8          2       1340         66
             9          2       1420         19
             9          2       1385         28
             9          2       1340          0
    36 rows selected.
    SQL> select tt.match_id,
           tt.team_id,
           tt.player_id,
           tt.runs,
           nvl(a.sum_player,0) OCC,
           nvl(b.sum_runs,0) SUM_RUNS
    from
    tt,
    (select a.match_id,a.team_id,a.player_id,a.runs,count(*) sum_player
    from tt a,
          (select match_id,player_id
           from   tt
           group by match_id,player_id) b
    where a.match_id>b.match_id
    and   a.player_id=b.player_id
    group by a.match_id,a.team_id,a.player_id,a.runs
    ) a,
    (select a.match_id,a.team_id,a.player_id,a.runs,sum(b.runs) sum_runs
    from tt a,
          (select match_id,player_id,runs
           from   tt) b
    where a.match_id>b.match_id
    and   a.player_id=b.player_id
    group by a.match_id,a.team_id,a.player_id,a.runs
    ) b
    where tt.match_id=a.match_id(+)
    and tt.team_id=a.team_id(+)
    and tt.player_id=a.player_id(+)
    and tt.match_id=b.match_id(+)
    and tt.team_id=b.team_id(+)
    and tt.player_id=b.player_id(+)
      MATCH_ID    TEAM_ID  PLAYER_ID       RUNS        OCC   SUM_RUNS
             1          1       1150         27          0          0
             1          1       1243         60          0          0
             1          1       1278         13          0          0
             1          2       1203         82          0          0
             1          2       1228          8          0          0
             1          2       1316         24          0          0
             2          1       1243         53          1         60
             2          1       1278         37          1         13
             2          1       1291          0          0          0
             2          2       1228         25          1          8
             2          2       1285        103          0          0
             2          2       1316         60          1         24
             3          1       1243         31          2        113
             3          1       1278         52          2         50
             3          1       1394          6          0          0
             3          2        858         43          0          0
             3          2       1228          8          2         33
             3          2       1285         25          1        103
             4          1       1243          3          3        144
             4          1       1278         61          3        102
             4          1       1394          6          1          6
             4          2        858          5          1         43
             4          2       1228         41          3         41
             4          2       1285         40          2        128
             6          2       1228         20          4         82
             6          2       1285        100          3        168
             6          2       1408          0          0          0
             7          2       1228         15          5        102
             7          2       1285         34          4        268
             7          2       1408         44          1          0
             8          2       1228          0          6        117
             8          2       1340         66          0          0
             8          2       1420         31          0          0
             9          2       1340          0          1         66
             9          2       1385         28          0          0
             9          2       1420         19          1         31
    36 rows selected.
    SQL> Is this do you want ?
    Nicolas.

  • Result of an SQL query as a Column name of another query

    Hi Friends,
    Can we use a result of a SQL Query as a column name of another table to retrieve data. If so please help me.
    For eg :
    I have a table where is store numbers;
    select col1 from table1 where col1='5';
    and i have another table where .. this value of col is a column name..
    select ( select col1 from table1 where col1='5') from table2;
    Thanks in advance.

    Hi,
    ORAFLEX wrote:
    Hi Friends,
    Can we use a result of a SQL Query as a column name of another table to retrieve data. If so please help me.
    For eg :
    I have a table where is store numbers;
    select col1 from table1 where col1='5';
    and i have another table where .. this value of col is a column name..
    select ( select col1 from table1 where col1='5') from table2;
    Thanks in advance.Do you really mean that?
    select col1 from table1 where col1='5';That query will always return either '5' or nothing. Whatever you're trying to accomplish with that, you can do with an EXISTS query.
    Perhaps you meant to reference two different columns in that query:
    select col1 from table1 where col2='5';In that case, sorry, no, you can't do that without resorting to dynamic SQL.
    If the same column is used throughout the query (but could change every time you run the query), then the dynamic SQL might be pretty easy. In SQL*Plus, for example, you could use substitution variables, defined in another query at run-time.
    If there are only a few possible values that the sub-query could possibly return, and you know what they all are, then you can fake a dynamic query like this:
    SELECT     CASE     ( SELECT  col1
                FROM       table1
                WHERE       col2     = '5'
              WHEN  'BONUS'     THEN  bonus
              WHEN  'COMM'     THEN  comm
              WHEN  'SAL'     THEN  sal
         END     AS col1
    FROM     table2
    ;Sorry to give such a vague answer, but it's the best I can do with the information I have.
    It would help if you posted a little sample data (CREATE TABLE and INSERT statments for both tables), and the results you want to get from that data. If you want to pass a parameter to the query, give the results you want for a couple of different parameters.

Maybe you are looking for

  • Oracle Financial 11.5.10.2 on Windows 2003 Installation Problem

    When I install the Oracle Finanacial the Rapidwiz show the error Oxcf9302f0 referenced memory at Oxcf9302f0. The memory could not be read. and after this the error shown RW-20013: Error: - Not enough free disk space on system: Database ORACLE_HOME =

  • Upgraded Itunes to 7.6.. Cant find Iphone?

    Hi! No I have no idea how this happned. Havn't had any problems with the Iphone and Itunes before. (Using Windows) So I saw that there was a new Itunes out and also a new firmware for Iphone! So yea, I started with upgrading my Itunes to the new vers

  • Hp g62 Black screen caps lock on and wifi button on

    Hello, My friend is having a problem with his laptop hp g62 which is 1 1/2 years old. This happened out of no where and have no idea why. Here is what happens: We power it up, fans turns on, caps lock stays on and Screen stays blank. Again we have no

  • Compare Oracle 10g & Oracle 11g

    Hi All, May i know the major differnece between the oracle 10g Vs oracle 11g. Regards S.Senthl Kumar

  • Does Aperture need to be on my computer's internal HD to be a managed library?

    My main Aperture Library (I have 5, but I'll get to that on another post) is on an external HD. If I store masters on this AL, will they become managed or are they referenced because the library is on an external HD? Also, I read a discussion where s