Chain replication using a sql function...
HelloIs 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
SIM
What 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
Tags: Database
Similar Questions
-
I need expert advice on writing a function of this requirement.
Guess it's my table named, SEARCH
STORE_ID PART_ID PART_NAM
1 100 "AAA".
1 200 'BBB '.
1 300 "CCC".
2 900 'MMM '.
OF 2 800 'YYY '.
3 400 'DDD '.
3 200 'BBB '.
3 100 "AAA".
I have only 3 stores separate with the ID 1, 2 and 3
I need to write a function such that I'll pass store_id and part_id and it should return the part_name.
my_fun (1,100) returns "AAA".
But there are chances that store_id went the calling procedure is incorrect, something like this... my_fun (4,900), there is no store with ID = 4. In this case, I need to watch the part_id assuming store_id is 2. If found return to part_name, if no data, assume that the base id is 3 and get the part_name, another newspaper error.
My_Func (4,900) should return "MMM", and
My_Func (5,400) should return "DDD".
Well, I wrote the work function, but it is ugly. Everything I do is every time, I take the County.
SELECT count (1)
in v_count
SEARCH
where part_id = p_part_id
and store_id = p_store_id;
County IF > 1 - indicates the existence of a record
THEN
SELECT part_nam
in v_part_name
SEARCH
where part_id = p_part_id
and store_id = p_store_id;
RETURN part_nam;
ON THE OTHER
SELECT count (1)
in v_count_2
SEARCH
where part_id = p_part_id
and store_id = * 2 *;
IF v_count_2 is > 1 - indicates the existence of the piece in store - 2
again use select it in to get the part_nam else
SELECT part_nam
in v_part_name
SEARCH
where part_id = p_part_id
and store_id = * 3 *;
While working, he looks very ugly. I don't know there's a better way to do this. Can anyone help?
Thank you
LIBERATORSo, everything you need inside a function would be something like...
select coalesce(t1.part_nam, t2.part_nam, t3.part_nam, 'Not Found') as part_nam into v_result from (select p_store_id as store_id, p_part_id as part_id from dual) r left outer join lookup t3 on (t3.store_id = 3 and t3.part_id = r.part_id) left outer join lookup t2 on (t2.store_id = 2 and t2.part_id = r.part_id) left outer join lookup t1 on (t1.store_id = r.store_id and t1.part_id = r.part_id)
where p_store_id and p_part_id are the parameters passed to the function and the v_result is a variable to the output of the query to
You can then test 'Not found' in your code and do whatever logging you must make as appropriate and take again the result of the function.
-
Can I use the SQL function while setting of passage in the links?
4.2.1
Hello
I have a report that is a hypertext link (using the column binding feature standard apex) to another page. One of the parameters (columns) I spend is a varchar column with & values. Now, there is a restriction on the passage, & in the apex in 4.2.1. I was wondering if we can use something as a replacement (COLUMN1 # #, ' & ','-')) in the connection settings?
Unfortunately, the column does not have an equivalent id that can be used.
All of the suggestions.
Thank you
Ryanryansun wrote:
4.2.1Hello
I have a report that is a hypertext link (using the column binding feature standard apex) to another page. One of the parameters (columns) I spend is a varchar column with & values. Now, there is a restriction on passage and in the apex in 4.2.1. I was wondering if we can use something like a replace(#COLUMN1#,'&','-')) in the connection settings?
Unfortunately, the column does not have an equivalent id that can be used.
All of the suggestions.
Thank you
RyanYou can create another field in your query that might contain the value "prepared" - you set this to be a hidden column in the report definition and use it in the URL.
-
assign a value to a text element using the PL/SQL function body
Hello
I want to assign a value to a text element using PL/SQL function body option in the Source elements. But the below error when I try to apply it.
Source code:
declare
name varchar2 (100);
Start
If v ("P3_CREHIDD") = 'Edit' then
Select ename in the name of cpy_emp where empno = v('P3_EMPNO2');
end if;
end;
ERR-1904 unable to calculate the default item: type = computation_type = function body declare name varchar2 (100); so start v ('P3_CREHIDD') = 'Edit' and then select ename in the name of cpy_emp where empno = v('P3_EMPNO2'); end if; end;.
Thank you
David.Hello
Your body of the function doesn't return anything.
Maybe it worksdeclare l_name varchar2(100); begin if v('P3_CREHIDD') = 'Edit' then select ename into l_name from cpy_emp where empno = v('P3_EMPNO2'); end if; RETURN l_name; end;
BR, Jari
-
How to use Pl/Sql in Discoverer report
Hello world
Would you be able to provide a flow of work and guidance how to use the sql function in right of discoverer of the creation of the function by using PLSQL Developer.
(I'm new to Oracle environment... Prev worked as analyst with Microsoft Access... takes PL/Sql class at school a few years ago)
We use Discoverer Desktop.
(a) dba just email for permission to create the pl/sql function.
(b) recently completed Discoverer Administrator installed on my pc.
can you pls add to the list:
c)....
d)....
etc. ?
TX for your help, sandraHi sandra,.
Its been ages've seen it here. How are you??
(c) creation of the function by using PLSQL developer
go through this link of creating functions
[http://www.techonthenet.com/oracle/functions.php]
(d) recording the discoverer function
GoTo Admin--> Tools--> Register PL / SQL--> functions import... Select your function and say apply
For more information about the functions, you can go through the tutorials
[http://download.oracle.com/docs/html/A90881_02/calculat.htm#1006629]
Hope this helps you.
Best wishes
Murielle. -
APEX shortcuts using the source of the body of the PL/SQL function
Hi all
Recently, I came across the feature of "Shortcuts" in the "Shared components" section of the APEX and thought great, somewhere to set the common/standard items once, then use these several times in different pages of my application.
This seemed to work correctly when you use the 'Source' of "HTML Text" or "HTML text with special characters escaped", but then I wanted to explore the use of the "Body of the PL/SQL function" option to create a more dynamic shortcut/variable on the base.
This is where I came across a particular problem in the APEX (Version 3.2.1.00.10 on GR 11, 2 on Oracle Enterprise Linux). When I set my shortcut, and then perform a reference to my shortcut (using "MY_SHORTCUT") in an area of a page, the value of shortcut is back, but is added with the reference variable (ie. the 'MY_SHORTCUT' chain).
For simplicity, my example looks like this (of course, my real world example is a bit more complicated, but this example produces the same error):
(a) I define my shortcut called "MY_SHORTCUT" and using the body of the PL/SQL function under "Source Type", define my procedure as "htp.p(:USER)."
(b) I then create a new page (basic HTML page), and a new region of the 'type'-> 'HTML Text (with shortcuts).
(c) in the "Source region", I define my shortcut like - "MY_SHORTCUT".
(d) I apply changes and then run the page.
I'll be back will be name of the current user with "MY_SHORTCUT" appended/added immediately after the user name - for example. the string:-' BRAD «MY_SHORTCUT»»
Question is - how to stop the shortcut/reference text "MY_SHORTCUT" to be added to the variable you want to see the and thereafter on your page? I am just wanting the variable, NOT the reference for the shortcut. I do something wrong using the HTP package, and if yes, what should I use?
If "MY_SHORTCUT" is defined as "HTML text with special characters escaped" (where I can refer to elements of application using the syntax '& USER.') so that everything works correctly. My reason for using the PL/SQL is to generate a more dynamic output variable, based on elements of application throughout the entire application - and of course the use of shortcuts to minimize coding and duplication.
Thanks in advance,
BradHello
The body of the PL/SQL function must RETURN a value.
Try:
RETURN :APP_USER;
Andy
-
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.
-
SQL using the analytic function
Hi allI want a help in the creation of my SQL query to retrieve the data described below:
I have a test of sample table containing data as below:
State ID Desc
MICHAEL 1 T1
ACTIVE 2 T2
T3 3 SUCCESS
DISABLE THE T4 4
The thing I want to do is to select all the lines with an ACTIVE status in the table but is there is no ACTIVE status, my request will give me the last line with MICHAEL status.
I can do this in a single request by using the analytical function for example, if yes can yiu help me on the request of unpacking.
Kind regards
Raluce
Something like that?
I had to fix it.
with testdata until)
Select 1 id, "T1" dsc "DISABLED" status of Union double all the
Select 2 id, 'T2' dsc, the status "ACTIVE" of all the double union
Select id 3, "T3" dsc, the status of 'SUCCESS' of all the double union
Select 4 id, "T4" dsc "DISABLED" status of double
)Select
ID
dsc
status
of testdata
where
status =
-case when (select count (*) in testdata where status = 'ACTIVE') > 0
then 'ACTIVE '.
Another 'DISABLED '.
end
and)
ID in (select id from testdata where status = ' ACTIVE')
or
ID = (select max (id) in testdata when status = 'DISABLED')
)STATE ID DSC
'2' 'T2' 'ACTIVE '.
Maybe it's more efficient
Select
ID
dsc
status
of testdata
where
status =
-case when (select count (*) in testdata where status = 'ACTIVE') > 0
then 'ACTIVE '.
Another 'DISABLED '.
end
and
ID =)
-case when (select count (*) in testdata where status = 'ACTIVE') > 0
then id
on the other
(select max (id) in testdata when status = 'DISABLED')
end
)Post edited by: correction of chris227
Post edited by: chris227
extended -
Use of the function of group in orcl:query sql - database - urgent
All,
Version: 10.1.3.4
Two requirements for me:
1. I want to use the sum function in orcl:query - database. How to use it?
For ex: I tried the following
< xsl: value-of select ='orcl:query - database ("select sum of emp", false (), false (), "jdbc/DB1")'/ >
I got the following error
oracle.xml.sql.OracleXMLSQLException: character ')' is not allowed in an XML tag name.
When I tried without the sum function, it works fine
2. I used the same table, but without the sum works as below
< xsl: value-of select ='orcl:query - database ("select emp salary", false (), false (), "jdbc/DB1")'/ >
This time, it returns the first salary employees! I don't understand this logic. I expected, either the query returns all rows, otherwise it throws the error, but none of them were real!
Can pls someone explain what behavior? I want your answer to both queries!
I am currently in a project where I work in the same scenario, so guru of let me know as soon as POSSIBLE.
Thank you
SenHello
have you tried to put an alias something like select Sum Total emp
-
Correct use of the function in the pipeline?
Hello
I have a function in the pipeline, I am using 11 g. the idea is I can pass in the name of a table, and it returns a set of rowcounts for this table
I obviously have something wrong, but what?
-Package
create or replace PACKAGE IS GetMigSamples
-set types for a record and an array of records like this
TYPE sample_record IS RECORD)
PERSON_ID NUMBER,
CF_ID VARCHAR2 (10),
number_of_records NUMBER);
TYPE sample_table IS the TABLE OF THE sample_record;
FUNCTION SP_MIG_SAMPLES (P_TABLE IN VARCHAR)
RETURN sample_table
IN PIPELINE;
END;
-Package body
create or replace PACKAGE GetMigSamples BODY IS
FUNCTION SP_MIG_SAMPLES (P_TABLE IN VARCHAR) sample_table RETURN PIPELINED IS
v_cur sys_refcursor;
v_rec sample_record;
v_migtable VARCHAR (64);
v_stmt_str VARCHAR2 (400);
v_col VARCHAR (64);
BEGIN
v_migtable: = P_TABLE;
-some tables have a different name for the foreign key column
v_col: = box
When v_migtable = "MYTABLE" then "MAIN_ID".
another end 'PERSON_ID ';
-build a sql query for this table and the foreign key column
v_stmt_str: = ' SELECT
MX.' | v_col |' like PERSON_ID,.
COALESCE (MX. Reference, "?") as CF_ID,.
Count (*) as number_of_records
OF ' | P_TABLE |' mx
GROUP BY mx.' | v_col;
-Open the query and loop through it, each line of pipes
Open the v_cur for v_stmt_str;
LOOP
EXTRACTION v_cur
IN v_rec;
EXIT WHEN v_cur % NOTFOUND;
PIPE ROW (v_rec);
END LOOP;
CLOSE V_cur;
RETURN;
End;
END GetMigSamples;
When I use it
Select getmigsamples.sp_mig_samples ('M_MY_TABLE') of double
I get
FW. SYS_PLSQL_228255_29_1()
Which I guess means that I have a reference to an object, rather than the actual values in the lines. I tried to corrrect it for centuries and have now arrived at the point of the tear-my-hair-out. Can anyone help please?
Thank you
When I use it
Select getmigsamples.sp_mig_samples ('M_MY_TABLE') of double
I get
FW. SYS_PLSQL_228255_29_1()
Which I guess means that I have a reference to an object, rather than the actual values in the lines. I tried to corrrect it for centuries and have now arrived at the point of the tear-my-hair-out.
No - this 'thing' you got is a hidden type of SQL Oracle automatically created to match the type of PL/SQL, that you used. SQL can only work with the SQL types defined at the schema level. But for functions PIPELINED Oracle allows you to specify the types of PL/SQL and it will create SQL HIDDEN types to make it work.
A pipeline function should be treated as a table. You must use the SCOREBOARD operator
Select * from table (myFunction);
Try this simple example
-type to match record emp
create or replace type emp_scalar_type as an object
(EMPNO NUMBER 4,
ENAME VARCHAR2 (10),
USE VARCHAR2 (9).
MGR NUMBER 4,
HIREDATE DATE,
NUMBER OF SAL (7, 2)
NUMBER OF COMM (7, 2)
DEPTNO NUMBER (2)
)
/
-records of the emp table
create or replace type emp_table_type to table of emp_scalar_type
/
-function of pipelined
create or replace function get_emp (p_deptno number)
return emp_table_type
PIPELINED
as
TYPE EmpCurTyp IS REF CURSOR RETURN emp % ROWTYPE;
emp_cv EmpCurTyp;
l_rec emp % rowtype;
Start
Open emp_cv SELECT * from emp where deptno = p_deptno;
loop
extract the emp_cv in l_rec;
When the output (emp_cv % notfound);
line of conduct (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))
See use of the SCOREBOARD operator?
-
Parse the JSON using PL/SQL string
I created a script that reads data from the Mobile App DB (which is based on MongoDB) of Oracle SQL Developer. The result is the string JSON stored in l_response_text VARCHAR2 (32767);
The string has the format such as:
[{"Postcode":"47100","OutletCode":"128039251","MobileNumber":"0123071303","_createdAt":"2014-11-10 06:12:49.837","_updatedAt":"2014-11-10 06:12:49.837"}, {"Postcode":"32100","OutletCode":"118034251", ..... ]
However, I need to analyze this l_response_text such that each table will in his column in a table called appery_test. appery_test table has the same number of columns pairs JSON and in the same order (e.g. name of the first column is 'postal Code')
I searched and I found most of the results on the analysis of the Oracle in JSON table and not the other way around. I found, however, that link which is somewhat similar to my problem. However, the library suggested in the answer doesn't have an example on how to use it to insert JSON into conventional table using PL/SQL.
N.B.: I use g 11 and not 12 c. If the functions built by are not available for me.
Thank you very much
Sorry, I am a novice in this area too.
However, it worked for me:
declare
l_list json_list;
l_data CLOB;
Code postal clob;
l_val json_value;
Start
-json data recovery
Select the data in l_data from jsons where id = 1;
l_list: = json_list (l_data);
I'm looping 1.l_list.count
l_val: = json_ext.get_json_value (json (l_list.get (i)), 'Postcode');
DBMS_LOB.CREATETEMPORARY (zip, true, 2);
json_value.get_string (l_val, postal code);
-Put some things
dbms_output.put_line (DBMS_LOB. GetLength (Postcode));
dbms_output.put_line (dbms_lob.substr (postal code, 20, 1));
DBMS_LOB.freeTemporary (Postcode);
end loop;
end;
47328
9J / / 4AAQSkZJRgABAQAA
Added dbms_lob.freetemporary (postcode);
-
ORA-06503: PL/SQL: function returned no value ORA-06512:
Hi all
SQL > set serveroutput on
SQL > CREATE OR replace FUNCTION qty_value (p_item_id number)
2 RETURN NUMBER
3 EAST
4 v_qty_arrival NUMBER;
5 BEGIN
6. SELECT THE CASE SENSITIVE OPTION
7. WHAT (SUM (b.quantity) - SUM (b.quantity_received)) < = 0 THEN 0
8 ELSE (SUM (b.quantity) - SUM (b.quantity_received))
9 END Qty_Arrival
10 INTO v_qty_arrival
Po_lines_all 11 a,
po_line_locations_all 12 b
13 WHERE a.po_line_id = b.po_line_id
14 AND a.item_id = p_item_id;
15 EXCEPTION
16 THEN THAN OTHERS THEN
17 v_qty_arrival: = NULL;
18 RETURN v_qty_arrival;
19 END qty_value;
20.
The function is created.
SQL >
SQL > select xxc_qty_arrivale (214960) double
2.
Select xxc_qty_arrivale (214960) double
*
ERROR on line 1:
ORA-06503: PL/SQL: function returned no value
ORA-06512: at the 'APPS '. XXC_QTY_ARRIVALE', line 19
Back AFTER using the exception block is fine as long as your code actually REACHED the exception block.
When there are no errors, then your code will not enter the exception block, but you still NEED to return a value, since it is what functions a function wants to return a value, that's what the functions are made for.
Spot the differences between the following 3 functions. Understand how they work.
The first function has only a return in the exception block but runs correctly. Result: error, because the back is missing in the code block.
The second function has a return in the exception block and one in the block of code and runs correctly. Result: no error, because the return is not missing in the code block.
The third function has a return in the exception block and one in the block of code and is forced into an error. Result: no error, because the return of the exception handler is used (instead of retriggering of the error, which you would normally do).
SQL > create or replace function myfunc
2 return number
3 as
4 start
5 dbms_output.put_line ('in the section of code');
6 null;
7 exception
8 then than others
9. can
10 dbms_output.put_line (' in the exception handler ' |) SQLERRM);
11 --
12 return 0;
13 --
14 end;
15.
The function is created.
SQL > select double myfunc;
Select double myfunc
*
ERROR on line 1:
ORA-06503: PL/SQL: function returned no value
ORA-06512: at "GHPLUS. MYFUNC", line 14
In the section of code
SQL > create or replace function myfunc
2 return number
3 as
4 start
5 dbms_output.put_line ('in the section of code');
6 null;
7 --
8 return 1;
9 --
10 exceptional
11 so that others
12. can
13 dbms_output.put_line (' in the exception handler ' |) SQLERRM);
14 --
15 return 0;
16 --
end 17;
18.
The function is created.
SQL > select double myfunc;
MYFUNC
----------
1
1 selected line.
In the section of code
SQL > create or replace function myfunc
2 return number
3 as
n number 4;
5. start
6 dbms_output.put_line ('in the section of code');
7 n: = 1/0; -force an error (zero divisor) to join the exception handler
8 --
9 return 1;
10-
exception 11
12 so that others
13. can
14 dbms_output.put_line (' in the exception handler ' |) SQLERRM);
15 --
16 return 0;
17 --
18 end;
19.
The function is created.
SQL > select double myfunc;
MYFUNC
----------
0
1 selected line.
In the section of code
In the handler for exception ORA-01476: divisor is equal to zero
SQL >
-
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
-
Is it possible that muse adobe to have a Back-End that connects to a database using MySQL, SQL, Access etc...
Nothing to do with the Muse at all. You have things backwards. If you use a dynamic interface, you work in the API hooks and predefined functions and that he don't just slap on an arbitrary HTML façade. It is simply not how it works.
Mylenium
-
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.
Maybe you are looking for
-
Why is my mac since update el capitanslow wifi ok on the cable
Since then until this day at el capitan slow on wifi ok on cable
-
Equium A100-027 - XP - mass storage controller driver?
Hello Re-installed Windows XP SP2 laptop respective, but one item in Device Manager is always crying out for drivers - "Mass Storage Controller". I seem to recall seeing the iSCSI initiator when Vista has been loaded, it is the same thing. Where can
-
Line ThinkPad T440 yellow on the screen
Hello I bought the laptop online and there is a vertical yellow we line screen. While searching the Internet for a fix that I noticed that the laptop is still under warranty. Who should I contact to have this problem, I'm in South Africa
-
Dv6-6C50US, tone of keyboard and keys do not work when you press on consecutively
Dv6-6c50US - windows 7 When I hit a key consecutively, it does only once. Example: I type 'business', it appears as "business". Same case with keys, including the arrow keys. I tried different options with character repeat in Control Panel, but no us
-
Internet Explorer hang ups and the desktop icons don't work
I have a 32-bit Vista, which has worked perfectly for almost 4 years until yesterday. Freeze the icons on my desktop and internet explore cannot open any other web site, after having opened the first web site. Once you close the web site, and then tr