Wednesday, 20 August 2014

Center Canvas and Window in Oracle Forms 11g

Today I will present two dynamic procedure for centering canvas or windows in middle center of the screen.

We always want to show canvas at middle center in another canvas and also for window in oracle forms.

So I will produce today two generic procedures for centering canvas/window at middle center of others.


Centering Canvas

To implement displaying canvas at middle center of another canvas (Container canvas) I will create procedure has two parameters ( canvas [C1] and container canvas[C2] ) and procedure will change x,y coordination of canvas[C1] at middle center of canvas[C2]

PROCEDURE CENTER_VIEW (IN_VIEW_NAME VARCHAR2, IN_CONTAINER_VIEW VARCHAR2) 
 IS 
 BEGIN 
 SET_VIEW_PROPERTY (IN_VIEW_NAME, VIEWPORT_X_POS, (GET_VIEW_PROPERTY (IN_CONTAINER_VIEW, WIDTH) / 2 ) - (GET_VIEW_PROPERTY (IN_VIEW_NAME, WIDTH) / 2) ); 
 SET_VIEW_PROPERTY (IN_VIEW_NAME, VIEWPORT_Y_POS, (GET_VIEW_PROPERTY (IN_CONTAINER_VIEW, HEIGHT) / 2 ) - (GET_VIEW_PROPERTY (IN_VIEW_NAME, HEIGHT) / 2) );
 END;

Centering Window

To implement displaying window at middle center of another window (Container window ) I will create procedure has two parameters ( window[W1] and container window[W2] ) and procedure will change x,y coordination of window [W1] at middle center of window [W2]

PROCEDURE CENTER_WINDOW (IN_WIN_NAME VARCHAR2, IN_CONTAINER_WIN VARCHAR2) 
 IS BEGIN 
 SET_WINDOW_PROPERTY (IN_WIN_NAME, X_POS, (GET_WINDOW_PROPERTY (IN_CONTAINER_WIN, WIDTH) / 2 ) - (GET_WINDOW_PROPERTY (IN_WIN_NAME, WIDTH) / 2) ); 
 SET_WINDOW_PROPERTY (IN_WIN_NAME, Y_POS, (GET_WINDOW_PROPERTY (IN_CONTAINER_WIN, HEIGHT) / 2 ) - (GET_WINDOW_PROPERTY (IN_WIN_NAME, HEIGHT) / 2) ); 
 END; 

For example
















Write code in when button pressed trigger
for window
center_window('NEW_WIN','MAIN_WIN');
show_window('NEW_WIN');

for canvas

center_view('VIEW_CAN','MAIN_CAN');
show_view('VIEW_CAN');




Monday, 18 August 2014


Date / Time related queries

Get the first day of the month
Quickly returns the first day of current month. Instead of current month you want to find first day of month where a date falls, replace SYSDATE with any date column/value.

SELECT TRUNC (SYSDATE, 'MONTH') "First day of current month"
FROM DUAL;



Get the last day of the month
This query is similar to above but returns last day of current month. One thing worth noting is that it automatically takes care of leap year. So if you have 29 days in Feb, it will return 29/2. Also similar to above query replace SYSDATE with any other date column/value to find last day of that particular month.

SELECT TRUNC (LAST_DAY (SYSDATE)) "Last day of current month"
FROM DUAL;



Get the first day of the Year
First day of year is always 1-Jan. This query can be use in stored procedure where you quickly want first day of year for some calculation.

SELECT TRUNC (SYSDATE, 'YEAR') "Year First Day" FROM DUAL;


Get the last day of the year
Similar to above query. Instead of first day this query returns last day of current year.

SELECT ADD_MONTHS (TRUNC (SYSDATE, 'YEAR'), 12) - 1 "Year Last Day" FROM DUAL


Get number of days in current month
Now this is useful. This query returns number of days in current month. You can change SYSDATE with any date/value to know number of days in that month.

SELECT CAST (TO_CHAR (LAST_DAY (SYSDATE), 'dd') AS INT) number_of_days
FROM DUAL;



Get number of days left in current month
Below query calculates number of days left in current month.

SELECT SYSDATE,
LAST_DAY (SYSDATE) "Last",
LAST_DAY (SYSDATE) - SYSDATE "Days left"
FROM DUAL;



Get number of days between two dates
Use this query to get difference between two dates in number of days.

SELECT ROUND ( (MONTHS_BETWEEN ('01-Feb-2014', '01-Mar-2012') * 30), 0)
num_of_days
FROM DUAL;


OR

SELECT TRUNC(sysdate) - TRUNC(e.hire_date) FROM employees;
Use second query if you need to find number of days since some specific date. In this example number of days since any employee is hired.

Display each months start and end date upto last month of the year
This clever query displays start date and end date of each month in current year. You might want to use this for certain types of calculations.

SELECT ADD_MONTHS (TRUNC (SYSDATE, 'MONTH'), i) start_date,
TRUNC (LAST_DAY (ADD_MONTHS (SYSDATE, i))) end_date
FROM XMLTABLE (
'for $i in 0 to xs:int(D) return $i'
PASSING XMLELEMENT (
d,
FLOOR (
MONTHS_BETWEEN (
ADD_MONTHS (TRUNC (SYSDATE, 'YEAR') - 1, 12),
SYSDATE)))
COLUMNS i INTEGER PATH '.');



Get number of seconds passed since today (since 00:00 hr)

SELECT (SYSDATE - TRUNC (SYSDATE)) * 24 * 60 * 60 num_of_sec_since_morning
FROM DUAL;



Get number of seconds left today (till 23:59:59 hr)

SELECT (TRUNC (SYSDATE+1) - SYSDATE) * 24 * 60 * 60 num_of_sec_left
FROM DUAL;


Copyright © ORACLE-FORU - SQL, PL/SQL and ORACLE D2K(FORMS AND REPORTS) collections | Powered by Blogger
Design by N.Design Studio | Blogger Theme by NewBloggerThemes.com