Using TRUNC function on partitioned column

Hi All,
I have a table as follows:
STEP1
CREATE TABLE TEST_PARTITION
EMP_ID VARCHAR2(10 BYTE),
CREATE_DT DATE,
EMP_RGN_NM VARCHAR2(2 BYTE),
DSPTCH_CNT NUMBER
PARTITION BY RANGE (CREATE_DT)
SUBPARTITION BY LIST(EMP_RGN_NM)
SUBPARTITION TEMPLATE(
SUBPARTITION RGN_E VALUES ('E') ,
SUBPARTITION RGN_MW VALUES ('MW') ,
SUBPARTITION RGN_SW VALUES ('SW') ,
SUBPARTITION RGN_W VALUES ('W') ,
SUBPARTITION RGN_SE VALUES ('SE')
PARTITION aug2008 VALUES LESS THAN (TO_DATE('01-Sep-2008', 'DD-MON-YYYY')),
PARTITION sep2008 VALUES LESS THAN (TO_DATE('01-Oct-2008', 'DD-MON-YYYY')),
PARTITION oth VALUES LESS THAN (MAXVALUE)
ENABLE ROW MOVEMENT;
STEP 2
insert into TEST_PARTITION values(1000,TO_DATE('01-Aug-2008 12:02:02', 'DD-MON-YYYY HH:MI:SS'),'SE',10)
insert into TEST_PARTITION values(1000,TO_DATE('02-Aug-2008 12:02:02', 'DD-MON-YYYY HH:MI:SS'),'SE',20);
insert into TEST_PARTITION values(1000,TO_DATE('03-Aug-2008 12:02:02', 'DD-MON-YYYY HH:MI:SS'),'SE',0);
insert into TEST_PARTITION values(1000,TO_DATE('01-sep-2008 12:02:02', 'DD-MON-YYYY HH:MI:SS'),'SE',10);
insert into TEST_PARTITION values(1000,TO_DATE('02-sep-2008 12:02:02', 'DD-MON-YYYY HH:MI:SS'),'SE',10);
insert into TEST_PARTITION values(1000,TO_DATE('01-Oct-2008 12:02:02', 'DD-MON-YYYY HH:MI:SS'),'SE',10);
insert into TEST_PARTITION values(1001,TO_DATE('01-Aug-2008 12:02:02', 'DD-MON-YYYY HH:MI:SS'),'SE',1);
insert into TEST_PARTITION values(1001,TO_DATE('02-Aug-2008 12:02:02', 'DD-MON-YYYY HH:MI:SS'),'SE',2);
insert into TEST_PARTITION values(1001,TO_DATE('03-Aug-2008 12:02:02', 'DD-MON-YYYY HH:MI:SS'),'SE',0);
insert into TEST_PARTITION values(1001,TO_DATE('01-sep-2008 12:02:02', 'DD-MON-YYYY HH:MI:SS'),'SE',10);
insert into TEST_PARTITION values(1001,TO_DATE('02-sep-2008 12:02:02', 'DD-MON-YYYY HH:MI:SS'),'SE',5);
insert into TEST_PARTITION values(1001,TO_DATE('01-Oct-2008 12:02:02', 'DD-MON-YYYY HH:MI:SS'),'SE',10);
insert into TEST_PARTITION values(1001,TO_DATE('02-Oct-2008 12:02:02', 'DD-MON-YYYY HH:MI:SS'),'SE',10);
STEP 3
I need to get all the dispatches on 1st of August and hence issue the statement as follows:
select * from test_partition where TRUNC(CREATE_DT)='01-Aug-2008' and EMP_RGN_NM = 'SE'
Using a function over the partitioned column, will it avaoid partition pruning? I mean will it scan all the partitiones instead of going to specific partition?
I need this urgently since we are having a discussion on this in few minutes from now.
Thanks so much
Saff

What about a function based index ?
SQL> select * from test_partition where TRUNC(CREATE_DT)='01-Aug-2008' and EMP_RGN_NM = 'SE';
Execution Plan
| Id  | Operation              | Name           | Rows  | Bytes | Cost (%CPU)| Pstart| Pstop |
|   0 | SELECT STATEMENT       |                |     1 |    32 |     4   (0)|       |       |
|   1 |  PARTITION RANGE ALL   |                |     1 |    32 |     4   (0)|     1 |     3 |
|   2 |   PARTITION LIST SINGLE|                |     1 |    32 |     4   (0)|   KEY |   KEY |
|   3 |    TABLE ACCESS FULL   | TEST_PARTITION |     1 |    32 |     4   (0)|   KEY |   KEY |
Note
   - 'PLAN_TABLE' is old version
SQL> create index idx on test_partition (TRUNC(CREATE_DT));
Index created.
SQL> select * from test_partition where TRUNC(CREATE_DT)='01-Aug-2008' and EMP_RGN_NM = 'SE';
Execution Plan
| Id  | Operation                          | Name           | Rows  | Bytes | Cost (%CPU)| Pstart| Pstop |
|   0 | SELECT STATEMENT                   |                |     1 |    32 |     2   (0)|       |       |
|   1 |  TABLE ACCESS BY GLOBAL INDEX ROWID| TEST_PARTITION |     1 |    32 |     2   (0)| ROWID | ROWID |
|   2 |   INDEX RANGE SCAN                 | IDX            |     1 |       |     1   (0)|       |       |
Note
   - 'PLAN_TABLE' is old version
I need this urgently since we are having a discussion on this in few minutes from now.It is not our problem, but yours.
Nicolas.

Similar Messages

  • How to use TRUNC function with dates in Expression Builder in OBIEE.

    Hi There,
    How to use TRUNC function with dates in Expression Builder in OBIEE.
    TRUNC (SYSDATE, 'MM') returns '07/01/2010' where sysdate is '07/15/2010' in SQL. I need to use the same thing in expression builder in BMM layer logical column.
    Thanks in advance

    use this instead:
    TIMESTAMPADD(SQL_TSI_DAY, ( DAYOFMONTH(CURRENT_DATE) * -1) + 1, CURRENT_DATE)

  • Using CURRENT_DATE function in DATE column

    Hi
    I am not able to use CURRENT_DATE function in my target DATE column.I am getting error like "EDATE": invalid identifier with defintion as 'Insert PK error'. This column is not there in the source table.
    Data Transfer from Oracle to Oracle
    IKM = SQL Incremental Update
    CKM = SQL Check
    LKM = LKM SQL to SQL

    Hi Shaishavi,
    check your Target datastore in Model whether it contains the DATE column or Not.
    have you use this Date column in PK?.
    Colud you please sent me the Error command which you have faced? And tell me about the interface detaily.
    Thanks,
    Madha.

  • Using AGO function with partitions

    I have a situation where we have logical sources with the same repository folder that are partitioned. We would like to use the AGO function but are getting the following error:
    State: HY000. Code: 10058. [NQODBC] [SQL_STATE: HY000] [nQSError: 10058] A general error has occurred. [nQSError: 22042] AGO function may not be used on '# Applied Invoices' because its source is horizontally partitioned. (HY000)
    Has anyone had success using the AGO function with partitions? If not, do you have an alternate solution to the problem?

    AGO doesn't work with partitions - it's documented on metalink....there's an enhancement request , but that's it - no work-around provided....I'd suggest creating a common view for that particular report

  • Using Trunc Function in OBIEE RPD to TRIM DATE

    Below is my requirment.How can i achieve this in BMM layer.
    CASE WHEN TRUNC(REPORTDATE) <= TRUNC(SYSDATE-2) THEN 1 ELSE 0 END

    Try this
    case when cast(REPORTDATE as date)<=cast((current_date-2) as date) then 1 else 0 end
    let me know updates
    Thanks
    http://cool-bi.com
    Edited by: Srini VEERAVALLI on May 22, 2013 9:29 AM

  • Using UPPER function with LONG datatype column

    Hi,
    Can anyone tell that how can I use UPPER function on a column which has data type as-- LONG?
    For ex--
    SELECT * FROM TABLE WHERE UPPER(LONG_COL) LIKE 'MYTEXT%';
    thanks,
    Abhijeet
    Edited by: @bhijeet ☻☻☻ on Nov 18, 2009 5:20 AM

    @bhijeet ☻☻☻ wrote:
    Yes I know that that's why I am asking about an alternate solution for it. Could you please let me know if you have any solution to do it?
    Thanks,
    AbhijeetI think you'll have to write a function to do this for you. You can use DBMS_SQL to break a LONG into pieces and work with 32K segments. I am not sure how to put the converted data back into the LOB at that point, though DBMS_SQL might provide a way to do this.

  • Using Analytic Functions

    Hi all,
    I am using ODI 11g(11.1.1.3.0) and I am trying to make an interface using analytic functions in the column mapping, something like below.
    sum(salary) over (partition by .....)
    The problem is that when ODI saw sum it assumes this as an aggregate function and puts group by. Is there any way to make ODI understand it is not an aggregate function?
    I tried creating an option to specify whether it is analytic or not and updated IKM with no luck.
    <%if ( odiRef.getUserExit("ANALYTIC").equals("1") ) { %>
    <% } else { %>
    <%=odiRef.getGrpBy(i)%>
    <%=odiRef.getHaving(i)%>
    <% } %>
    Thanks in advance

    Thanks for the reply.
    But I think in ODI 11g getFrom() function is behaving differently, that is why it is not working.
    When I check out the A.2.18 getFrom() Method from Substitution API Reference document, it says
    Allows the retrieval of the SQL string of the FROM in the source SELECT clause for a given dataset. The FROM statement is built from tables and joins (and according to the SQL capabilities of the technologies) that are used in this dataset.
    I think getfrom also retrieves group by clause, I create a step in IKM just with *<%=odiRef.getFrom(0)%>* and I can see that even that query generated has a group by clause

  • Using TRUNC in timestamps

    Sir,
    As you know we were using TRUNC function in DATE datatype. But I want to use it with TIMESTAMP datatypes. For example:
    select trunc(systimestamp,'hh24:mi:ss') from dual;
    The main idea to get some part of given timestamp without using type conversions (i.e. TO_CHAR).
    Note that this is useful when you want to ADD or Subtract the time side from timestamp with interval values and comparing them to another timestamps fields or values.
    Thank you in advance.

    Trunc is not working in 9i
    Oracle9i Enterprise Edition Release 9.2.0.1.0 - Production
    With the Partitioning, OLAP and Oracle Data Mining options
    JServer Release 9.2.0.1.0 - Production
    SQL> SELECT current_timestamp - TRUNC (current_timestamp) time
    2 FROM dual
    3 /
    SELECT current_timestamp - TRUNC (current_timestamp) time
    ERROR at line 1:
    ORA-00932: inconsistent datatypes: expected NUMBER got TIMESTAMP
    SQL>
    But in 10g...
    Personal Oracle Database 10g Release 10.1.0.2.0 - Production
    With the Partitioning, OLAP and Data Mining options
    SQL> SELECT current_timestamp - TRUNC (current_timestamp) time
    2 FROM dual;
    TIME
    +000000000 14:53:04.941000
    SQL>
    Why?

  • Use EVALUATE function in obiee

    Hi ALL
    i hv a database query like this;
    select
    deptno,
    rtrim (xmlagg (xmlelement (e, ename || ',')).extract ('//text()'), ',') enamesfrom
    emp
    group by
    deptno;
    now, i want to use this using Evaluate function in obiee column formula.
    thn how to do it.
    Please reply.
    THX
    SAP

    Hello SAP,
    I have seen you for sometime and one thing I came to know is you are creating threads and once you got your solution or you dont feel to follow up you are just leaving the thread.
    see few here,
    Sorting month name
    Drill down problem
    Re: Filter in Union Request
    so please better close the threads which are answered and proceed further.

  • Best practices on using EVALUATE functions

    hi, experts,
    I wanna know what is the best practices on using EVALUATE functions on obiee (calling oracle user defined functions)
    I found that if I use evaluate functions in Answers,
    obiee will construct a sql behind and then execute.
    sometimes, obiee contructs some unexpected sqls, and returns errors.
    so, is it better to use EVALUATE functions in logical columns ?
    thanks

    EVALUATE('DB_Function(%1)' as returntype, {Comma separated Expression})
    even when used in Logical columns, its gonna fire the same sql.

  • Error when trying to use trim function

    when i try to use trim function on a column it gives me following error for the below query
    select trim(first_name) name from table1@pa1;
    ORA-28500: connection from ORACLE to a non-Oracle system returned this message:
    DSNT408I SQLCODE = -440, ERROR: NO FUNCTION BY THE NAME TRIM HAVING COMPATIBLE ARGUMENTS WAS FOUND IN THE CURRENT PATH DSNT418I SQLSTATE = 42884 SQLSTATE RETURN CODE DSNT415I SQLERRP = DSNXORFN SQL PROCEDURE DETECTING ERROR DSNT416I SQLERRD = -100 0 0 -1 0 0 SQL DIAGNOSTIC INFORMATION DSNT416I SQLERRD = X'FFFFFF
    any idea gurus ???Thanks

    This might work:
    select trim(first_name) name from
      (select first_name from table1@pa1);The problem is that pa1 is a non-Oracle database and does not have a trim function. It may have another function that does the same thing but it's not called TRIM.

  • SSRS 2008R2 : Not able to use Previous aggregrate function in matrix columns cell

    Hi Expert,
    I have used a matrix tablix in my report. It is working fine. But when I am trying to use Previous aggregrate in one matrix column cell I get the below error:
    The use of previous aggregrate function ia a tablix cell with in 'Tablix1' is not supported.
    Please help me regarding that.
    Thanks Rana

    Hi Rana,
    In your scenario, you use previous function in the “Data” cell, right? Previous function cannot be used in the overlapping parts of row group and column group. One workaround of this issue is use custom code to get the previous value.
    Public Shared previous as Integer
    Public Shared current as Integer
      Public Shared Function GetCurrent(Item as Integer) as Integer
         previous=current
         current=Item
         return current
      End Function
      Public Shared Function GetPrevious()
         return previous
      End Function
    Then you can use the expression below in the “Data” cell to get the previous value:
    =Code.GetCurrent(fields!Score.Value) & "-Previous-" & iif(Code.GetPrevious()=0,"",Code.GetPrevious())
    If you have any questions, please feel free to ask.
    Regards,
    Charlie Liao
    TechNet Community Support

  • How to use, Case function and Filter in Column Formula?

    Hello All,
    I am using case function and also would like to filter value to populate.
    Below is showing error :
    case
    when '@{Time}' = 'Year' then "Time"."Fiscal Year"
    when '@{Time}' = 'Quarter' then "Time"."Fiscal Quarter"
    when '@{Time}' = 'Month' then FILTER ("Time"."Fiscal Period" USING "Time"."Fiscal Period" NOT LIKE 'A%')
    else ifnull('@{Time}','Selection Failed') end
    Thanks, AK

    when '@{Time}' = 'Month' then FILTER ("Time"."Fiscal Period" USING "Time"."Fiscal Period" NOT LIKE 'A%')I dont think Filter this works here or any other data types except number.
    Try to use option Column's->Filter->Advanced->Convert this filter to SQL
    If helps mark

  • SQL LOADER: how to load CLOB column using stored function

    Hi,
    I am a newbie of sql loader. Everything seems to be fine until I hit a
    road block - the CLOB column type. I want to load data into the clob
    column using a stored function. I need to do some manipulation on the
    data before it gets saved to that column. But I got this error when I
    run the sql loader.
    SQL*Loader-309: No SQL string allowed as part of "DATA" field
    specification
    DATA is my CLOB type column.
    here is the content of the control file:
    LOAD DATA
    INFILE 'test.csv'
    BADFILE 'test.bad'
    DISCARDFILE 'test.dsc'
    REPLACE
    INTO TABLE test_table
    FIELDS TERMINATED BY ','
    OPTIONALLY ENCLOSED BY '"'
    TRAILING NULLCOLS
    codeid          BOUNDFILLER,
    reason          BOUNDFILLER,
    Checkstamp     "to_date(:CHECKSTAMP, 'mm/dd/yyyy')",
    "DATA"          "GetContent(:codeid, :reason)"
    All references are suggesting to use a file to load data on
    CLOB column but I want to use a function in which it generates
    the content to be saved into the column.
    Any help is greatly appreciated.
    Thanks,
    Baldwin
    MISICompany

    *** Duplicate Post ... Please Ignore ***

  • ORA-00932 while using nvl with trunc function

    What happens when trunc is executed on null?
    I am executing the following query:
    "select nvl(trunc(null),sysdate) from dual"
    and this throws "ORA-00932: inconsistent datatypes: expected NUMBER got DATE, error at Line:1 Column:23".
    Whereas "select nvl(null,sysdate) from dual" returns sysdate correctly.
    Also "select trunc(null) from dual" returns null only. So when the returned null is passed through nvl why am I getting exception?
    This is happening in ver 9.2.0.5.0 and 10.2.0.2.0
    There is another observation, which is an issue that we have found in our code, and while trying to fix that we saw the earlier observation.
    SELECT * FROM orgs, dual where
    trunc(SYSDATE) between trunc(orgs.effective_start_date) and nvl(trunc(orgs.effective_end_date),trunc(sysdate))
    Here effective start date and effective end date for orgs are null for all records.
    When we run this query on ver 9.2.0.5.0, this runs without any exception. But when we run this query on ver 10.2.0.2.0, we get the same exception, "ORA-00932: inconsistent datatypes: expected NUMBER got DATE, error at Line:2 Column:95".
    The join with dual is fake, in actual scenario we have join with other tables, but since we are able to replicate with dual, removed all other details to keep this simple.
    Now if we remove the join with dual, the query works fine in both the env.
    SELECT * FROM orgs where
    trunc(SYSDATE) between trunc(orgs.effective_start_date) and nvl(trunc(orgs.effective_end_date),trunc(sysdate))

    What happens when trunc is executed on null?
    I am executing the following query:
    "select nvl(trunc(null),sysdate) from dual"
    and this throws "ORA-00932: inconsistent datatypes:
    expected NUMBER got DATE, error at Line:1
    Column:23".
    Whereas "select nvl(null,sysdate) from dual" returns
    sysdate correctly.
    Also "select trunc(null) from dual" returns null
    only. So when the returned null is passed through nvl
    why am I getting exception?
    This is happening in ver 9.2.0.5.0 and 10.2.0.2.0The first parameter to NVL is determining the expected datatype of the returned column, with the trunc function defaulting that to NUMBER because it's parameter is NULL. The second parameter to NVL needs to match that datatype which it doesn't because it is a date.
    SQL> select nvl(trunc(sysdate), sysdate) as mydate from dual;
    MYDATE
    26/05/2006 00:00:00
    SQL> select nvl(trunc(null), sysdate) as mydate from dual;
    select nvl(trunc(null), sysdate) as mydate from dual
    ERROR at line 1:
    ORA-00932: inconsistent datatypes: expected NUMBER got DATE
    SQL> select nvl(trunc(123), sysdate) as mydate from dual;
    select nvl(trunc(123), sysdate) as mydate from dual
    ERROR at line 1:
    ORA-00932: inconsistent datatypes: expected NUMBER got DATE
    SQL>

Maybe you are looking for

  • GL Account in Fast change not working - is any Exit or BADI available?

    Hi All, In ME21N/ME22N, there is a Fast Change Icon at the item level after Copy Item Icon. When clicked on it, we can see the hidden fields in it which are present in the structure MEGUI_MASSCH_ALLOWED_FIELDS Now I want to add one more field which i

  • How to browse objects in different schemas

    If I connect to the database in one schema is there a way to browse objects in a different schema? For example, I connect as hr and I want to view the tables in the ord schema.

  • IMovie Issue after Mavericks upgrade

    I upgraded my iMac 2009 to Mavericks today. I updated all the user accounts for format changes to Mail, iPhoto and iMovie. What a pain. I don't recall this being an issue before (I was running Lion) but iMovie now only lets one user run iMovie at a t

  • [SOLVED] howto unzip multipart zipfiles?

    Hi all, I have a problem that is driving me crazy, I downloaded some app I need and its a multipart zip file, In windows I should just unzip the file regularly and all went good, whoever the unzip linux utility refuses to do so. I do have a virtual m

  • How do I find the UDID?

    There seems to be a security issue with iPads and iTunes that has to do with the UDID.  Does anyone know how to check to see if one's iTunes account is secure?  How does one find the UDID? And then how does one use it to check the security of one's A