PL/SQL equivalent for networkdays function

Hi,
Is anyone aware of a PL/SQL equivalent for the Excel "networkdays" function, that returns the number of whole workdays between 2 dates?
Thanks!
Phil

To calculate the number of days between january 1st and today, use the following.
1* select trunc(sysdate) - trunc(to_date('01-jan-05')) from dual
SQL> /
TRUNC(SYSDATE)-TRUNC(TO_DATE('01-JAN-05'))
58

Similar Messages

  • T-SQL Equivalent For Group_Concat() Function

    Hello, I am looking for a way to do the MSSQL T-SQL equivalent of the MySQL aggregate function: group_concat().
    We are running SQL 2005 Express. Is there a pure T-SQL way to do this, or if not, a way to create a new custom aggregate function?
    EX:
    SELECT GROUP_CONCAT(FIRST_NAME) AS STUDENT_LIST FROM STUDENTS GROUP BY TEACHER
    OUTPUT:
    JOSH,JOEY,MARK,LINDA,PAM,BILL,MIKE,JUSTIN

    Can anyone help me with MS SQL equivalent code for below MySQL statement.
    select group_concat
    (Col1
    order
    by field(Col2,8,13,15,53,55,6,73,75,3,42,41,45,44))
    as FinalColumn from TestTable
    Any help is greatly appriciated... thanks in advance...

  • Invalid state in SQL query for a function that was created with no errors.

    SQL> CREATE OR REPLACE FUNCTION overlap(in_start1 IN TIMESTAMP, in_end1 IN TIMESTAMP, in_start2 IN TIMESTAMP, in_end2 IN TIMESTAMP) RETURN NUMBER
    2 IS
    3
    4 BEGIN
    5 IF (in_start1 BETWEEN in_start2 AND in_end2 OR in_end1 BETWEEN in_start2 AND in_end2 OR in_start2 BETWEEN in_start1 AND in_end1) THEN
    6 RETURN 0;
    7 ELSE
    8 RETURN 1;
    9 END IF;
    10 END;
    11 /
    Function created.
    SQL> show errors;
    No errors.
    SQL>
    SQL> SELECT * FROM tbl where overlaps(current_time,current_time+1,current_time-1,current_time+2) = 0;
    SELECT * FROM tbl where overlaps(current_time,current_time+1,current_time-1,current_time+2) = 0
    ERROR at line 1:
    ORA-06575: Package or function OVERLAPS is in an invalid state
    I do not understand why overlaps is returned as in invalid state in the query, when it was created with no errors earlier. Could anyone help me?

    Marius
    Looking at the logic you are trying to create it looks like you are looking for overlapping time periods.
    Consider two date/time ranges:
    Range 1 : T1 - T2
    Range 2 : T3 - T4
    Do they overlap?
    1) No: T1 < T4 (TRUE)  T2 > T3 (FALSE)
    T1 --- T2
               T3 --- T4
    2) Yes: T1 < T4 (TRUE)  T2 > T3 (TRUE)
    T1 ---------- T2
               T3 --- T4
    3) Yes: T1 < T4 (TRUE)  T2 > T3 (TRUE)
    T1 -------------------- T2
               T3 --- T4
    4) Yes: T1 < T4 (TRUE)  T2 > T3 (TRUE)
                   T1 ----- T2
               T3 --- T4
    5) Yes: T1 < T4 (TRUE)  T2 > T3 (TRUE)
               T1 --- T2
           T3 ------------ T4
    5) No: T1 < T4 (FALSE) T2 > T3 (TRUE)
                    T1 --- T2
           T3 --- T4Answer: Yes they overlap if:
    T1 < T4 AND T2 > T3
    So you can code the logic in your SQL as simply:
    SELECT *
    FROM tbl
    WHERE range1_start < range2_end
    AND    range_1_end > range2_startIf you go around implementing PL/SQL functions for simple logic that can be achieved in SQL alone then you cause context switching between the SQL and PL/SQL engines which degrades performance. Wherever possible stick to just SQL and only use PL/SQL if absolutely necessary.

  • SQL Query for all Function Name attached to Responsibility

    I have a requiremnet where in the data needs to be fetched giving all details of User Name, Responsibility Name, Function_user_name at responsibility level.
    For e.g when a user logs in ORacle application and gets in to a responsibility and uses short cut key (Cntrl + L), the application lists out all the form functions, i need those form funtion for all users at responsibility level.
    follwoing is the SQL i developed but its not listing the form function when we use (cntrl + L).
    SELECT fur.user_name, fur.description, fur.responsibility_name,
    mnu.user_function_name, mnu.function_name --, mnu.TYPE, mnu.PARAMETERS
    FROM (
    SELECT /*+ ordered use_nl(ffft) */
    DISTINCT fm.menu_id, ffft.user_function_name, fff.function_name,
    fff.TYPE, fff.PARAMETERS
    FROM (select distinct menu_id
    from apps.fnd_responsibility_tl frt,
    applsys.fnd_responsibility fr
    where 1=1
    and frt.responsibility_id = fr.responsibility_id
    and frt.application_id = fr.application_id
    and frt.responsibility_name = 'SLCHR Admin Asst' ) frm,
    apps.fnd_menus fm,
    apps.fnd_form_functions fff,
    apps.fnd_form_functions_tl ffft
    WHERE 1 = 1
    --AND fm.menu_id IN (1004979, 1009084)
    AND frm.menu_id = fm.menu_id
    AND fff.function_id = ffft.function_id
    AND fm.menu_id IN (SELECT me.menu_id
    FROM apps.fnd_menu_entries me
    START WITH me.function_id = fff.function_id
    CONNECT BY PRIOR me.menu_id = me.sub_menu_id)
    ) mnu,
    (SELECT fusr.user_name, fusr.description, frv.responsibility_name, frv.menu_id
    FROM apps.fnd_responsibility_vl frv,
    apps.fnd_user_resp_groups_direct frg,
    apps.fnd_user fusr
    WHERE 1 = 1
    --and   fusr.user_name = 'JLEWIS03'
    AND frv.responsibility_name = 'SLCHR Admin Asst'
    AND frv.end_date IS NULL
    AND fusr.user_id = frg.user_id
    AND fusr.end_date IS NULL
    AND frv.responsibility_id = frg.responsibility_id
    ) fur
    WHERE 1 = 1
    AND fur.menu_id = mnu.menu_id
    Please help

    Please see these docs.
    Checking Functions Associated with a User Menu or a Responsibility [ID 948512.1]
    HOW TO GENERATE MENU TREE FOR A MENU ATTACHED TO A RESPONSIBILITY IN ORACLE APPLICATIONS 11i ? [ID 312014.1]
    Thanks,
    Hussein

  • PL/SQL Equivalent for TAB in SQL

    What is the equivalent of a TAB in SQL to use with a REPLACE function?
    <CR><LF> = CHR(13)||CHAR(10))
    what is
    <TAB> = ???????
    Miller

    select ascii('tab') tab_val from dual ;I think we get the ascii value of 't'
    Which version you are using??

  • Help for decode function

    Hi all,
    I want to use decode function in RTF template.
    I know i can use if statement to deal with it ,but if the conditions are over 3, if statement is not good choice.
    Here is the if condition statement
    <?if:answer='Y'?>Yes<?end if?> <?if:answer='N'?>No<?end if?>
    how can i translate this if statement to use decode function
    I tried to use the statement as below, but it doesn't work.
    <?xdofx:decode(:answer,Y,'YES',N,'NO')?>
    using this statement i got empty in this field.
    I appreciate any responds, thanks in advance.
    appcat

    Hi,
    it should work,coz there is no xsl equivalent for this function that i have seen on blogs,
    the syntax that i have got it from other xmlp blogs, sounds like you put correct syntax, try to give multiple conditions to check the result
    <?xdofx:decode(’xxx’,’bbb’,’ccc’,’xxx’,
    ’ddd’)?>
    srinuk

  • Equivalent of to_date function in Ms SQL and using it in Evaluate function

    Hi,
    I am trying to find out a function in MS SQL which is equivalent to to_date function in oracle. Please find below the advanced filter i am trying to use in OBIEE.
    Evaluate('to_date(%1,%2)' as date ,SUBSTRING(TIMES.CALENDAR_MONTH_NAME FROM 1 FOR 3)||'-'||cast(TIMES.CALENDAR_YEAR as char(4)),'MON-YYYY')>=Evaluate('to_date(%1,%2)' as date,'@{pv_mth}'||'@{pv_yr}','MON-YYYY') and Evaluate('to_date(%1,%2)' as date ,SUBSTRING(TIMES.CALENDAR_MONTH_NAME FROM 1 FOR 3)||'-'||cast(TIMES.CALENDAR_YEAR as char(4)),'MON-YYYY') <=timestampadd(sql_tsi_month,4,Evaluate('to_date(%1,%2)' as date,'@{pv_mth}'||'@{pv_yr}','MON-YYYY'))
    The statement above works fines with oracle DB with to_date function. The same statement throws an error with MS SQL since to_date is not a built in function.
    With MS SQL I tried with CAST, not sure how to pass parameters %1 and %2.
    Please help me how to use Evaluate function and passing parameters along with to_date funtion in MS SQL.
    Regards!
    RR

    Hi,
    please refer to this thread for useful information on using to_char and to_date functions of oracle in MS SQL server:
    http://database.ittoolbox.com/groups/technical-functional/sql-server-l/how-to-write-to-to_char-and-to_date-sql-server-351831
    Hope this helps.
    Thanks,
    -Amith.

  • Equivalent of ValueList function in SQL

    Hi,
    Is there an equivalent of valueList function in SQL? Here's
    what I am trying to do:
    Suppose I have the following table:
    Name -- Color
    John -- Green
    John -- Red
    Mike -- White
    I want to do a query such that the colors are aggregated as a
    list. So the result would be:
    Name -- Color List
    John -- Green, Red
    Mike -- White
    The only way I could think of doing this is to loop through
    each name in the table and doing ValueList in each loop. Is there a
    better way?
    Thanks.
    Min

    > I want to do a query such that the colors are aggregated
    as a list.
    If it _must_ be done in sql, there are some database options.
    Such as the one mentioned above. There are also some interesting
    approaches using xml path and cross apply with MS SQL 2005. I do
    not know about other databases.
    http://databases.aspfaq.com/general/how-do-i-concatenate-strings-from-a-column-into-a-sing le-row.html
    Bear in mind there are some performance implications with all
    of the methods. For example, a udf would execute once for each
    name. So the more records, the greater the impact.
    Another possibility is to use cfoutput's group attribute to
    create a list for each name. Assuming that is feasible ..

  • Convert columns to row equivalent to stragg function in oracle sql

    Hi,
    Sorry i forgot my Oracle version :
    SQL> select * from v$version;
    BANNER
    Oracle Database 10g Enterprise Edition Release 10.2.0.3.0 - 64bi
    PL/SQL Release 10.2.0.3.0 - Production
    CORE    10.2.0.3.0      Production
    TNS for 64-bit Windows: Version 10.2.0.3.0 - Production
    NLSRTL Version 10.2.0.3.0 - ProductionI searched in google but i didn't found the solution.
    I looking for a function in discoverer equivalent to stragg sql function.
    Note : stragg function convert columns to rows.
    Thanks
    SELECT   deptno, stragg ('-' || ename)
        FROM emp_test
    GROUP BY deptno;
        DEPTNO STRAGG_STR                                                 
            10 -CLARK-KING-MILLER                                         
            20 -SMITH-FORD-ADAMS-SCOTT-JONES                              
            30 -ALLEN-BLAKE-MARTIN-TURNER-JAMES-WARD                      
    3 rows selected.Edited by: Salim Chelabi on 2010-01-29 08:32

    Hi again,
    *1- I created  my function in my schema.*
    CREATE OR REPLACE TYPE t_string_agg AS OBJECT
      g_string  VARCHAR2(32767),
      STATIC FUNCTION ODCIAggregateInitialize(sctx  IN OUT  t_string_agg)
        RETURN NUMBER,
      MEMBER FUNCTION ODCIAggregateIterate(self   IN OUT  t_string_agg,
                                           value  IN      VARCHAR2 )
         RETURN NUMBER,
      MEMBER FUNCTION ODCIAggregateTerminate(self         IN   t_string_agg,
                                             returnValue  OUT  VARCHAR2,
                                             flags        IN   NUMBER)
        RETURN NUMBER,
      MEMBER FUNCTION ODCIAggregateMerge(self  IN OUT  t_string_agg,
                                         ctx2  IN      t_string_agg)
        RETURN NUMBER
    SHOW ERRORS
    CREATE OR REPLACE TYPE BODY t_string_agg IS
      STATIC FUNCTION ODCIAggregateInitialize(sctx  IN OUT  t_string_agg)
        RETURN NUMBER IS
      BEGIN
        sctx := t_string_agg(NULL);
        RETURN ODCIConst.Success;
      END;
      MEMBER FUNCTION ODCIAggregateIterate(self   IN OUT  t_string_agg,
                                           value  IN      VARCHAR2 )
        RETURN NUMBER IS
      BEGIN
        SELF.g_string := self.g_string || ',' || value;
        RETURN ODCIConst.Success;
      END;
      MEMBER FUNCTION ODCIAggregateTerminate(self         IN   t_string_agg,
                                             returnValue  OUT  VARCHAR2,
                                             flags        IN   NUMBER)
        RETURN NUMBER IS
      BEGIN
        returnValue := RTRIM(LTRIM(SELF.g_string, ','), ',');
        RETURN ODCIConst.Success;
      END;
      MEMBER FUNCTION ODCIAggregateMerge(self  IN OUT  t_string_agg,
                                         ctx2  IN      t_string_agg)
        RETURN NUMBER IS
      BEGIN
        SELF.g_string := SELF.g_string || ',' || ctx2.g_string;
        RETURN ODCIConst.Success;
      END;
    END;
    SHOW ERRORS
    CREATE OR REPLACE FUNCTION string_agg (p_input VARCHAR2)
    RETURN VARCHAR2
    PARALLEL_ENABLE AGGREGATE USING t_string_agg;
    SHOW ERRORS
    *2- I ran my query in my schema with sqlplus.*
    SELECT deptno,ename,sal, string_agg(ename)over(partition by deptno) AS employees
    FROM   emp_test
    order by deptno;
        DEPTNO ENAME             SAL EMPLOYEES                                        
            10 CLARK            2450 CLARK,KING,MILLER                                
            10 KING             5000 CLARK,KING,MILLER                                
            10 MILLER           1300 CLARK,KING,MILLER                                
            20 JONES            2975 JONES,FORD,ADAMS,SMITH,SCOTT                     
            20 FORD             3000 JONES,FORD,ADAMS,SMITH,SCOTT                     
            20 ADAMS            1100 JONES,FORD,ADAMS,SMITH,SCOTT                     
            20 SMITH             800 JONES,FORD,ADAMS,SMITH,SCOTT                     
            20 SCOTT            3000 JONES,FORD,ADAMS,SMITH,SCOTT                     
            30 WARD             1250 WARD,TURNER,ALLEN,JAMES,BLAKE,MARTIN             
            30 TURNER           1500 WARD,TURNER,ALLEN,JAMES,BLAKE,MARTIN             
            30 ALLEN            1600 WARD,TURNER,ALLEN,JAMES,BLAKE,MARTIN             
            30 JAMES             950 WARD,TURNER,ALLEN,JAMES,BLAKE,MARTIN             
            30 BLAKE            2850 WARD,TURNER,ALLEN,JAMES,BLAKE,MARTIN             
            30 MARTIN           1250 WARD,TURNER,ALLEN,JAMES,BLAKE,MARTIN             
    14 rows selected.
    *3- I import this function in discoverer administration*
    4- My problem :When i use the function string_agg(ename)over(partition by deptno) in discover deskto i got the error you can't use over in this place.
    Any ideas.
    Thank in advance.
    Regards Salim.

  • To find last updated date in sql developer for a procedure or a function

    hi
    how to to find last updated date in sql developer for a procedure or a function.
    i m using sql developer version in 1.2

    I think you are in the wrong forum...
    Anyway you can try
    select * from
    all_objects o
    where o.object_type in ('FUNCTION','PROCEDURE');
    you have there the created date, last DDL and timestamp

  • Sql queries for retrieving setups data for functional modules

    Hi,
    Can anyone give me the sql queries for retrieving setups data for functional modules (GL, AP, AR, FA, and CM) from Database.

    Hi,
    Can anyone give me the sql queries for retrieving setups data for functional modules (GL, AP, AR, FA, and CM) from Database.

  • SQL Servers's SCOPE_IDENTITY() function in Oracle???

    There is a query in SQL SERVER in my project SELECT SCOPE_IDENTITY()
    I would need to write equivalent query in Oracle.
    Could you pelase let me know what is the substitue for the function SCOPE_IDENTITY() in Oracle?

    This is how I am returing IDENTITY value from my c function whilst successfully inserted the data.
         sprintf(szSQLStatement , "INSERT INTO tabel1 VALUES ( '%s', '%s', '%s' ) ", Rec->field1, Rec->field2, Rec->field3 );     
         sprintf(szSelectString , "SELECT SCOPE_IDENTITY() ");
         retcode = SQLAllocStmt(hdbc, &hstmt); // Statement handle
         if (retcode == SQL_SUCCESS) {
              retcode = SQLExecDirect(hstmt, szSQLStatement, strlen(szSQLStatement));
              if (retcode == SQL_SUCCESS) {
                   retcode = SQLExecDirect(hstmt, szSelectString, strlen(szSelectString));
                   if (retcode == SQL_SUCCESS) {
                        retcode = SQLFetch(hstmt);                    
                        if (retcode == SQL_SUCCESS || retcode == SQL_SUCCESS_WITH_INFO) {
                             SQLGetData(hstmt, 1, SQL_C_CHAR, szRetData, 20, &cbLen);
                             if (cbLen != SQL_NULL_DATA)
                             *nScopeID = atoi(szRetData);
                   retcode = 0;
              SQLFreeStmt(&hstmt, SQL_DROP);
         return retcode;

  • SQL equivalent of if-statement

    What would be really useful would be if I could do an SQL equivalent of an if-statement. I'm just making the following up to show what I mean:
    SELECT CASE
              WHEN(det.user_entity_name = 'PO Header')
                 THEN (SELECT pha.segment1
                         FROM po.po_headers_all pha
                        WHERE pha.po_header_id = ad.pk1_value)
              WHEN(det.user_entity_name = 'PO Line')
                 THEN (SELECT pha.segment1
                         FROM po.po_headers_all pha
                            , po.po_lines_all pla
                        WHERE pha.po_header_id = pla.po_header_id
                          AND pla.po_line_id = ad.pk1_value)
              ELSE 'UNDEFINED'
           END doc_num
         , ad.seq_num
         , fu.description created_by
         , dt.description
         , det.user_entity_name
         , ad.creation_date
         , ad.entity_name
         , ad.pk1_value
         if dat.user_name = 'Short Text' then
         dst.short_text
         elseif dat.user_name = 'Long Text' then
         dlt.long_text
         end if
      FROM applsys.fnd_document_datatypes dat
         , applsys.fnd_document_entities_tl det
         , applsys.fnd_documents_tl dt
         , applsys.fnd_documents d
         , applsys.fnd_document_categories_tl dct
         , applsys.fnd_attached_documents ad
         if dat.user_name = 'Short Text' then
    , applsys.fnd_documents_short_text dst
         elseif dat.user_name = 'Long Text' then
         , applsys.fnd_documents_long_text dlt
         end if            
         , applsys.fnd_user fu
    WHERE d.document_id = ad.document_id
       AND dt.document_id = d.document_id
       AND dct.category_id = d.category_id
       AND d.datatype_id = dat.datatype_id
       AND ad.entity_name = det.data_object_code
         if dat.user_name = 'Short Text' then
    AND dt.media_id = dst.media_id(+)
         elseif dat.user_name = 'Long Text' then
    AND dt.media_id = dlt.media_id(+)
         end if  
       AND ad.created_by = fu.user_id
       AND d.creation_date > '01-OCT-2007'
         if dat.user_name = 'Short Text' then
    AND dat.user_name = 'Short Text'
         elseif dat.user_name = 'Long Text' then
    AND dat.user_name = 'Long Text'
         end if     
       AND dct.user_name = 'To Supplier';Is that possible, or am I just talking a load of nonsense?
    Thanks

    How to do IF in SQL:
    1) CASE
    2) DECODE
    3) UNION, UNION ALL, MINUS, INTERSECT
    4) AND + OR + ()
    5) stored functions
    6) ...
    which is best just depends on the situation. For your example I would use decode in the select clause and some UNION ALL for the from/where clauses.

  • "DatePart" Equivalent for a calculated list column

    Hello All,
    I need to break out dates from a calendar field into separate columns of month and year. In SQL I would just use DatePart, but I can't find a similar function for SP 2010 calculated columns. Is there a DatePart equivalent for calculated columns using just
    the web interface?
    Also, does anyone know where is the list of functions for calculated columns?
    Thanks in advance for the support.
    Alcide

    Hi Alcide,
    you should be able to do something like =Year([Date column]) for your Year column and =Month([Date column])for your month column
    here is a reference of calculated field functions from Microsoft.
    http://msdn.microsoft.com/en-us/library/bb862071.aspx
    Please let me know if this helps,
    Alex

  • SQL Expression in decode function or case statement?

    Can I put SQL expressions in decode function or case statement?
    For example,
    select le.profile, decode( select count(1) from profile_data where NAME= 'XXXX_AFTER' and object_id = le.profile, 0, 'N', 'Y')
    from element le;
    or
    select le.profile, case WHEN ( select count(1) from profile_data where NAME= 'XXXX_AFTER' and object_id = le.profile) = 0 THEN 'N'
    ELSE 'Y'
    from element le;
    None of the above work.
    Can anyone tell me how to make it work?
    Is there any workaround?
    Thanks,
    J

    You simply needed and END to your CASE statement;
    SQL> with profile_data as (
       select 'XXXX_AFTER' name, 1 object_id from dual),
         element as (
       select 1 profile from dual union all
       select 2 from dual)
    select le.profile,
       case WHEN ( select count(1) from profile_data where NAME= 'XXXX_AFTER' and object_id = le.profile) = 0
       THEN 'N'
       ELSE 'Y'
       END new_col
    from element le
       PROFILE N
             1 Y
             2 N

