PL/SQL FUNCTION: Passage date &; string as parameter
Hello
I have a situation where I have to convert the ISO date format Date [YYYY-MM - DDTHH24:MI]
Is function def. : FN_ISO (IN_DATE Varchar2, Varchar2 IN_TIME)
Front-end for the date and time, I can enter in 3 different ways.
Input 1. what date / time is completely known
Date: 5 April 2015
Time: 23:56
Input 2. When the date is known, but the time is unclear (the hour is UNK)
Date: 5 April 2015
Time: UNK:56
Entry 3. When the date and time are unknown (month is UNK)
Date: 05-UNK-2015
Time: UNK:56
Here, I am facing the problem with the Time parameter. Please find below scenarios:
Scenario 1: If the time is complete (as input 1) then I'll pass the data type Date in 2nd parameter (5 April 2015, which contains the time internally)
Scenario 2: If the time is incomplete or partially known (as input 2) then I'll pass the Varchar2 data type in 2nd parameter (UNK:56 as string)
Problem statement:
Consider scenario 1; If date & time is over so I'm passing the data type Date (April 5, 2015 23:56) Varchar2, then time will be 5 April 2015 00:00, however I need to get the time (23:56)
Note:
-I can't use the overload of functions.
-I can not change the way call function which I now call.
-I can't do second parameter date because in scenario 2 I have to pass the string "UNK:56".
Please suggest me, how I can address the issue. Your help would be very appreciated.
Thanks in advance!
create or replace function fun_iso (IN_DATE VARCHAR, IN_TIME VARCHAR2 ) return varchar2 is V_ISO varchar2(20); begin SELECT (case when regexp_like(IN_DATE,'(UNK|\d+)/(UNK|\d+)/(UNK|\d+)') THEN REGEXP_REPLACE((REGEXP_REPLACE(translate(in_date||' '||in_time,'/ ','-T'),'UNK|NUL','-')),'(:|-|T)+$') WHEN regexp_like(IN_DATE,'\d+-(\w+|\d+)-(\d+)') then REGEXP_REPLACE((REGEXP_REPLACE(translate(TO_char(to_date(IN_DATE,'DD-MM-YY'),'YYYY-MM-DD')||' '|| /*for scenario 1*/ (CASE WHEN regexp_like(IN_TIME,'(\d+)-(\w+)-(\d+)') THEN DECODE(TO_CHAR((IN_TIME),'HH24:MI:SS'),'00:00:00', NULL,TO_CHAR(IN_TIME,'HH24:MI:SS')) /* Here i need time if i will pass 05-Apr-2015*/ ELSE NULL END) ,'/ ','-T'),'UNK|NUL','-')),'(:|-|T)+$') else '0' END) INTO V_ISO from dual; RETURN V_ISO; end; / /* Use below table : line 35 is scenario 1 */ select a.*, fun_iso(IN_DATE, IN_TIME) FROM ( (SELECT '2015-01-15T22:29:59 ' ISO_DATE_TIME, '2015/05/05' IN_DATE , '22:29:59' IN_TIME FROM DUAL UNION SELECT ' ' ISO_DATE_TIME, 'UNK/UNK/UNK' IN_DATE , '22:29:NUL' IN_TIME FROM DUAL UNION SELECT ' ' ISO_DATE_TIME, '01-Jan-15' IN_DATE , '22:UNK:NUL' IN_TIME FROM DUAL UNION SELECT ' ' ISO_DATE_TIME, '01-Jan-1948' IN_DATE , '22:29:NUL' IN_TIME FROM DUAL UNION SELECT ' ' ISO_DATE_TIME, '01-05-15' IN_DATE , '22:29:NUL' IN_TIME FROM DUAL UNION SELECT ' ' ISO_DATE_TIME, '25-05-2015' IN_DATE , '22:29:NUL' IN_TIME FROM DUAL UNION --SELECT ' ' ISO_DATE_TIME, '25-05-2015' IN_DATE , TO_CHAR(TO_DATE('01-AUG-14 23:56:00','DD-Mon-YY HH24:MI:SS')) IN_TIME FROM DUAL UNION SELECT '2009' ISO_DATE_TIME, '2009/UNK/UNK' IN_DATE , 'UNK:UNK:NUL' IN_TIME FROM DUAL UNION SELECT '2009---25' ISO_DATE_TIME, '2009/UNK/25' IN_DATE , 'UNK:UNK:NUL' IN_TIME FROM DUAL UNION SELECT '--03-25' ISO_DATE_TIME, 'UNK/03/25' IN_DATE , 'UNK:UNK:NUL' IN_TIME FROM DUAL UNION SELECT '--03--T-:15' ISO_DATE_TIME, 'UNK/03/UNK' IN_DATE , 'UNK:15:NUL' IN_TIME FROM DUAL UNION SELECT '2009-03 ' ISO_DATE_TIME, '2009/03/UNK' IN_DATE , 'UNK:UNK:NUL' IN_TIME FROM DUAL UNION SELECT '2009-03--T12' ISO_DATE_TIME, '2009/03/UNK' IN_DATE , '12:UNK:NUL' IN_TIME FROM DUAL ) ) a;
Hello
Here's one way:
FUNCTION to CREATE or REPLACE fun_iso
(in_date in VARCHAR2
in_time IN VARCHAR2
)
RETURN VARCHAR2
DETERMINISTIC
IS
month_name VARCHAR2 (51): = ' JAN Feb MAR Apr MAY June July Aug SEP OCT NOV DEC UNK;
month_num VARCHAR2 (50): = '01 02 03 04 05 06 07 08 09 10 11 12-';
BEGIN
RETURN SUBSTR (in_date,-4)
|| '-'
|| SUBSTR (month_num
INSTR (month_name
, SUBSTR (in_date, 4, 3)
)
2
)
|| '-'
|| SUBSTR (in_date, 1, 2)
|| ' T '
|| CASE
WHEN SUBSTR (in_time, 1, 3) = "UNK".
THEN '-'
Of OTHER SUBSTR (in_time, 1, 2)
END
|| '-'
|| SUBSTR (in_time-2)
;
END fun_iso;
/
If your needs are more complex, you can do this drill several assignments, where you build a string a little at a time, and RETURN this string at the end.
Tags: Database
Similar Questions
-
Hello OTN.
I don't understand why my sql query will pass by in the data model of the BI Publisher. I created a new data model, chose the data source and type of Standard SQL = SQL. I tried several databases and all the same error in BI Publisher, but the application works well in TOAD / SQL Developer. So, I think it might be something with my case so I'm tender hand to you to try and let me know if you get the same result as me.
The query is:
SELECT to_char (to_date ('15-' |)) TO_CHAR(:P_MONTH) | » -'|| (To_char(:P_YEAR), "YYYY-DD-MONTH") - 90, "YYYYMM") as yrmth FROM DUAL
Values of the variable:
: P_MONTH = APRIL
: P_YEAR = 2015
I tried multiple variations and not had much luck. Here are the other options I've tried:
WITH DATES AS
(
Select TO_NUMBER (decode (: P_MONTH, 'JANUARY', '01',))
'FEBRUARY', '02',.
'MARCH', '03'.
'APRIL', '04'
'MAY', '05'.
'JUNE', '06'.
'JULY', '07',.
'AUGUST', '08'.
'SEPTEMBER', '09'.
'OCTOBER', '10',.
'NOVEMBER', '11'.
"DECEMBER", "12."
'01')) as mth_nbr
of the double
)
SELECT to_char (to_date ('15-' |)) MTH_NBR | » -'|| (TO_CHAR(:P_YEAR), 'DD-MM-YYYY') - 90, "YYYYMM")
OF DATES
SELECT to_char (to_date ('15-' |: P_MONTH |)) » -'|| ((: P_YEAR, 'MONTH-DD-YYYY')-90, "YYYYMM") as yrmth FROM DUAL
I'm running out of ideas and I don't know why it does not work. If anyone has any suggestions or ideas, please let me know. I always mark answers correct and useful in my thread and I appreciate all your help.
Best regards
-Konrad
So I thought to it. It seems that there is a bug/lag between the guest screen that appears when you enter SQL in the data model and parameter values, to at model/value data.
Here's how I solved my problem.
I have created a new data model and first created all my settings required in the data model (including the default values without quotes, i.e. APRIL instead "Of APRIL") and then saved.
Then I stuck my sql query in the data model and when I clicked ok, I entered my string values in the message box with single quotes (i.e. "in APRIL' instead of APRIL)
After entering the values of string with single quotes in the dialog box, I was able to retrieve the columns in the data model and save.
In the data tab, is no longer, I had to enter the values in single quotes, but entered values normally instead, and the code worked.
It seems the box prompted to bind the values of the variables when the SQL text in a data model expects strings to be wrapped in single quotes, but no where else. It's a big headache for me, but I'm glad that I solved it, and I hope this can be of help to other institutions.
See you soon.
-
Can I use data string Web App (image) in a CSS hover function?
I'm developing a profile of employee of company "show and tell" using the Web application. I built my item in the list and details. Works very well. However, I have no hover function. So, I created a few css - one div id and added a background image then hover div with another image to hover. It worked. I moved the code of Dreamweaver in British Colombia - inside (the list template) Web application. I replaced the paths of the image with the data string Web App - image (e.g. {tag_employee photo}). Then I did the same thing to hover - I changed the image of the data string (e.g. {tag_employee photo2}). It does not work now.
All CSS is written inside the body, so it's not pulling to the outside path. I thought that a path from the outside may not understand the data string.
How can I get this to post a link with the chain of image data? Am I missing something?
How can I create an image using CSS switch and function WITH the BC Web App data strings hover?
Here's how I wrote the id of the DIV:
# {List_photo
height: 200px;
Width: 200px;
background-image: url("{tag_employee photo (200px)}" ");
position: relative;
margin-bottom: 10px;
Display: block;
}
# {List_photo:hover
height: 200px;
Width: 200px;
background-image: url("{tag_employee photo (hover)}" ");
position: relative;
margin-bottom: 10px;
Display: block;
}
Thank you!
Robert
Hi Robert,.
The concept of what you're doing works (as long as the)
-
CSXSInterface: Call to jsx-function with a string xml as parameter?
Hello
for me CSXSInterface worked very well so far with all the settings and the SyncResults.
Now, I do a few operations xml with actionscript 3 and photoshop scripts. I am able to return an XML from a function javascript to actionscript3 and do all kinds of operations with it. Somehow, I can't call a function with the string xml as parameter jsx? Does anyone have a solution for this?
Here is what I tried:
var xmlStr:String = _myXml.toXMLString(); // I tried _myXml.toString() too but it didnt work either ;-( CSXSInterface.instance.evalScript("xmlFunction", xmlStr);
Thanks in advance!
Not for me it isn't...
I use Flash Builder (with Extension Builder added on) too, and I don't remember having seen a mistake HostObject of any kind. Import you the classes necessary?
Substances
-
How to get the query of the region "PL/SQL function body returns the query string"?
Hello
is it possible to get the query string from the region of type "PL/SQL function body returns the query string"?
I can get the definition of the region as a PL/SQL procedure, but I am interested in the returned query. I tried to write something like
< pre > v_return_query: = «...» » ;
: P49_QUERY: = v_return_query;
Return v_return_query; < / pre >
to save the return on hidden item P49_QUERY string, but it does not work. I get the error message: ERR-1002 cannot find the item for the "P49_QUERY" element ID in the application '4000 '.
Kind regards
PrzemekIf you need to make reference to a page element in the block then you can use this type of control to avoid having to use generic column names:
if apex_application.get_current_flow_sgid(:APP_ID) = apex_application.get_sgid then-- runtime :P9_SQL := vSQL;else-- design time null;end if;
But if all you want to do is capture the SQL debugging you can take all the references element in the block and use the insert statement (in a debug table) as I showed earlier.
Scott
-
SQL function for comparing 2 strings
Hi all
Is there a SQL function for comparing 2 strings?There is no function of pre defined in Sql for the string comparison. You can create according to your requirement.
Concerning
-
PL/SQL functions as LOV to use in another display object
Hello
We had a custom search to extract data from a display object and the data displayed as a Table of ADF. Now, there are few requests for searches on this report. Go see criteria and Panel request if we allow saved search. But the fields used in the research are going through a lot of logic and thus the PL/SQL functions are implemented. We used to call these functions and lists separated by commas and then divided the list into individual elements and put in the component "select options".
The value (String) returned by the pl/sql function is something like - APAC, EMEA, NORTH AMERICA, FDA
I am creating a LOV based on SQL-query "Select getRegions() from dual;
Now, I want the list separated by commas to divide so that I could use this LOV in an another view and try the display criteria and saved searches.
I tried to assign as LOV just to check and the criteria drop-down view for region displays same value as single element - "APAC, EMEA, NORTH AMERICA, LAD."
I want it to be 4 separate - elements
APAC
EMEA
NORTH AMERICA
DVL
Is there anyway to achieve this?
Or better is at - it another way to do this (maybe I'm wrong)
Thank you.
JDev: 11.1.2.4
Instead of a programmatic VO of PL/SQL, I found sometimes easier to write PL/SQL functions that return a table - need to CREATE a TYPE for the data items to be returned and a TYPE of TABLE IMBRIQUE tabular form of the first kind. The function returns the type of table, and can even be a PIPElined table function. Then I create a VO with the following text:
SELECT * from TABLE (my_function_returning_table)
The function can even take parameters, which you fill with variable BIND your VO.
-
No support for oracle sql functions
Hi all
Please can someone explain why the B-tree indexes are not capable of supporting SQL queries using the built-in functions of Oracle.
We have indexes of tree b on account_no column.
Select * from test_table where account_no = 11005208
the above query use the index on account_no
Select * from test_table where superior (account_no) = 11005208
But this query does not use the index on the account_no, going for the full table scan.
My question here is account_no is the numeric data type.
Then, there is no difference between the data in the columns account_no and upper (account_no) column data, so why he does not use index when using sql functions in an sql query?Hello
If you apply the upper function, Oracle implicitly converts its argument to a string, so your query is actually upper (to_char (account_no)).
There is none HAVE fully functional in the optimizer and you do not expect to know everything and do all the conclusions that a human being can do. Why should Oracle re - write this type of query analysis the data type of the columns and features when it seems more natural programmer write a correct query (without capital letters in this example) or, if necessary, create an index based on a function? -
Problem inserting new line in a VO with SQL functions and subqueries
Hello
I use JDeveloper 10.1.3.4 and and stuck with insertion of a new line when the values to insert into some fields of the new line are returns of SQL functions and subqueries.
At the sqlplus prompt, the following sql statement is tested and developed successfully:
Note that the values for the fields of 4th and 5th are returns of subqueries and SQL functions.insert into VALIDATIONS values ( '111223333', 'JANE', 'DOE', SYSDATE, (select to_char(sysdate, 'yymmdd') from dual)|| (select to_char(count(TRANSACTION_DATE)+1,'fm0999') from VALIDATIONS where trunc(TRANSACTION_DATE) = to_char(sysdate)) );
Ideally, it would be simple to assemble a SQL and executed him as he did to the old way of servlet:
I'm not sure it can be done in JDeveloper, and it was not found in the developer's guide. What I found was rather:String sql = "insert into VALIDATIONS values ('" + id + "', '" + firstName + "', '" + lastName + "', SYSDATE, (select to_char( ......)))"; statement.executeUpdate(sql);
In my case, it would be OK for the first three fields as shown below (in the code of transactionsRecords is a display object). But what about the 4th and 5th fields?// 1. Find the ServiceRequests view object instance. ViewObject svcReqs = am.findViewObject("ServiceRequests"); // 2. Create a new row and insert it into the row set Row newSvcReq = svcReqs.createRow(); svcReqs.insertRow(newSvcReq); // 3. Show effect of entity object defaulting for Status attribute System.out.println("Status defaults to: "+newSvcReq.getAttribute("Status")); // 4. Set values for some of the required attributes newSvcReq.setAttribute("CreatedBy",308); // Nancy Greenberg (user) Date now = new Date(new Timestamp(System.currentTimeMillis())); newSvcReq.setAttribute("RequestDate",now); newSvcReq.setAttribute("ProdId",119); // Ice Maker newSvcReq.setAttribute("ProblemDescription","Cubes melt immediately"); // 5. Commit the transaction am.getTransaction().commit();
A big thank you to those who know or have experience before!Row newTransaction = transactionsRecords.createRow(); transactionsRecords.insertRow(newTransaction); newTransaction.setAttribute("StudentId", id); newTransaction.setAttribute("FirstName", firstName); newTransaction.setAttribute("LastName", lastName); newTransaction.setAttribute("TransactionDate", <how to put "SYSDATE" here?>); newTransaction.setAttribute("ConfirmNumber", <how to put subqueries here?>);
NewmanNewman,
You can do this via a procedure call. This technique is described here
I guess you can't do this directly in the EO or VO.
You can do it the old way to create a prepared directly query and call it as you described. To get the declaration use getDBTransaction () .createPreparedStatement (...) method available in the module of your application.
Be aware of the implications using the given solution. The framework doesn't know anything of what you are doing. So to see the changes that you used to update the tables that you change.Timo
-
Chain replication using a sql function...
Hello
Is there a sql function that reproduces a string given so many times that appears in a parameter...?
For example: String-> test
Select < sql_function > ('test', 3) double
-> testtesttest
Note: I use Oracle10g v.2
Thank you
SIMWhat about a SQL?
satyaki> satyaki>select * from v$version; BANNER ---------------------------------------------------------------- Oracle Database 10g Enterprise Edition Release 10.2.0.3.0 - Prod PL/SQL Release 10.2.0.3.0 - Production CORE 10.2.0.3.0 Production TNS for 32-bit Windows: Version 10.2.0.3.0 - Production NLSRTL Version 10.2.0.3.0 - Production Elapsed: 00:00:00.08 satyaki> satyaki> satyaki>select DBMS_XMLGEN.getxmltype ('SELECT '||chr(39)||'&str'||chr(39)||' cola FROM dual connect by rownum<='||&num).EXTRACT('//text()') res 2 from dual; Enter value for str: satyaki Enter value for num: 1 old 1: select DBMS_XMLGEN.getxmltype ('SELECT '||chr(39)||'&str'||chr(39)||' cola FROM dual connec new 1: select DBMS_XMLGEN.getxmltype ('SELECT '||chr(39)||'satyaki'||chr(39)||' cola FROM dual con RES ---------------------------------------------------------------------------------------------------- satyaki Elapsed: 00:00:00.07 satyaki>/ Enter value for str: satyaki Enter value for num: 2 old 1: select DBMS_XMLGEN.getxmltype ('SELECT '||chr(39)||'&str'||chr(39)||' cola FROM dual connec new 1: select DBMS_XMLGEN.getxmltype ('SELECT '||chr(39)||'satyaki'||chr(39)||' cola FROM dual con RES ---------------------------------------------------------------------------------------------------- satyakisatyaki Elapsed: 00:00:00.03 satyaki> satyaki>/ Enter value for str: satyaki Enter value for num: 3 old 1: select DBMS_XMLGEN.getxmltype ('SELECT '||chr(39)||'&str'||chr(39)||' cola FROM dual connec new 1: select DBMS_XMLGEN.getxmltype ('SELECT '||chr(39)||'satyaki'||chr(39)||' cola FROM dual con RES ---------------------------------------------------------------------------------------------------- satyakisatyakisatyaki Elapsed: 00:00:00.02 satyaki> satyaki>/ Enter value for str: satyaki Enter value for num: 5 old 1: select DBMS_XMLGEN.getxmltype ('SELECT '||chr(39)||'&str'||chr(39)||' cola FROM dual connec new 1: select DBMS_XMLGEN.getxmltype ('SELECT '||chr(39)||'satyaki'||chr(39)||' cola FROM dual con RES ---------------------------------------------------------------------------------------------------- satyakisatyakisatyakisatyakisatyaki Elapsed: 00:00:00.14
Kind regards.
LOULOU
Published by: Satyaki_De on September 27, 2008 14:10
-
PL/SQL function to calculate the non-working days
Hello
I have the following pl/sql function which generates a number of days between two selected dates (i.e. excluding weekends). However, I also need to exclude specific holidays - day of Christmas etc. These holiday dates are stored in a table in our database (11 GR 2) called "HOLIDAY".
How can I integrate the holidays which is held in the table of holidays in the following query to exclude these dates as well? I know how to write a separate funtion pl/sql for a number of days between two dates using SELECT... BUT I can't work out how to bring together them in a single query.
Could someone show me how with the pl/sql / dates below please?
Example of HOLIDAY table below.
Thank you!
TP
create or replace function WORKING_DAYS (pi_start_date in date, pi_end_date in date) return integer is v_start_date date :=pi_start_date; v_end_date date:=pi_end_date; v_count integer:=0; begin while v_start_date <= v_end_date loop if to_char(v_start_date,'D') not in ('6','7') then v_count := v_count+1; end if; v_start_date:=v_start_date+1; end loop; return v_count; end;
(select '10-Apr-2013' as NWD from dual union all select '06-May-2013' from dual union all select '27-May-2013' from dual union all select '26-Aug-2013' from dual union all select '26-Dec-2013' from dual union all select '25-Dec-2013' from dual union all select '01-Jan-2014' from dual union all select '18-Apr-2014' from dual union all select '21-Apr-2014' from dual union all select '05-May-2014' from dual union all select '26-May-2014' from dual union all select '25-Aug-2014' from dual union all select '25-Dec-2014' from dual union all select '26-Dec-2014' from dual) HOLIDAYS
Hello
the link is on MOSC, not OTN... Here's a copy:
This function calculates the number of days between two dates, ignoring weekends and holidays (if requested and if the holidays are stored in a table)
I give an example of table 'public_holiday' with sample data, but users must ensure that their table contains the relevant data (all holidays within the maximum range of use of the service)
CREATE TABLE public_holiday (calendar_day, DATE, text VARCHAR2 (30));
FUNCTION to CREATE or REPLACE nb_days (p_date_from IN DATE
p_date_to DATE by DEFAULT TRUNC (sysdate)
, p_public_holidays in CHAR DEFAULT 'Y '.
) RETURN NUMBER
DEFINE AUTHID
AS
/*********************************************************************/
/ * Author: Bruno Vroman * /.
/ * Created: 23-AUG-2012 * /.
/ * Last updated: 23-AUG-2012 * /.
/ * Object: to calculate the number of days between 2 dates, to the exclusion of * /.
/ * Saturday and Sunday, but also "holidays" If the * /.
/ * argument 'p_public_holidays' = 'Y ' * /.
/ * Support: p_date_from<= p_date_to ="">=>
/ * component ' hour min dry "ignored (just counting days) * /.
/* First step: */
/ * the calendar days between 2 days * /.
/ Remove 2 days for each "week" and 0 or 1 extra day * /.
/ * function to a condition "complex" mix day of first week * /.
/ * and the number of days when full remaining weeks are removed * /.
/ * (set up once for all, for example if there is 3 days and the * /)
(/ * first day is a Thursday, there is 1 "Sat/Sun" to subtract) * /.
/ * Second step: If 'p_public_holidays' = 'Y': other * /.
/ * days, do not count holidays. */
/ Holiday everyday are defined in a table "public_holiday" * /.
/ * Note: there may be holidays defined on Saturday/Sunday. */
/*********************************************************************/
l_result NUMBER;
l_from DATE;
l_to DATE;
l_case tank (4);
BEGIN
l_from: = TRUNC (p_date_from);
l_to: = TRUNC (p_date_to);
l_case: = TO_CHAR (l_from, 'Dy', 'NLS_DATE_LANGUAGE = English').
To_char (MOD (l_to - l_from + 1, 7));
l_result: = l_to - l_from + 1
-TRUNC ((l_to-l_from + 1) / 7) * 2
-CASE
WHEN l_case IN ('Mon6', 'Tue5', 'Wed4', 'Thu3', 'Fri2'
, "Sat1", "Sun1", "Sun2', 'Sun3", "Sun4".
, "Sun5', 'Sun6.
)
THEN 1
WHEN l_case IN ('Tue6', 'Wed5', 'Wed6', 'Thu4', "Thu5"
, 'Thu6', 'Fri3', 'Fri4', 'Fri5', 'Fri6 '.
, "Sat2", "Sat3', 'Sat4', 'Sat5", "Sat6.
)
THEN 2
0 OTHERWISE
END
;
IF SUPERIOR (p_public_holidays) = "Y".
THEN
SELECT l_result - COUNT (*)
IN l_result
OF public_holiday p
WHERE p.calendar_day > = l_from
AND p.calendar_day<=>=>
AND SUBSTR (TO_CHAR (p.calendar_day
, "Dy".
'NLS_DATE_LANGUAGE = English'
)
, 1, 1 ) != 'S'
;
END IF;
RETURN l_result;
EXCEPTION
WHILE OTHERS
THEN
DBMS_OUTPUT. Put_line (' CTF nb_days (' |))
To_char (p_date_from, "MON-DD-YYYY"). ', ' ||
To_char (p_date_to, "MON-DD-YYYY"). ', ' ||
p_public_holidays | ' ) : ' || SQLERRM
);
LIFT;
END nb_days;
/
REM
REM example:
REM A) fill out the 'public_holidays '.
REM
TRUNCATE TABLE public_holiday;
INSERT INTO public_holiday VALUES (DATE ' 2012-01-01', ' new year (a Sunday)');
INSERT INTO public_holiday VALUES (DATE '' 2012-01-03, "for example");
REM (insert other days...)
COMMIT;
Call the function for some pairs of dates of REM B)
REM nb1: remove only Sat/Sun
REM nb2: also remove holidays
REM
ALTER SESSION SET nls_date_format ='Dy DD-MON-YY';
WITH some_dates AS
(SELECT DATE ' 2011-12-29'd dual FROM
UNION ALL SELECT DATE ' 2012-01-08' FROM dual
UNION ALL SELECT DATE ' 2012-01-10' FROM dual
)
SELECT d1.d 'FROM '.
, d2.d ' to THE '.
, nb_days (d1.d, d2.d, ' don't) nb1
, nb_days (d1.d, d2.d, 'Y') nb2
OF some_dates d1
some_dates d2
WHERE d1.d<=>=>
ORDER BY nb1, nb2, d1.d
;
GO TO NB1 NB2
------------- ------------- ---- ----
Monday, January 8, 12 Monday, January 8, 12 0 0
Friday, December 29, 11 Friday, December 29, 11 1 1
Wednesday, January 10, 12 Wednesday, January 10, 12 1 1
Monday, January 8, 12 Wednesday, January 10, 12 2 2
Friday, December 29, 11 Monday, January 8, 12 7 6
Friday, December 29, 11 Wednesday, January 10, 12 9 8
Hope that this could be useful, but note that this code has not been completely tested, so check and test before you trust it (in the case of any questions, please post a comment)
Bruno Vroman.
Best regards
Bruno
-
Hi all
I have a table which includes
ID, first_name, last name and date of birth
I want to retrieve all the records that have the same name and DOB
for example.
ID, first_name, last name, DOB
1 xyz abc 01/01/2012
hij 2 efg 15/05/2012
3 xyz abc 01/01/2012
4 xyz abc 01/01/2012
so in the output of 1, 3 and 4 rows will appear only.
can someone advise please on the appropriate SQL function
Thanks in advance
Hello
One way is to use the analytical COUNT function:
WITH got_num_rows AS
(
SELECT id, first_name, last_name, dob
, COUNT (*) OVER (PARTITION BY first name
last_name
, dob
) AS num_rows
FROM table_x
)
SELECT id, first_name, last_name, dob
OF got_num_rows
WHERE num_rows > 1
;
The subquery is needed here, because the analytical functions are calculated after the WHERE clause has been applied. To use the results of an anlytic function in a WHERE clause, you must calculate the function in a subquery, then you can use the results where you want (including the WHERE clause) of a Super query.
-
BEEP 10 g call a PL SQL function
Hello..
It's really breaking the feet... googled a lot but always back to square start.
... Well guys want to help me...
I need to call a function from PL SQL BI editor passing 3 parameters.
that means this feature is... it feeds a table.
And the editor of BI report is read from the populated table...
Kindly help me out here... How can I start...
PL SQL function is a stand-alone... It is not under any procedure/package...
If you could give me some small excerpts of what to write in the style of data... that would be great... and Yes, indeed, this is the old version of the BEEP... 30%>
Total Questions: 11 (10 open)
>
Why can't anyone help you?>
He throws me an error
Variable binding does not existany work arounds guy?
>
soand in z_report_sys_op_test_pkg.z_report_sys_op_test get the necessary value
>
substr (: Store, 0, InStr(:Store,'-') - 1). -
Hello
In a query XQuery is posssible to call a function or procedure SQL (PL / SQL)?
Here is an example of what I had accomplished:
SELECT THE PRD. XMLCOLUMN of
XMLTABLE (' for $i in ora: view("P_iXXX")/LINE)
$j in ora: view("P_jXXX")/LINE.
where
($i / NSU_xxx = $j/NSU_xxx)
return
(
< NCL >
{
$i / NSU_xxx,
H3. CALL the SQL function? as sql_xxx
for $k in ora: view("P_kxxx")/ROW
($vk/COD_RMP_VPM = "PRD")
Return()
}
< / NCL >
() "PATH of XMLType 'XMLCOLUMN' COLUMNS 'resultsqlfunction' INTEGER PATH 'xsql_xxx' INTEGER ACCESS to 'NSU_xxx' path 'NSU_xxx', '.') as the PRD;
Thanks in advance for your answers
FrançoisWho today replaces "ora: see?
On 11.2, ora expansion feature: view() is deprecated in favor of the fn:collection("oradb:/") method:
http://docs.Oracle.com/CD/E11882_01/AppDev.112/e23094/xdb_xquery.htm#BABECFFD
My DBA database have installed Oracle XML DB to use the XMLType and XMLTable, I thought that these features among other things speed up the creation of XML.
What are the benefits of using XQuery and XMLTable and XMLQUERY functions?
Which version of the database you use?
Please read: http://docs.oracle.com/cd/E11882_01/appdev.112/e23094/xdb_xquery.htm#CBAGCBGJ
Is there another method to expedite the creation of XML?
Publication of SQL/XML functions are probably the best way to create custom relational data XML documents.
The basic functionality of XQuery is not to the RDBMS query tables or views, although Oracle provides extensions to do.
Most of the time, I use XQuery (via XMLTable and XMLQuery) to do exactly the opposite, i.e. to extract XML data in a relational form, or the transformation of XML fragments.If your actual requests are slow - even if you need to define what that means and that you are pregnant - then maybe the SQL/XML functions are not the real problem.
In a "Where clause" as I turn, I have several "outer join". Here is an example.
where
PPM. NSU_PPM = w.NSU_PPM and FRNS. NSU_FRN (+) IS FCO. NSU_FRN and FCO. NSU_FCO (+) IS PPM. NSU_FCO
and T2O. NSQ_T2O (+) IS PPM. NSQ_T2O
and T51. NSQ_T51 (+) IS PPM. NSQ_T51
and TWU. NSU_STT (+) IS PPM. NSU_STT
and T01. NSQ_T01 (+) IS PPM. NSQ_T01
and vpm.cod_rmp_vpm (+) = "PRA".
and vpm.num_vsn_vpm (+) = PPM.vsn_sup
and w.nsu_ppm = A.nsu_ppm (+)
and W.NSU_SOO = A_HEADER. NSU_SOO and A_HEADER. NOR_SOM = 0Yes, it's exactly what I was talking about.
Transposing the logic for XQuery 1.0 is not the approach more simple (to say the least), because there is no direct support OUTER JOIN.
XQuery 3.0 provides the functionality, but it is not yet here in the database.My suggestion would be to stick to the publication of SQL/XML functions.
If you have a specific question about the performance, we (as the members of the forum) will be happy to help you.
Provides the steps necessary to reproduce the problem, including some examples of data.Kind regards
Marc.
-
PL/SQL function for the addition of "days."
I created a function that, at a date and a number, adds many days to the date. The problem is that there are parameters to include Saturday, Sunday or Monday as these days. Here is an example of the call
DAYSBETWEEN('01-Aug-11',5,0,0,0) will give 5 calendar days since August 1, 2011 (that you would not exclude Saturday, Sunday or Monday)
DAYSBETWEEN (August 1, 11 ', 5, 1,1,0) would give you 5 working days since August 1, 2011
DAYSBETWEEN('01-Aug-11',5,0,1,1) would give you 5 days of August 1, 2011 spring break Sunday and Monday.
My current role is:
This works for a small set of values for the date, but when there is a bigger set of dates, it takes hours to complete because of the time loop and multiple or statements.create or replace FUNCTION DAYSBETWEEN( DAYIN IN DATE , ADDNUM IN NUMBER , EXSAT IN NUMBER , EXSUN IN NUMBER , EXMON IN NUMBER ) RETURN DATE IS dtestart DATE; intcount NUMBER; holidays NUMBER; BEGIN dtestart := DAYIN; intcount :=1; WHILE intcount <= ADDNUM LOOP dtestart := dtestart + 1; IF NOT((EXSAT = 1 AND TO_CHAR(dtestart, 'd')= 7) OR (EXSUN=1 AND TO_CHAR(dtestart, 'd')= 1) OR (EXMON=1 AND TO_CHAR(dtestart, 'd')= 2)) THEN intcount := intcount + 1; END IF; END LOOP; RETURN dtestart; END DAYSBETWEEN;
Y at - it another game of logic, I could use to improve this query, using possibly not the while loop / or statements?Hi again:
This is the query, reformatted in the form of a function, exectuing the same thing I did in the above query:
SQL> CREATE OR REPLACE FUNCTION daysbetween 2 ( 3 dayin IN DATE , 4 addnum IN NUMBER , 5 exsat IN NUMBER , 6 exsun IN NUMBER , 7 exmon IN NUMBER ) 8 9 RETURN DATE 10 11 IS 12 13 dtestart DATE; 14 intcount NUMBER; 15 holidays NUMBER; 16 17 BEGIN 18 19 WITH all_dates AS 20 ( 21 SELECT LEVEL AS days_to_add 22 , dayin 23 , dayin + LEVEL AS new_dt 24 , addnum 25 , exsat 26 , exsun 27 , exmon 28 FROM dual 29 CONNECT BY LEVEL <= addnum * 2 30 ) 31 , exclusions AS 32 ( 33 SELECT ROW_NUMBER() OVER ( ORDER BY new_dt) ordering 34 , addnum 35 , new_dt 36 , TO_CHAR ( new_dt, 'DY' ) 37 FROM all_dates 38 WHERE 1=1 39 AND TO_CHAR ( new_dt, 'DY' ) != DECODE ( exsat, 1, 'SAT', 'XXX') 40 AND TO_CHAR ( new_dt, 'DY' ) != DECODE ( exsun, 1, 'SUN', 'XXX') 41 AND TO_CHAR ( new_dt, 'DY' ) != DECODE ( exmon, 1, 'MON', 'XXX') 42 ) 43 SELECT MAX( new_dt ) 44 INTO dtestart 45 FROM exclusions 46 WHERE ordering <= addnum; 47 48 RETURN dtestart; 49 50 END daysbetween; 51 / Function created. SQL> SELECT daysbetween ( DATE '2011-08-01', 150, 1, 0, 1) FROM DUAL; DAYSBETWE --------- 26-FEB-12 1 row selected.
The only variable not factored is holiday, but I saw that you were for them in your LOOP function either.
Due to the nature and variability holiday, it is better to have a table with the listed holidays, and those who could be elminated of charges together in the same 'exculsions' query where I used the TO_CHAR and DECODE to exclude the Fri, sat and Sun.
Maybe you are looking for
-
I don't remember not how I put in place, but my to-do list was in a bar side, accessible from the view menu on the left side of the page. It was listed on view > sidebar. Now, all I see are history and bookmarks.
-
Simple Handler.vi error ignores the error code?
I'm trying to understand the behavior of Simple Error Handler.vi, and it confuses me because it seems not be properly error code I give. According to the documentation, if I have an error code, then: If error in indicates an error, the VI ignores the
-
How to install rom 4.1 enigma n 4.2 in p xperia with bootloader locked?
How to install rom 4.1 enigma n 4.2 in p xperia with bootloader locked? If anyone knows please tell the steps, don't post juice link xda developers, cz I tried before posting here
-
How to import personal DVD videos?
I have a personal DVD that was made for me and I want to make copies. Whenever I charge it only seems to be able to do is to play the DVD. How can I import it so that I can make copies for friends and family? Thank you Anne
-
System reserve partition is created during installation to Win7 Pro?
I would like to know how not to create partition reserve system during installation to Win7 Pro. Does anyone have any suggestions?Thanks in advance for your suggestions