Calculate business days in Oracle SQL(no functions or procedure)

The solution, finally: SELECT OrderNumber, InstallDate, CompleteDate, (TRUNC(CompleteDate) – TRUNC(InstallDate) ) +1 – ((((TRUNC(CompleteDate,’D’))-(TRUNC(InstallDate,’D’)))/7)*2) – (CASE WHEN TO_CHAR(InstallDate,’DY’,’nls_date_language=english’)=’SUN’ THEN 1 ELSE 0 END) – (CASE WHEN TO_CHAR(CompleteDate,’DY’,’nls_date_language=english’)=’SAT’ THEN 1 ELSE 0 END) as BusinessDays FROM Orders ORDER BY OrderNumber; Thanks for all your responses !

Auto Increment for Oracle

Create the table and the sequence SQL> create table staff ( 2 emp_id number primary key, 3 staff_name varchar2(100) 4 ); Table created. SQL> create sequence emp_id_seq; Sequence created. Now, you can create a trigger that uses the sequence to populate the primary key SQL> create trigger trg_emp_id 2 before insert on staff 3 for … Read more

Left Outer Join using + sign in Oracle 11g

TableA LEFT OUTER JOIN TableB is equivalent to TableB RIGHT OUTER JOIN Table A. In Oracle, (+) denotes the “optional” table in the JOIN. So in your first query, it’s a P LEFT OUTER JOIN S. In your second query, it’s S RIGHT OUTER JOIN P. They’re functionally equivalent. In the terminology, RIGHT or LEFT … Read more

ORA-12514 TNS:listener does not currently know of service requested in connect descriptor

I had this issue and the fix was to make sure in tnsnames.ora the SERVICE_NAME is a valid service name in your database. To find out valid service names, you can use the following query in oracle: select value from v$parameter where name=”service_names” Once I updated tnsnames.ora to: TEST = (DESCRIPTION = (ADDRESS_LIST = (ADDRESS … Read more