Creating a function of hours

I am new to oracle and I need to create a function that will take two datestamp and then tell me how many hours are between these two dates.
Opening hours are from 06:00 to 06:00 p.m., Monday to Friday.

For example: if my startdate is 20/07/2010-08:00 and at the end we day 2010-07-02 21:00. Total working hours will be 10 hours no 13.
Another scenario:
start date: 20/07/2010 03:00 and end 20/07/2010 06:01 hour. Total work hours are 1 min.

I have serious difficulty with that.

Thank you
Amir

Hi, Amir,

user10356209 wrote:
Frank,
THiiS is almost perfect. I see that the function is only the dates not accpeting datestamp.
I call the function with these parameters
Select Business_Hours double ((21 juillet 10 07.58.22 AM ', 21 juillet 10 07.58.22 AM'))

and I get the following error
SQL error: ORA-01830: date format picture ends before converting all of the input string
01830 00000 - "date format picture ends before converting all of the input string.

Any thoughts?

If the function expecects DATEs for the arguments, it does not pass strings.
One thing you can do is TO_DATE allows to convert the strings to DATEs:

Select  Business_Hours ( TO_DATE ( '21-JUL-10 07.58.22 AM'
                             , 'DD-MON-RR HH.MI.SS AM'
                     )
                 , TO_DATE ( '21-JUL-10 07.58.22 AM'
                             , 'DD-MON-RR HH.MI.SS AM'
                     )
from    dual;

If you are still calling the function with strings as arguments, no DATEs, and if the strings are always in the same format, then you could call TO_DATE function, or write a separate function which takes the strings as arguments:

CREATE OR REPLACE FUNCTION     business_hours_s
(   in_start_datestamp     IN  VARCHAR2
,   in_end_datestamp     IN  VARCHAR2
)
RETURN  NUMBER
DETERMINISTIC
IS
BEGIN
     RETURN  business_hours ( TO_DATE ( in_start_datestamp
                                   , 'DD-MON-RR HH.MI.SS AM'
                           )
                      ,  TO_DATE ( in_end_datestamp
                                   , 'DD-MON-RR HH.MI.SS AM'
                           )
                      );
END     business_hours_s
;

It's literally the entire function; just a RETURN statement.
Leave the original function exactly as it is, with the arguments to DATE.

Tags: Database

Similar Questions

  • How to create a function for the function date two

    Hai All

    How can we create a function for the date function two and to return the number of hours between two dates

    For example

    1 January 2010 0815' - '01-jan-2010 1715' and I need to calculate the time between two dates

    How can I create a procedure

    Thanks I advance

    Srikkanth.M

    What have you tried?

    Here is an example (untested):

    CREATE OR REPLACE FUNCTION RETURN_HOURS
    (
            pDateStart      IN DATE
    ,       pDateEnd        IN DATE
    )
    RETURN NUMBER
    DETERMINISTIC
    AS
    BEGIN
            RETURN (pDateEnd - pDateStart) * 24;
    END RETURN_HOURS;
    
  • How to create a function

    Hai All

    My table structure is

    EMPCODE VARCHAR2 (25)
    EMPNAME VARCHAR2 (25)
    BAR CODE VARCHAR2 (25)
    VARCHAR2 (25) RESPONDENT
    OUTTIME VARCHAR2 (25)
    DATE OF ATTEND_DATE
    UNITID VARCHAR2 (25)
    WTIME VARCHAR2 (25)
    VARCHAR2 (25) END
    E TIME VARCHAR2 (25)


    Here, I got the inime, outtime and attend_date and bar code, emp_code iam while generating my table


    Now I need to know the hours between respondent and outtime the time to work

    I got this by sql query

    Update dail_att set wtime = extract (hour of (to_date (outtime,' HH24:MI')-to_date(intime,'HH24MI')) to the second day);))


    And I need to get the Extratime IE greater than workinghours 0830
    so I created a simple proc


    Set serveroutput on
    declare
    w_time varchar2 (25);
    Start
    If w_time > 0830 then
    Update dail_att set =(wtime-0830) etime where barcode = 0000000001949215 and attend_date = 9 November 09 ';
    end if;
    end;

    How can I include both it and create a function

    Thank you for giving a good solution

    Concerning

    Srikkanth.M

    What keeps you write 2 updates in a block?

    Set serveroutput on
    declare
    w_time varchar2 (25);
    Start

    Update dail_att set wtime = extract (hour of (to_date (outtime,' HH24:MI')-to_date(intime,'HH24MI')) to the second day);))

    I'm in (select * from dail_att)
    LOOP
    If i.w_time > 0830 then
    Update dail_att set =(i.wtime-0830) etime where barcode = i.barcode and attend_date is i.attend_date;.
    end if;
    END LOOP;

    end;

  • How to create a function to calculate the calendar

    Oracle Forms 6i

    Hai

    I'm generating a daily presence that is stored in the database with the fields

    Empcode, attend_date, intimate, outtime, extratime, deptcode, unitid and some other things

    I need to create a function by taking these fields of the table unitid, empcode, intimate, outtime, attend_date, deptcode and return total hours he worked, and more than 8 means it will add in extra time.

    If it is possible to give the run of the date value to which to this day, you must calculate.

    Thanks in advance

    Srikkanth.Ml

    Srikkanth,
    Depending on how you stated your RESPONDENT and OUTTIME, columns this should quite simply be a calculation. For example, if you have declared these columns as DATE columns, the following calculation should work:

    SELECT NVL(OUTTIME,SYSDATE) - INTIME AS hours_worked
    FROM DAILY_ATTENDANCE
    WHERE EMPCODE = "Emp Code of the employee you are evaluating";
    

    Once you have the HOURS_WORKED, you can check if the amount is greater than 8 (or whatever is the approved duration of working hours of the employee's) to determine if he or she worked longer than their approved shift back the extra time, and the user has worked or NULL or zero if they have not exceeded their shift.

    If you have set up the columns of time as something other than the DATE or DATETIME, you will need to convert the values in input/OUTPUT at a DATE so that you can use the functionality of calculation date default Oracle or you need to build your own process of calculation of the WORK_HOURS based on how you store the RESPONDENT and OUTTIME values.

    I hope this helps.
    Craig...

  • Error Photoshop CC while opening jpeg files created less than 24 hours ago "could not complete your request because it is not the right kind of document.

    I am under photoshop cc and a sudden am this message cannot open jpg files. And so, I used photoshop to create less than 24 hours. Any suggestions?

    Thanks for sharing files.

    Looks very good load on my end.

    Suggest you to reinstall Camera Raw from this link and then check: https://helpx.adobe.com/x-productkb/multi/camera-raw-plug-in-installer.html

  • reporting invalid-ORA-00900 error while creating a function

    Hello

    can someone guide me to what is doing the worng...

    error! sql statement not valid 00900 - ORA-.

    your help is greatly appreciated.

    FUNCTION test_irc (num in NUMBERS, varsql IN VARCHAR2)
    RETURNS the NUMBER IS varSTMT VARCHAR2 (32767): = NULL;

    type of v_key_type temp2_irc.key_type %;
    v_key_type1 temp2_irc.key_type1%type;


    BEGIN
    INSERT INTO temp2_irc (key_type, key_type1)
    VALUES(v_key_type,v_key_type1);

    RETURN 1;

    EXCEPTION WHEN OTHERS THEN
    dbms_output.put_line ('down in test');
    dbms_output.put_line (' SQL error: ' |) SUBSTR (SQLERRM, 1, 1000));
    RETURNS - 1;
    END test_irc;

    temp2_irc / / desc:

    KEY_TYPE varchar2 (1 byte),

    key_type1 varchar2 (1 byte)

    If you create a database function, you must include the keyword of CREATE or REPLACE

    for example

    Create the FUNCTION replace or test_irc (num in NUMBERS,
    varsql IN VARCHAR2) RETURN NUMBER IS
    varSTMT VARCHAR2 (32767): = NULL;
    v_key_type temp2_irc.key_type%type;
    v_key_type1 temp2_irc.key_type1%type;
    BEGIN
    INSERT INTO temp2_irc (key_type, key_type1)
    VALUES(v_key_type,v_key_type1);

    RETURN 1;
    EXCEPTION WHEN OTHERS THEN
    dbms_output.put_line ('down in test');
    dbms_output.put_line (' SQL error: ' |) SUBSTR (SQLERRM, 1, 1000));
    RETURNS - 1;
    END test_irc;

  • can I use create valude function for MSSql scalar and table.

    Hello

    (1) can I use create scalar function for MSSql and function table?
    (2) is there how many type of function defined by the user in oracle 11 g express?
    (3) and I can reture 'type' any form user defined function?


    Attract sincerely

    944768 wrote:

    the answer lies in a few cases only,

    The response illustrates the basic concept of how customers need to use cursors created using PL/SQL as a layer of abstraction - SQL and this concepts adapts to ALL cases where the customer wants to Oracle via PL/SQL cursor.

    a case is,
    If my function returns only a single value, then I can use oracle 'create function' with the return type as types predefined as a whole, varchar2 etc?
    with regard to performance.

    With regard to this performance problem? And why now suddenly change the question to want to use a function to return data type number or string? How does this relate to PL/SQL to return a cursor now?

    A function can return scalar values, not scalar. A function may return atomic values (such as a unique number, or a non-scalar list of numbers). A function can return a complex data structure consisting of scalar values, not scalar.

    However, in PL/SQL function must NOT be used to read the lines of the database to cache lines in a memory of the server PL/SQL (PGA), then back to the client.

    He does not. It does not fit. It is too bloody dangerous to the overall health of the server as such code plays silly blighters with very expensive server memory.

    A PL/SQL function can also be used as guideline, returning data via expensive PGA, but via the SQL engine instead and using its slider interface (which allows output data to be "gradual" and not to return all data with a single copy of croustilleur mass of the call stack) directly. IT IS, HOWEVER, AN EXCEPTION. There is very rarely the need to make the functions PL/SQL pipeline table - and is often victims of abuse and bad demonstrated with examples of absurd code here.

  • I am trying to create a function that would be on the table type returns.

    Gurus,

    I am trying to create a function that returns a table nested with 3
    columns in a table as a guy.

    my query is like

    Select col1, col2, col3 from table_1;

    I am a bit newbie in Oracle and have never used collections.
    Can you please guide?

    >
    I am a bit newbie in Oracle and have never used collections.
    >
    Then you should start with the documentation
    http://docs.Oracle.com/CD/B28359_01/AppDev.111/b28370/TOC.htm

    Chapter 5 is all about collections using PL/SQL and examples
    >
    I am trying to create a function that returns a table nested with 3
    columns in a table as a guy.
    >
    This isn't enough of a description to know what you're trying to do, or how you plan to use the service. The query you provided is completely irrelevant to the question you are asking.

    You ask about functions in pipeline? Here is an example of this

    -- type to match emp record
    create or replace type emp_scalar_type as object
      (EMPNO NUMBER(4) ,
       ENAME VARCHAR2(10),
       JOB VARCHAR2(9),
       MGR NUMBER(4),
       HIREDATE DATE,
       SAL NUMBER(7, 2),
       COMM NUMBER(7, 2),
       DEPTNO NUMBER(2)
      )
      /
    
    -- table of emp records
    create or replace type emp_table_type as table of emp_scalar_type
      /
    
    -- pipelined function 
    
    create or replace function get_emp( p_deptno in number )
      return emp_table_type
      PIPELINED
      as
       TYPE EmpCurTyp IS REF CURSOR RETURN emp%ROWTYPE;
        emp_cv EmpCurTyp;
        l_rec  emp%rowtype;
      begin
        open emp_cv for select * from emp where deptno = p_deptno;
        loop
          fetch emp_cv into l_rec;
          exit when (emp_cv%notfound);
          pipe row( emp_scalar_type( l_rec.empno, LOWER(l_rec.ename),
              l_rec.job, l_rec.mgr, l_rec.hiredate, l_rec.sal, l_rec.comm, l_rec.deptno ) );
        end loop;
        return;
      end;
      /
    
    select * from table(get_emp(20))
    
  • I want to create the function for the function create for ODD or EVEN (NUMBER)

    I want to create the function for the function create for ODD or EVEN (NUMBER) also
    If number is odd, multiply by 5
    If there is an even number, multiply it by 10;

    Not tested,

    create or replace function fnc_env_odd(p_number in number)
    return number as
    begin
     if p_number>0  -- Remove if you want to consider negative numbers also
       if mod(p_number,2)=0 --Means even
          return p_number*10;
       else                 --Means odd
          return p_number*5
       end if;
     end if;
    end;
    /
    

    G.

  • Instance create the function

    Jyn

    I need some help with a game that I do. I have a list of instances, and I want to make a function that will create another symbol, similar to that was just clicked. The problem is that I don't know how to create the new instance... In my library, they are like 'next' link + name of the instance. Thank you for your help ^^,

    square_mc.addEventListener (MouseEvent.MOUSE_CLICK, Create);

    circle_mc.addEventListener (MouseEvent.MOUSE_CLICK, Create);

    ...

    triangle_mc.addEventListener (MouseEvent.MOUSE_CLICK, Create);

    function Create(event:MouseEvent):void

    {

    var name: String = "next" + event.target.name;

    var temp: Name = Name();

    addChild (temp);

    lines of code

    removeChild (temp);

    }

    Here's the right way to dynamically call an instance of the current class.

    var ClassRef: Class = Class (getDefinitionByName ("className");
    var classInstance: * = new ClassRef();
    addChild (classInstance);

    In your case, 'className' would be your "next" + event.target.name;

    and you can use event.currentTarget.name to be safer.  If your objects contain other objects in their midst, 'target' can point to them instead.  "currentTarget" will always point to the object with the listener who are entrusted to him.

  • Create the function of responsibility which would pass parameters to 3rd party app

    Hello all,.

    My organization uses Oracle HRMS but no payroll. We try to convert them into electronic heels and have developed a 3rd party app, but we do not want users to have to use a separate password for our instance of EBS. Is it possible to create a function to attach to the responsibility of the employee self-service that will launch the 3 web part app and validate the information as user_id to spend?

    Thanks in advance!
    Kristopher

    Hello

    You can use pageContext.putSessionValueDirect () API to do this, as this API set parameters directly in the HTTP session as

    pageContext.putSessionValueDirect ("Parameter1", value1);
    pageContext.putSessionValueDirect ("Parameter2", value2);
    pageContext.setForceForwardURL ('Page URL',
    NULL,
    OAWebBeanConstants.KEEP_MENU_CONTEXT,
    NULL, null, true,
    OAWebBeanConstants.ADD_BREAD_CRUMB_YES,
    OAWebBeanConstants.IGNORE_MESSAGES);
    }

    It could be useful!

    Ajay

  • Creating a function and passing the value of the query

    I have what I thought, it was a pretty easy to resolve the situation: I want to concatenate two fields of the query, if the 2nd is not empty.

    I created a function:

    < name cfargument = "q1" value = "#query.q1 #" / > "
    < name cfargument = "q1a' value =' #query.q1a #" / > "

    < CFSET variables.myPunct = ":" > "
    < cfset variables. ResultVar = "" >

    < cfif QNE Trim (arguments.q1) "" > "".
    < cfset variables. ResultVar =' #arguments.q1 # ">"
    < / cfif >

    < cfif QNE Trim (arguments.q1a) "" > "".
    < cfif variable. ResultVar NEQ "" > "".
    < cfset variables. ResultVar ='#variables. ResultVar & variables.myPunct # ">"
    < / cfif >
    < cfset variables. ResultVar ='#variables. ResultVar & arguments.q1a # ">"
    < / cfif >
    < variable cfreturn. ResultVar >

    It's basically just the example they provide in online education, with the names have been changed.

    In the strip of the details of my report, I have an expression builder containing field: report.mytestfunction)

    When I run the present, I get: Q1 element is not defined in the ARGUMENTS.

    I tried this ninety different ways (literally). It seems very clear to me that the query.q1 (Incidentally, none of the results of the query) are NOT passed to the function. I tried to make the expression: report.mytestfunction (query.q1). I tried to create an input parameter.

    The documentation on this is ridiculously limited, given that the ability to implement conditional logic is entirely dependent on the 'function', I can say. I can in no way to get the function of interface with the query results. If the value fixed values in the service, rather than trying to use query variables, it shows very well.

    Any ideas?

    Have you tried to remove the attribute "value" of your cfargument tag? The way I see it, you should have:


    ... rest of function...

    And then you have to call it with: report.mytestfunction (query.q1, query.q1a)

  • Creating a function (to check windowlist)

    I want to create a function (or Manager) that once called will check to see if the popups are (by checking windowList). If Yes, I want to see if each person is set to invisible (which means that they have closed the popup window) and got it close and forget the window.

    Now, when I create any function at all... to say:

    on testFunction
    back track (_player.windowList)
    end

    and place it in the first picture... and try to use it by placing it in a button:

    on mouseUp
    testFunction
    end

    He told me that the Manager does not exist. What I am doing wrong?

    Your personal Manager is expected to go into a film script, not a frame script.

  • How can I create a function using variables TestStand and call from Meadow step Expression?

    In one sequence, I have dozens of prior Expressions, which are almost the same thing, like this...

    Locals.tagID = (Parameters.singlePhaseEnabled? ('L': "D") & Str (Locals.phase) & "006".

    .. and the only thing different is this three-digit string in the end ("006" may vary). How can I write a function that I can call from Meadow step Expression then it should look like this? ...

    Locals.tagID = MyNewFunction("006")

    You can not write custom expressions for commands.

    That being said, there are two options:

    • Create a sous-suite with a single step. Use a setting of the sequence as "function parameter.

    • Create a step type custom including a lower level module that implements the function. Add a step edit to allow the user to the steptype graciously change the setting.

    • Store the variable setting in a local global variable / file and change the value in each step. This will, at least, keep the same 'function' for each step.

    Norbert

  • 'HRMS Create Document' function errors

    Hello

    I created a web ADI to download the data of the DIS.

    The responsibility for the integration of Office I can create and use the document to download the data and its success.

    Now I want to assign the document to create the end user if I include the "HRMS create a Document" function in the menu of the responsibility. The function is displayed on the screen, but when I click it, it says "web page not found."

    Also, I tried to associate the custom function by running the Integrator "HR ADI seeded Integrator Associations of shape functions. He has successfully completed. I added the custom liability function, but it is not there. I saw the definition of function, its almost empty. When I updated the definition with some dummy URLs, it seems.

    How can I give access to the document create for just this Integrator for the end user?

    Abdul Wahid

    Hi all

    Solved. In the call of html, instead of "oracle.apps.bne.webui.BneApplicationService", only "BneApplicationService" should be placed.

    Abdul Wahid

Maybe you are looking for