How to find the first Sunday and the second Saturday of each month
Hi all
How to find the first Sunday and the second Saturday of each month
Thank you
Oracle Database 11 g Enterprise Edition Release 11.1.0.7.0 - 64 bit Production
994122 wrote:
Hello
I need to pass the months parameter how to do this? like Jan, Feb etc... (one of those)
Do you have a procedure?
Should you output only for the months you passed in the parameter?
The easiest way is to set the parameter as date. When you go such as p_date as DATE ' 2014-10-01', then you can
PROCEDURE two_dates)
p_date IN DATE
p_first_sunday DATE
p_second_saturday DATE
)
IS
BEGIN
p_first_sunday: = NEXT_DAY (TRUNC (p_date, 'MM') - 1, TO_CHAR (DATE ' 2014-10-12', 'DAY'));
p_second_saturday: = NEXT_DAY (TRUNC (p_date, 'MM') - 1, TO_CHAR (DATE ' 2014-10-11', 'DAY')) + 7;
END two_dates;
Or you describe what you need.
Tags: Database
Similar Questions
-
How to get the second Monday of each month in a given date range?
In Oracle forms, how to get the second Monday of each month in a given date range?
I tried below using the query WITH the Clause, but it seems that WITH Clause does not work in Oracle forms. So is there another way to do this in Oracle forms?
WITH month_range AS
(
SELECT TO_DATE ('Dec 2013', 'Mon YYYY') AS first_month
, TO_DATE ('Mar 2014', 'Mon YYYY') AS last_month
OF the double
)
SELECT NEXT_DAY (6 + ADD_MONTHS (first_month
, LEVEL - 1
)
, 'MONDAY '.
) AS second_monday
OF month_range
CONNECTION OF LEVEL < = 1 + MONTHS_BETWEEN (last_month, first_month)
;
Thanks in advance.
Good fishing, when the first day of the month is Thursday... So I changed the query accordingly... Try the below
SELECT CASE WHEN TO_CHAR (ADD_MONTHS (TRUNC(startdate,'MM'),(LEVEL-1)), 'DY') = 'game '.
THEN NEXT_DAY (ADD_MONTHS (TRUNC(startdate,'MM'),(LEVEL-1)), 'THU')
Of OTHER NEXT_DAY (ADD_MONTHS (TRUNC(startdate,'MM'),(LEVEL-1)), 'Game') + 7
END AS second_day
FROM (SELECT SYSDATE startdate,
SYSDATE + 300 enddate
THE DOUBLE)
CONNECT BY LEVEL<=>=>
-
To find the third Saturday of a month
Hi all
Y at - it a simple way to find the third Saturday of each month
other than two queries below.
< CODE >
-The first code (No nested query)
SELECT MAX (DECODE (LENGTH (TO_CHAR (LEVEL)), 1))
, TO_DATE (TO_CHAR (SYSDATE, 'YYYYMM') |) '0' || TO_CHAR (LEVEL), 'YYYYMMDD')
, TO_DATE (TO_CHAR (SYSDATE, 'YYYYMM') |) TO_CHAR (LEVEL), 'YYYYMMDD'))) THIRD_SAT
OF THE DOUBLE
WHERE DECODE (LENGTH (TO_CHAR (LEVEL)), 1).
, TO_CHAR (TO_DATE (TO_CHAR (SYSDATE, 'YYYYMM') |)) '0' || TO_CHAR (LEVEL), 'YYYYMMDD'), "DY")
, TO_CHAR (TO_DATE (TO_CHAR (SYSDATE, 'YYYYMM') |)) TO_CHAR (LEVEL), 'YYYYMMDD'), "DY")
) = 'SAT '.
CONNECT BY LEVEL < 22
--deuxieme code (a nested query)
MAX SELECT THIRD_SAT (ALL_DATES)
OF (MAX SELECTION (DECODE (LENGTH (TO_CHAR (LEVEL)), 1)))
, TO_DATE (TO_CHAR (SYSDATE, 'YYYYMM') |) '0' || TO_CHAR (LEVEL), 'YYYYMMDD')
, TO_DATE (TO_CHAR (SYSDATE, 'YYYYMM') |) TO_CHAR (LEVEL), 'YYYYMMDD'))) ALL_DATES
OF THE DOUBLE
CONNECT BY LEVEL < 22
)
WHERE TO_CHAR (ALL_DATES, 'DY') = 'SAT '.
< code >
Thank you and best regards,
CDPRASADHello
Tubby wrote:
ME_XE?select next_day(trunc(sysdate, 'MM'), 'SATURDAY') + 14 from dual; NEXT_DAY(TRUNC(SYSDA -------------------- 21-AUG-2010 00 00:00 1 row selected. Elapsed: 00:00:00.00
Be careful! If the month happens to start Saturday, which returns the 4th Saturday, not the 3rd:
select next_day ( trunc ( DATE '2010-05-15' , 'MM' ) , 'SATURDAY' ) + 14 from dual; NEXT_DAY( --------- 22-MAY-10
That's because NEXT_DAY always returns a DATE after (not the same as) its 1st argument.
Do this instead:select next_day ( trunc ( DATE '2010-05-15' , 'MM' ) + 13 , 'SATURDAY' ) AS third_sat from dual; THIRD_SAT --------- 15-MAY-10
or, if you need something that is independent of the NLS:
select next_day ( trunc ( SYSDATE , 'MM' ) + 13 , TO_CHAR ( DATE '2010-07-31' -- You can use any Saturday here , 'Day' ) ) AS third_sat from dual; THIRD_SAT --------- 21-AUG-10
-
How to find the child level for each table in a relational model?
Earthlings,
I need your help, and I know that, "Yes, we can change." Change this thread to a question answered.
So: How to find the child level for each table in a relational model?
I have a database of relacional (9.2), all right?
Tips:. O /* This is a child who makes N references to each of the follow N parent tables (here: three), and so on. */ /↑\ Fks O"O O" <-- level 2 for first table (circle) /↑\ Fks "o"o"o" <-- level 1 for middle table (circle) ↑ Fk "º"
-Each circle represents a table;
-Red no tables have foreign key
-the picture on the front line of tree, for example, a level 3, but when 3 becomes N? How is N? That is the question.
I started to think about the following:
First of all, I need to know how to take the kids:
Thought...select distinct child.table_name child from all_cons_columns father join all_cons_columns child using (owner, position) join (select child.owner, child.constraint_name fk, child.table_name child, child.r_constraint_name pk, father.table_name father from all_constraints father, all_constraints child where child.r_owner = father.owner and child.r_constraint_name = father.constraint_name and father.constraint_type in ('P', 'U') and child.constraint_type = 'R' and child.owner = 'OWNER') aux using (owner) where child.constraint_name = aux.fk and child.table_name = aux.child and father.constraint_name = aux.pk and father.table_name = aux.father;
We will share!
Thanks in advance,
Philips
Published by: BluShadow on April 1st, 2011 15:08
formatting of code and hierarchy for readbilityHave you looked to see if there is a cycle in the graph of dependence? Is there a table that has a foreign key to B and B has a back of A foreign key?
SQL> create table my_emp ( 2 emp_id number primary key, 3 emp_name varchar2(10), 4 manager_id number 5 ); Table created. SQL> ed Wrote file afiedt.buf 1 create table my_mgr ( 2 manager_id number primary key, 3 employee_id number references my_emp( emp_id ), 4 purchasing_authority number 5* ) SQL> / Table created. SQL> alter table my_emp 2 add constraint fk_emp_mgr foreign key( manager_id ) 3 references my_mgr( manager_id ); Table altered. SQL> ed Wrote file afiedt.buf 1 select level lvl, 2 child_table_name, 3 sys_connect_by_path( child_table_name, '/' ) path 4 from (select parent.table_name parent_table_name, 5 parent.constraint_name parent_constraint_name, 6 child.table_name child_table_name, 7 child.constraint_name child_constraint_name 8 from user_constraints parent, 9 user_constraints child 10 where child.constraint_type = 'R' 11 and parent.constraint_type = 'P' 12 and child.r_constraint_name = parent.constraint_name 13 union all 14 select null, 15 null, 16 table_name, 17 constraint_name 18 from user_constraints 19 where constraint_type = 'P') 20 start with child_table_name = 'MY_EMP' 21* connect by prior child_table_name = parent_table_name SQL> / ERROR: ORA-01436: CONNECT BY loop in user data
If you have a cycle, you have some problems.
(1) it is a NOCYCLE keyword does not cause the error, but that probably requires an Oracle version which is not so far off support. I don't think it was available at the time 9.2 but I don't have anything old enough to test on
SQL> ed Wrote file afiedt.buf 1 select level lvl, 2 child_table_name, 3 sys_connect_by_path( child_table_name, '/' ) path 4 from (select parent.table_name parent_table_name, 5 parent.constraint_name parent_constraint_name, 6 child.table_name child_table_name, 7 child.constraint_name child_constraint_name 8 from user_constraints parent, 9 user_constraints child 10 where child.constraint_type = 'R' 11 and parent.constraint_type = 'P' 12 and child.r_constraint_name = parent.constraint_name 13 union all 14 select null, 15 null, 16 table_name, 17 constraint_name 18 from user_constraints 19 where constraint_type = 'P') 20 start with child_table_name = 'MY_EMP' 21* connect by nocycle prior child_table_name = parent_table_name SQL> / LVL CHILD_TABLE_NAME PATH ---------- ------------------------------ -------------------- 1 MY_EMP /MY_EMP 2 MY_MGR /MY_EMP/MY_MGR 1 MY_EMP /MY_EMP 2 MY_MGR /MY_EMP/MY_MGR
(2) If you try to write on a table and all of its constraints in a file and do it in a valid order, the entire solution is probably wrong. It is impossible, for example, to generate the DDL for MY_EMP and MY_DEPT such as all instructions for a table come first, and all the instructions for the other are generated second. So even if NOCYCLE to avoid the error, you would end up with an invalid DDL script. If that's the problem, I would rethink the approach.
-Generate the DDL for all tables without constraint
-Can generate the DDL for all primary key constraints
-Can generate the DDL for all unique key constraints
-Can generate the DDL for all foreign key constraintsThis is not solidarity all the DOF for a given in the file object. But the SQL will be radically simpler writing - there will be no need to even look at the dependency graph.
Justin
-
How to find the second largest in a pl/sql table
Hello friends,
I want to find the first and second maximum items in a pl/sql table.
Here's the code...
DECLARE
Max_earnings_type TYPE TABLE IS NUMBER;
max_earnings_tab max_earnings_type: = max_earnings_type();
number of v_count: = 0;
number of v_max_earnings;
Can someone give me how to find the maximum first max and second in the type of the given table.
appreciate your help.
Thank you/kumar
Published by: kumar73 on October 21, 2010 09:42kumar73 wrote:
When I tried to implement your logic in my application, I get the following error...
PL/SQL: digital or value error: NULL index key value table
What happens if the PL/SQL table has NULL values. Question is how you want to handle NULL values. You want to ignore nulls as GROUP BY do? If you want to consider NULL values, you can say if you want to order the NULLS FIRST or NULLS LAST. I guess that logical GROUP BY:
DECLARE TYPE max_earnings_type IS TABLE OF NUMBER; TYPE max_earnings_sorted_type IS TABLE OF NUMBER INDEX BY BINARY_INTEGER; max_earnings_tab max_earnings_type; max_earnings_tab_sorted max_earnings_sorted_type; BEGIN SELECT sal + comm BULK COLLECT INTO max_earnings_tab FROM emp; FOR v_i in 1..max_earnings_tab.count LOOP IF max_earnings_tab(v_i) IS NOT NULL THEN max_earnings_tab_sorted(max_earnings_tab(v_i)) := 1; END IF; END LOOP; DBMS_OUTPUT.PUT_LINE('MAX value in PL/SQL table is ' || nvl(to_char(max_earnings_tab_sorted.last),'NULL')); DBMS_OUTPUT.PUT_LINE('Second MAX value in PL/SQL table is ' || nvl(to_char(max_earnings_tab_sorted.prior(max_earnings_tab_sorted.last)),'NULL')); END; / MAX value in PL/SQL table is 2650 Second MAX value in PL/SQL table is 1900 PL/SQL procedure successfully completed. SQL> SELECT sal + comm 2 FROM emp; SAL+COMM ---------- 1900 1750 2650 1500 SAL+COMM ---------- 14 rows selected. SQL>
SY.
-
How to find the rank lowest for each student using a Select query?
Hey I'm having a little trouble here
I have this table
Student - Grade
John - 8
Richard - 9
Louis - 9
Francis - 5
John - 13
Richard - 10
Peter - 12
Shades may vary from 0 to 20.
Name - varchar (50)
Grade - wide
I'm trying to generate a SQL search to search for each rank lowest for each student.
So far, I did:
Select s.name, s.grade
s student
where s.grade = (select min (grade) of student)
The result of this search returns me only the rank lowest of all ranks posted above, which is Francis - 5.
I want to find the lowest rank, but not only for Francis, but for all students in the table.
How do I do that?
Thank you in advance.Ok
Now we head into analytical SQL:
with student as (select 'John' name, 8 grade, 'fail' result from dual union all select 'John' name, 13 grade, 'pass' result from dual union all select 'Francis', 5 grade, 'fail' from dual union all select 'Peter', 12, 'pass' from dual) -- End of your test data SELECT name, MAX (result) KEEP (DENSE_RANK FIRST ORDER BY grade) result, MIN (grade) min_grade FROM student GROUP BY name
Please note that I passed ;)
Concerning
PeterTo learn more:
http://download.Oracle.com/docs/CD/B19306_01/server.102/b14200/functions056.htm#SQLRF00641 -
How to find the value duplicate of each column.
I have it here are four columns,
How can I find the duplicate of each columns value.
with All_files like)
Select ' 1000 'like BILL, "2000" AS DELIVERYNOTE, CANDELINVOICE ' 3000', '4000' CANDELIVERYNOTE of all union double
Select ' 5000 ', ' 6000', ' 7000 ', ' 8000' Union double all the
Select '9000 ', '1000', '1100',' 1200' from dual union all
Select ' 1200 ', ' 3400', ' 6700 ', ' 8790' Union double all the
Select ' 1000 ', ' 2000', ' 3000 ', ' 9000' Union double all the
Select '1230', '2340', ' 3450 ', ' 4560' double
)
SELECT * from All_files
Output should be as shown below.
1000 2000 3000 4000
9000 1000 1100 1200
1200 3400 6700 8790
1000 2000 3000 9000
Required to check uniqueness columns.
Thank you.Hello
If you are not too concerned about performance, this should give you the desired result:
SELECT distinct INVOICE, DELIVERYNOTE, CANDELINVOICE, CANDELIVERYNOTE FROM ( SELECT a.*, count(*) over(partition by t.column_value) cnt FROM All_files a, table( sys.odcivarchar2list( a.INVOICE , a.DELIVERYNOTE , a.CANDELINVOICE , a.CANDELIVERYNOTE ) ) t ) WHERE cnt > 1 ;
-
How to find the redo generated by each SQL statement?
Database version is 10.2.0.4. OS is AIX.
We must again excessive generation during a specific time. We want to identify what a statement contributes to excessive recovery.
ADDM shows this as a first observation
Waiting on event "log file sync" during the execution of operations of COMMIT and ROLLBACK consumed at the time of the important data.
Is it possible to know which statement sql generates how many redo in bytes for a moment?
Thank you
DelphineIs it possible to know which statement sql generates how many redo in bytes for a moment?
It will not help you.
For example, you can see a lot of UPDATE, DELETE, INSERT from the apps statements. Then? What you do with them? If you can modify the application to eliminate the useless LMD - it would be great of course. But it is unlikely.When the DML statements also generate Redo, does not cause them too much expectations "log file sync", because the writer log buffer empty buffer as soon as it fulfills more than 30% after a certain time or on Commit / Rollback.
Waiting on event "log file sync" during the execution of operations of COMMIT and ROLLBACK consumed at the time of the important data.
Right. This is because the writer written newspaper here synchronous, reliable, he waits until the HDD writes data down and meets its written OK.
And hard drives are not the fastest things in the computer. They are mechanical - that's why.I would recommend:
1. place files redo log on quick drives used preference dedicated only to this end. If other I/O will often disturb these readers resulting securities heads change causing longer HDD expected.
2 consider using faster technology such as SAN or SSD. -
How to find the value max and min for each column in a table 2d?
How to find the value max and min for each column in a table 2d?
For example, in the table max/min for the first three columns would be 45/23, 14/10, 80/67.
Thank you
Chuck,
With color on your bars, you should have enough experience to understand this.
You're a loop in the table already. Now you just need a function like table Max and min. loop. And you may need to transpose the table 2D.
-
How to find the right server to use windowsmail to send and receive e-mails?
How to find the right server to use windowsmail to send and receive e-mails?
Who is your current e-mail server? (Which is after the @ in your address).Windows Mail: Setting up an account of end-to-end
http://Windows.Microsoft.com/en-us/Windows-Vista/Windows-mail-setting-up-an-account-from-start-to-finish -
How to find the book, THE, Op units, Org (All) names and ID?
How to find the book, THE, Op units, Org (All) names and ID?
With regard to:
Mr. Shahzad Saleem
Please run the following query
SELECT gl.NAME ledger_name, hou.NAME operating_unit_name,
xep.NAME legal_entity_name
Gl_ledgers gl, hr_operating_units hou, xle_entity_profiles xep
WHERE gl.ledger_id = hou.set_of_books_id
AND hou.default_legal_context_id = xep.legal_entity_id
-
How to find my WEP key and the name of my network?
I need to reset my wireless printer to scan. It asks for my WEP key and I thought it was one that is not correct. How to find the right WEP key and my correct network name? I have a laptop HP Pavilion dm4 with HP scanner/printe wireless
You must log - on to your AP or wireless router and look for the 'Wireless' or similar tab for your WEP key and the network name (SSID). Or you may be able to locate the information by going to control Panel\All Control Panel Items\Network and Center sharing on your laptop.
Frank
-
How to find the age of a child and snapshot number snapshot for a virtual machine.
Hi all
How to find the age of a snapshot for a virtual machine child count and snapshot.
This code snippet should help... Assuming that you have the following entries:
VM (VC:VirtualMachine)
snapshot (VC:VirtualMachineSnapshot)
System.log("====== Snapshot details for VM: "+snapshot.config.name+" ======"); var snapshotTrees = vm.snapshot.rootSnapshotList; System.log("Snapshot Tree Count: "+snapshotTrees.length); for each (snapshotTree in snapshotTrees){ showSnapshotInfo(snapshotTree, snapshot); } function showSnapshotInfo(snapshotTree, selectedSnapshot){ if(selectedSnapshot == snapshotTree.snapshot){ System.log("===================="); System.log("Name: "+snapshotTree.name); System.log("Id: "+snapshotTree.id); System.log("Description: "+snapshotTree.description); System.log("createTime: "+snapshotTree.createTime); System.log("quiesced: "+snapshotTree.quiesced); System.log("replaySupported: "+snapshotTree.replaySupported); System.log("backupManifest: "+snapshotTree.backupManifest); System.log("snapshot id: "+snapshotTree.snapshot.id); System.log("state: "+snapshotTree.state.value); var childSnapshotList = snapshotTree.childSnapshotList; if(childSnapshotList != null){ System.log("childSnapshotList length: "+snapshotTree.childSnapshotList.length); } System.log(""); } if(snapshotTree.childSnapshotList != null){ System.log("Children found: "+snapshotTree.childSnapshotList.length); for each (childSnapshotTree in snapshotTree.childSnapshotList){ showSnapshotInfo(childSnapshotTree, selectedSnapshot); } } }
During the passage of one of my virtual machines, here is an example of output I get:
[2014-06-12 15:19:21.493] [I] Snapshot Tree Count: 1 [2014-06-12 15:19:21.493] [I] ==================== [2014-06-12 15:19:21.494] [I] Name: before upgrade to 5.0.1 [2014-06-12 15:19:21.494] [I] Id: 31 [2014-06-12 15:19:21.494] [I] Description: [2014-06-12 15:19:21.495] [I] createTime: Mon Mar 19 2012 13:48:57 GMT-0400 (EDT) [2014-06-12 15:19:21.495] [I] quiesced: false [2014-06-12 15:19:21.495] [I] replaySupported: null [2014-06-12 15:19:21.495] [I] backupManifest: null [2014-06-12 15:19:21.496] [I] snapshot id: snapshot-83 [2014-06-12 15:19:21.496] [I] state: poweredOff [2014-06-12 15:19:21.496] [I] childSnapshotList length: 1 [2014-06-12 15:19:21.496] [I] [2014-06-12 15:19:21.497] [I] ==================== [2014-06-12 15:19:21.497] [I] Name: Before 5.1 upgrade [2014-06-12 15:19:21.497] [I] Id: 36 [2014-06-12 15:19:21.497] [I] Description: [2014-06-12 15:19:21.498] [I] createTime: Fri Sep 21 2012 21:59:58 GMT-0400 (EDT) [2014-06-12 15:19:21.498] [I] quiesced: false [2014-06-12 15:19:21.498] [I] replaySupported: null [2014-06-12 15:19:21.498] [I] backupManifest: null [2014-06-12 15:19:21.499] [I] snapshot id: snapshot-84 [2014-06-12 15:19:21.499] [I] state: poweredOff [2014-06-12 15:19:21.499] [I] childSnapshotList length: 1 [2014-06-12 15:19:21.499] [I] [2014-06-12 15:19:21.500] [I] ==================== [2014-06-12 15:19:21.500] [I] Name: Before Named Instance [2014-06-12 15:19:21.500] [I] Id: 37 [2014-06-12 15:19:21.501] [I] Description: [2014-06-12 15:19:21.501] [I] createTime: Mon Nov 11 2013 13:40:46 GMT-0500 (EST) [2014-06-12 15:19:21.501] [I] quiesced: false [2014-06-12 15:19:21.501] [I] replaySupported: null [2014-06-12 15:19:21.502] [I] backupManifest: null [2014-06-12 15:19:21.502] [I] snapshot id: snapshot-236 [2014-06-12 15:19:21.502] [I] state: poweredOff [2014-06-12 15:19:21.502] [I]
-
How to find the difference between standard edition and standard edition one
How to find the difference between oracle database standard edition and standard edition one 64 bit
(a) using sql
(b) using the configuration/installation filesHow to find the difference between oracle database standard edition and standard edition one 64 bit
(a) using sql
Select * the option of $ v;
(b) using the configuration/installation files
opatch lsinventory-details
-
How to find the path of reports to PDF and send them via JAVA?
Hi expert,
We have created many reports of OBIEE, how to find the way of reports to PDF and send them via JAVA?
Catalog/shared /..., but it is a binary file that is not sent to the customers.Hey kobe,.
You can try this:
http://satyaobieesolutions.blogspot.com/2012/07/setting-up-iBOT-to-save-report-to.html
Maybe you are looking for
-
showa MacBook with question mark folder
My oldmacbookdoes not start instead, I get a folder with a questionmark
-
can someone use my ipad stolen
Hi can locate my stolen iPad apple if some toys for use with iTunes account? Steven
-
Son PC, no backup discs. Hard drive died, bought new hard drive, everything is good, but must purchase the restore disks so that we can he return to clean state software factory. Are they still available? Thank you. Product # QW841AA #ABA
-
Bell: How to scan from HP4620 HP Tower
I can print to 4620, but when I try to scan it told me that there is a computer on the network. I recently installed a new toer.
-
Hello, I have a persistent problem that I can't find a solution for: Whenever I connect to my PC and try to open a file, I get a "Smart Web Printing" dialogue box pop up asking permission to install a file (SmartWebPrinting.msi) and the selected path