Maybe you are looking for

  • Firewall Support of Discoverer 4i

    We have been trying to set up dial-up access to Oracle Discoverer 4i. When our Firewall Administrator opened access to all ports it worked perfectly and very fast but obviously such a configuration is far from ideal. Our Administrator noted that when

  • IC Winclient

    Hi, Crm gurus i am working on crm 4.0 IC win client profile is assigned to organizational unit and position level in the organizational structure. But assignment to user level is not possible. why? points will be reward thanks [email protected]

  • Re: calling charges by country

    The website is a joke. I simply want to know what the cost per minute is on pay as you go, for calls from Spain to a UK landline. All I keep on getting is the rates page which does not work. I am going round and round in circles. How hard is it to fi

  • Installing IAS on a P$

    I'm trying to IAS on a Pentium 4 with Windows 2000?. I know that iPlanet does not support W2K but we have it running on P3s now in W2K when we ignore the warning. The only difference is the chip. On the P4 the server will not load and I get the follo

  • 5000 frame project renders fast at first... then... slooooows.... down.

    Maybe you guys can help me with this.  I have a single ProRes 4444 Quicktime movie in a comp. No effects, no scaling. Just re-rendering the Quicktime to another ProRes 422 Quicktime.  It's about 5000 frames @ 1600x1200. So it starts of blazingly fast