Calendar holiday table logic required in sql instead of pl sql
My fn_test function calculates the date of-1. And if it's a holiday according to the temp_calendar of the table, and then call it recursively the fn_test again to-1. In this case until I get a holiday, no date.I've implemented as follows:
But I can have a single SQL do which is more effective?
Drop table temp_calendar;
Create table temp_calendar)
Identification number,
date of vacation);
Insert into temp_calendar values (1, "January 5, 2012'");
Insert into temp_calendar values (1, ' 6 January 2012');
Insert into temp_calendar values (1, 10 January 2012 ');
Insert into temp_calendar values (1, ' 2 February 2012');
Insert into temp_calendar values (1, 11 February 2012 ');
Commit;
FUNCTION to CREATE or REPLACE fn_test (in_date IN DATE)
DATE OF RETURN
IS
v_pr_day DATE;
BEGIN
v_pr_day: = in_date-1;
BY Calendar_Dates (holiday SELECT FROM temp_calendar)
LOOP
IF (v_pr_day = Calendar_Dates.holiday)
THEN
v_pr_day: = fn_test (v_pr_day);
END IF;
END LOOP;
RETURN TRUNC (v_pr_day);
END fn_test;
/
Select double fn_test('8-JAN-2012'); -Returns Jan. 7 as no holiday in the temp_calendar table.
But select double fn_test('7-JAN-2012'); -Returns Jan 6 4 and 5 is holidays in the temp_calendar table.
Thank you...
Hello
It could do:
create or replace FUNCTION fn_test (in_date IN DATE)
return date
is
l_ret date;
begin
select startdt-1
into l_ret
from (
select min(holiday) startdt, max(holiday) enddt
from (
select id, holiday, holiday-(row_number() over (order by holiday)) grp
from temp_calendar
)
group by grp
) v
where in_date-1 between startdt and enddt;
return l_ret;
exception when no_data_found then
return in_date-1;
end fn_test;
/
Test:
[11.2] Scott @ My11g > l
1 declare
2 l_date1 date := to_date('8-JAN-2012','dd-Mon-yyyy');
3 l_date2 date := to_date('7-JAN-2012','dd-Mon-yyyy');
4 begin
5 null;
6 dbms_output.put_line(l_date1 ||' => '||fn_test(l_date1));
7 dbms_output.put_line(l_date2 ||' => '||fn_test(l_date2));
8* end;
[11.2] Scott @ My11g > /
08/01/2012 00:00:00 => 07/01/2012 00:00:00
07/01/2012 00:00:00 => 04/01/2012 00:00:00
PL/SQL procedure successfully completed.
Elapsed: 00:00:00.02
Tags: Database
Similar Questions
-
A question about the count of several lines of table in a PL/SQL block
Hi all
I have a problem on counting the rows from several tables in a PL/SQL block, and I would be grateful if you could kindly give me a helping hand. Here's my problem: file in Microsoft Excel (one column) I have a list of several names of tables. For each table, when the number of rows is equal to 10000 I have to call a procedure. Here's how I tried to do:
I already checked this code with tables inividual and it works. The only problem isDECLARE CURSOR tb_cursor IS WITH my_table_names AS ( SELECT 'table1' AS tbname FROM DUAL UNION SELECT 'table2' AS tbname FROM DUAL UNION SELECT 'table3' AS tbname FROM DUAL UNION SELECT 'table4' AS tbname FROM DUAL UNION . . Here I continue writing one line for each table in order . to have the table names stored in my Excel file as a table to be queried by SELECT statement . ) SELECT * FROM my_table_names; BEGIN -- Here I verify that for each table having more than 10000 lines -- I call the specified procedure which is needed FOR I IN tb_cursor LOOP DECLARE -- Here I declare a cursor for counting the number of rows CURSOR currentTableRowCounter IS SELECT COUNT(*) AS rowsNum FROM I.tbname; numberOfRows currentTableRowCounter%ROWTYPE; BEGIN OPEN currentTableRowCounter; FETCH numberOfRows INTO numberOfRows; CLOSE currentTableRowCounter; IF (numberOfRows.rowsNum > 10000) THEN -- And here I will call the procedure which has to be run END IF; END; END LOOP; END; /
Indeed, oracle considers "I.tbname" as an unknown table name (although he refers to by its exact name).. . . SELECT COUNT(*) AS rowsNum FROM I.tbname; . . .
How can I solve this problem? I mean, how to use a variable (in my example, I.tbname) as the table name in the FROM clause to query a table instead of explicitly write the name of the table?SQL> @script.sql FROM I.tbname; * ERROR at line 99: ORA-06550: line 99, column 12: PL/SQL: ORA-00942: table or view does not exist
Thanks in advance,
DariyooshReplace the following code:
DECLARE -- Here I declare a cursor for counting the number of rows CURSOR currentTableRowCounter IS SELECT COUNT(*) AS rowsNum FROM I.tbname; numberOfRows currentTableRowCounter%ROWTYPE; BEGIN OPEN currentTableRowCounter; FETCH numberOfRows INTO numberOfRows; CLOSE currentTableRowCounter; IF (numberOfRows.rowsNum > 10000) THEN -- And here I will call the procedure which has to be run END IF; END;
By the following:
Declare numberOfRows number; begin EXECUTE IMMEDIATE 'select count(*) from '||I.tbname into numberOfRows; IF (numberOfRows.rowsNum > 10000) THEN -- And here I will call the procedure which has to be run END IF; end;
Max
[My Italian blog Oracle | http://oracleitalia.wordpress.com/2010/01/10/crittografia-in-plsql-utilizzando-dbms_crypto/]Published by: Massimo Ruocchio, January 12, 2010 15:25
Added Variable Declaration -
Is it possible to import Windows calendar holidays. I know that cam with Outlook. I have Vista Home Premium.
Hi yankyhater,
Windows Vista does not feature of holidays in windows calendar. There are third party online software that can help you accomplish the task above.
Link below may interest you
Create a family calendar with Windows Vista
http://www.Microsoft.com/athome/organization/vistacalendar.aspxI hope this helps!
Halima S - Microsoft technical support.
Visit our Microsoft answers feedback Forum and let us know what you think. -
Cannot see the table in the p/sql procedure but can in normal sql
Hello
using 11.2.0.3
that sql format
Select schema_owner. < table > - it works in good sql and pl/sql get message table or view does not exist.
Other fine tables.
Y at - it a permission to have reference to the table in the pl/sql procedure rather than sql?
Thank you
Hello
I'm glad you solved the problem!
Don't forget to mark it as "answered". It will help others with a similar problem, and it will save time for people answering questions on this forum.
-
passage of table to procedure pl/sql-pls-00306 wrong number/types of args
its oracle 10.2 database;
I have a simple procedure with parameters of table based on the sql types.
for example
create or replace type vt_attrname is table of the varchar2 (50);
My call to the procedure now works when the table is empty;
whenever I bulk collect in my local table, I get a compilation error.
for example
If I pass null, the call works but obviously the array is empty.declare my_array vt_attrname; begin select label bulk collect into my_array from table_name where 1=1; my_proc(p_array=>my_array); -- syntax error end;
I read something about being incompatible between sqltypes and pl/sql varray.
How to work around this problem?
Most collect works very well.
A small example would be appreciated.Take a look at your code:
v_cardapplattrtag vt_attrname;
and the protototype of procedure:
ppt_cardapplattrtag IN VT_BPATTRNAME DEFAULT NULL
Amiel
-
Logical operations in SQL decode function?
Hello
Is it possible to perform logical operations in SQL decode function
as
' > '
' < '
' > ='
' < ='
'<>'.
not in
in
non-null
a null value
for example...
Select col1, order_by, decode (col1, > 10, 0, 1)
tab;
Select col1, order_by, decode (col1, <>0, 10, 1)
tab;
Select col1, order_by, decode (col1, not in (10,11,12), 0, 1)
tab;
Select col1, order_by, decode (col1, is set to null, 0, 1).
tab;
Kind regards
infantry
Published by: user780731 on April 30, 2009 12:07 AM
Published by: user780731 on April 30, 2009 12:07 AM
Published by: user780731 on April 30, 2009 12:08 AM
Published by: user780731 on April 30, 2009 12:08 AM
Published by: user780731 on April 30, 2009 12:09 AMexample:
select col1 ,order_by,case when col1 > 10 then 0 else 1 end from tab; select col1 ,order_by,case when col1 <> 10 then 0 else 1 end from tab; select col1 ,order_by,case when col1 not in (10,11,12) then 0 else 1 end from tab;
Regarding testing for null, decode the handles which, by default, anyway, so that you can get decode or case easily...
select col1 ,order_by,decode (col1, null , 0 , 1) from tab; select col1 ,order_by,case when col1 is null then 0 else 1 end from tab;
-
Re: How to make the values in the table as required
Hi all
I use JDev11.1.2.3.0
I have 5 TariffRate (LOV), quantity fields (text input), BillQuantity (text input), amount(input text), calculated quantity (text input). These fields are in the format.not table in the form.here, that the logic is
BillQuantity = quantity * calculated the amount
amount = quantity * calculated the quantity * TariffRate
Here rate rate, calculated quantity, quantity which is mandatory.but I am not able to set the amount and the amount calculated as mandatory.if I select tariffrate in LOV immediately asking amount and quantiy calculated when the property set to true, or quantity.hints.mandatory the problem is that I'm not able to select the value of tariff rate for the second time , now I need to select the quantity and the quantity calculated values first without selecting the rate rate.so how I can configure mandatory for quantity and calculated quantity.can someone help me please.
I guess you are hit by "required field" error because you refresh the dependent fields (for example, the amount and the calculated quantity) by PPR declarative (for example "partialTriggers" attributes of these fields in the tariff rates field reference). In this way, when you choose a new tariff, ADF Faces includes the fields of PPR - ed in the life cycle, they are validated and they result in errors of "required field".
You can work around this behavior in the following way:
- Remove attributes of mandatory fields that depend on the rate of "partialTriggers" (i.e. loose quantity and the quantity calculated rate by removing the attributes 'partialTriggers' of the Quatity field and calculated quantity);
- Add a ValueChangeListener for the rate field. In the ValueChangeListener add commands for programming up to date dependent fields, for example:
{} public void tariffRateValueChanged (ValueChangeEvent valueChangeEvent)
AdfFacesContext.getCurrentInstance () .addPartialTarget (quantityField);
AdfFacesContext.getCurrentInstance () .addPartialTarget (calculatedQuantityField);
}
This way ADF Faces will not include the quantity field and the quantity calculated in the life cycle JSF (and they will not be verified for non-empty values). I use this trick for a long time and it really works.
Dimitar
-
Business Model - Table logic Source
Can someone give me details on exactly when you would follow scenario 1 when modeling a logical table and exactly when you would follow scenario 2, and what is the main difference in behavior between the two. It would help if someone could illustrate with joins of equivalent sql tables.
Scenario 1
You drag a second physical column of table on the logical table. This causes an additional field will appear in this list of logical tables in columns from another table to the original and causes a second table to appear under the original table in the source folder.
Scenario 2
You drag a second physical table to the existing source of the logical table of a logic table. The source of physical table appears on the surface, the same as before, but when you examine its properties you will see that the second table was joined to it.
Thanks for your comments,
Robert.Scenario 1
---> It would be more economical and BI server is free to use his Intelligence to peak sources based on the extraction of columns in the criteria tab provide you do know the sources using the content tab.
In general, we're going to do this is when:
Extensions of dimension
Fragmentation
Global tableScenario 2
---> In this case we force Server BI go as we said (which forces to use joins) and can be intelligence not to use BI
In general, we're going to do this is when:
Of fact extensions
10 g; What measures are based on certain conditions based on the dimensions, so we might have to add/map them and make
version of Siebel Analytics we used to go the aggregations based on the logical columns, it is not more than 10 g and 11 g.Hope this helps
Published by: Srini VIEREN on 21 February 2013 09:17
-
I have a table and passes as below:
START DATE TOTAL NUMBER OF DAYS
11/10/2011 15:00 1
15/10/2011-05:00 1
2011-12-22 10:00 1
22/12/2011 11:00 2
30/12/2011-10:00 1
01/01/2012 01:00 1
01/01/2012 10:00 1
01/01/2012 16:00 2
02/01/2012 14:00 1
03/01/2012-15:00 1
04/01/2012-15:00 2
04/01/2012 18:00 1
I need to ask where the values in the table above
must return values as below:
I tried many ways, but not able to find the solution.
Kindly help me in this regard.
START DATE TOTAL NUMBER OF DAYS
11/10/2011 15:00 1
15/10/2011-05:00 1
22/12/2011 11:00 2
30/12/2011-10:00 1
01/01/2012 16:00 2
02/01/2012 14:00 1
03/01/2012-15:00 1
04/01/2012-15:00 2
the ultimate goal is to summarize the TOTAL number of DAYS column all the numbers in the second table... All jobs must be treated in the same query. I can't use the coding of java to process what my requirement should be included in the query that already exists.
Published by: 915175 on February 16, 2012 23:02select trunc(start_date), max(start_date), max(total_days) from tablename group by trunc(start_date);
Please check below is on my local site with you Test data:
SQL> SQL> with tablename as 2 ( 3 select to_date('10/11/2011 15:00' , 'mm/dd/yyyy hh24:mi') start_date, 1 total_days from dual union all 4 select to_date('10/15/2011 5:00' , 'mm/dd/yyyy hh24:mi') start_date, 1 total_days from dual union all 5 select to_date('12/22/2011 10:00' , 'mm/dd/yyyy hh24:mi') start_date, 1 total_days from dual union all 6 select to_date('12/22/2011 11:00' , 'mm/dd/yyyy hh24:mi') start_date, 2 total_days from dual union all 7 select to_date('12/30/2011 10:00' , 'mm/dd/yyyy hh24:mi') start_date, 1 total_days from dual union all 8 select to_date('1/1/2012 1:00' , 'mm/dd/yyyy hh24:mi') start_date, 1 total_days from dual union all 9 select to_date('1/1/2012 10:00' , 'mm/dd/yyyy hh24:mi') start_date, 1 total_days from dual union all 10 select to_date('1/1/2012 16:00' , 'mm/dd/yyyy hh24:mi') start_date, 2 total_days from dual union all 11 select to_date('1/2/2012 14:00' , 'mm/dd/yyyy hh24:mi') start_date, 1 total_days from dual union all 12 select to_date('1/3/2012 15:00' , 'mm/dd/yyyy hh24:mi') start_date, 1 total_days from dual union all 13 select to_date('1/4/2012 15:00' , 'mm/dd/yyyy hh24:mi') start_date, 2 total_days from dual union all 14 select to_date('1/4/2012 18:00' , 'mm/dd/yyyy hh24:mi') start_date, 1 total_days from dual 15 ) 16 select TO_CHAR(max(start_date),'MM/DD/YYYY HH24:MI') start_date , max(total_days) total_days from tablename 17 group by trunc(start_date); START_DATE TOTAL_DAYS ---------------- ---------- 10/15/2011 05:00 1 01/03/2012 15:00 1 12/30/2011 10:00 1 01/01/2012 16:00 2 10/11/2011 15:00 1 12/22/2011 11:00 2 01/04/2012 18:00 2 01/02/2012 14:00 1 8 rows selected. SQL>
Kind regards
Lifexisxnotxsoxbeautiful...Update: added test done to my database...
Edited by: lifexisxnotxsoxbeautiful Vithalani, on February 16, 2012 23:18
-
View of the existing tables logic model
Hello!
I'm new to the Oracle sql developer Data Modeler.
I use Version 2.1.1.64 of the oracle sql developer.
I've created connections to a scheme called "you".
I use this pattern for my development with apex 4 and oracle 10g xe.
For an application, I use this schema tables (I created these table with apex).
Now, I want to display the model logical and physical this tables with oracle sql developer Data Modeler.
I have not found a tutorial how to do this.
And I have no idea how start up!
Can someone help me?
Thank you!
GerhardI would recommend oyu get the most recent version. You can import existing templates using older versions of the Data Modeler but I don't know if it's available through SQL Developer in earlier versions.
I don't not know umbutu so help oyu it. For windows, that you just download the file and unzip it. When you start the exe file it will automatically migrate your connections.
-
Extraction of multiple logical records through sql loader
Hello gurus,
I have a few questions about the sql loader. I m totally new to this, I've never used, this is the first time that I m using
1.
How can I find the position of the character number or a number? I have to physically count the position? is it textpad metering or usage in a specific way to do this?
I know it sounds like a silly question... but I wanted to know if there is a better way to do
2.
---example data 1119 Smith 1120 Yvonne 1121 Albert 1130 Thomas The following control file extracts the logical records: INTO TABLE emp (empno POSITION(1:4) INTEGER EXTERNAL, ename POSITION(6:15) CHAR) INTO TABLE emp (empno POSITION(17:20) INTEGER EXTERNAL, ename POSITION(21:30) CHAR)
2 can it please contact what is the "null deptno = white if"? "»
I really appriciate it ~deptno POSITION(1:2) INTEGER EXTERNAL(2) NULLIF deptno=BLANKS,
Thank youHello
The NULLIF means white load as NULL
http://download.Oracle.com/docs/CD/B19306_01/server.102/b14215/ldr_field_list.htm#sthref1129
Not sure I understand your first question. Of course you know the file format, TextPad might be an ok tool to determine this format for a fixed-width file.
Concerning
Peter -
Wharton are logical, physical table Logical data Source
Hello
Can someone explain me in details what Wharton are logical table, given logical physical Source table.
Any help of qucik will be graetly appreciatedIn OBI, there are three layers - physical, Business Model and mapping (MDB) and presentation.
As the name of the physical layer contain mainly the physical appearance of the application as what connection to use, what schema (also the catalogue in the case of SQL server) for you connect and also which table to use. This layer confirms joins PK_FK for related tables. This layer represents mainly how the data was stored in the database layer.On top of this layer, you will have layer MDB. The place where all the work a developer begins. You will structure the accourding of tables for the needs of the company. The structure must be a STAR schema. All the entities in this layer are called logical because they are not directly to a database object that they provides a logical mapping to database entities. This becomes obvious when you use more than a logic Table Source (LTS) for your logical tables. A logical column may map to the number N of physical columns according to the context. You can also create unusable columns in this layer, which are quite logical in nature.
I do not write anything on the presentation layer as it is not in your question. :)
Hope this will help.
Kind regards
Somnath -
Requirements of SQL VWorkspace 8.6.1
I was going through the hardware and software requirements for vw 8.6.1 and he said: vworkspace management database can be hosted on SQL 2012 +. We have not the ability to upgrade the SQL Server at this time. Is it possible to host it on SQL 2008 R2? Someone has it already tried?
A few other questions:
The role of broker can be installed on the Windows Server 2012 R2 kernel? (Basic without the GUI edition)
VWorkspace service of catalyst for Hyper-v supports Hyper-V server? (Basic without the GUI edition)
in our environment, we use 8.6.1 with SQL 2008 r2 without problems.
-
Monitor a specific table in a ms-sql-server
Hi... is - that someone has already tried to control a table of ms sql server with a custom script? or is there already a model availlable or the module script?
would be the "cream" on top of monitoring :-)
Cheers, patrikThere are SQL for Foglight cartridges. You should check your license to see if you qualify for these cartridges. You can monitor the different databases, including Oracle, MS SQL, DB2 and others. Check with your vendor.
-dave -
Rename tables and columns in sql running that accessing these columns in the table.
Hello
Using oracle 11.2.0.3
We want to rename columns, tables and work just a sql scripts for this.
If sqls who have access to those running long tables/columns for example reports what is happening
Existing sql running, will work perfectly in that picked up sql before table/colum rename or will they crash if tables/columns renamed during them.
scripts wil take a few seconds to run maximum
Thank you
The only other activity that would go on select is against these tables/columns. No etl isnert/update/delete etc wil, which happened during the name change.
Only possible activities are report instructions srunning select.
Tried to run a long selection and rename that select while that was going on and got no error on the test system.
This is because certain statements does not place locks on tables or lines, so even if a session is reading data, another session can make some ddl (or dml) manipulation.
In this situation (with only selects, no other dml queries), renaming can be done, but the question remains, what the application code?
If it refers to old column names after name change operation, is no good.
Maybe you are looking for
-
Main problems after upgrading from XP to Vista on Qosmio F20
I have recently upgraded from XP to Vista on my Qosmio F20 and having problems. It seems that I lost the ability to change screen resolutions, to adjust the volume, brightness, etc. Basically, I lost the laptop functions. I also tried updating the BI
-
What causes a wifi connections go to saved when you try to connect. I tried to forget it, and restart options. Some wifi that I can connect to some that I can't. When I stay in now the wifi was the connection for days, now today it will record, once
-
EN blackBerry smartphones? Help, please
When I have a text field to type on my curve I see an EN box at the top of the screen in the right corner. He was not used to be there, I must have pressed something in a language or a dictionary definition. Does anyone know how to get rid of it? Tha
-
HTML5 does not not within player Oracle LMS
I use Adobe Captivate 8.1 to develop sensitive (HTML5) courses and publication on Oracle EBS LMS 12.1.I can see the course at IE11 browser without problem (with verified compatibility view).But when running courses in the LMS (Oracle LMS) drive I get
-
WINDOWS 8 PRO x 64 CAN NOT BE ACTIVATED
I had read and implemented what I read in some relevant posts on the subject, but I keep getting the following information: Error code: 0xC004F074 Error description: The Software Licensing Service reported that the product could not be activated. No