I've 2 identical tables of 300+ columns each,and each of table is having pk as combination of 2 fields.There are some fields where data is not matching. need a query which will use these two tables and return the following-
We have employee salary table which will have salary of an employee on daily basis (only working days). Below is the table structure:
emp_salary ---------- emp_id NUMBER(15) NOT NULL effective_date DATE NOT NULL salary NUMBER(15) NOT NULL Primary key - emp_id, effective_date This table is yearly partitioned
I have to find out how long the salary is not changed for an employee from given date, and last salary. I am using below query to do this:
WITH salary_tab AS (SELECT effective_date, salary, (CASE WHEN (LAG (salary) OVER (PARTITION BY emp_id ORDER BY effective_date ASC) = salary ) THEN 0 ELSE 1 END ) changed_ind FROM emp_salary WHERE emp_id = 12345 [code]....
The cost of this query is 1677 and it is taking around 60 msec to complete. When I run this query for around 2000 employees in a loop it is taking around 3 minutes to complete.
The main bottleneck of this query is in the with clause where I am processing the entire history instead of stopping after first change.
A B ---------- ---------------------------------------- 1 Hello 2 Hello 3 No Hello 4 No Hello 5 Hello 6 Hello 7 Hello
I want to print the output of this table as -->>
A B ---------- ---------------------------------------- 1 2 Hello 3 4 No Hello 5 6 7 Hello
To make it more clear, I just want that whenever the value f column "B" changes then only its value should be printed, else it should be NULL. And if "B" has same value for all the records then the value of "B" should be printed at the last.
I have two primary key values based on that I would need to query at least 25+ tables(each of these tables might have both primary key columns or either one to query) to extract data for my 150 columns and load it onto my target table.
WITH table1 AS ( SELECT 345 id, To_Date('1/31/2010', 'mm/dd/yyyy') dt, 123 cid, 'test' txt FROM dual UNION ALL SELECT 345 id, To_Date('2/1/2010', 'mm/dd/yyyy') dt, 121 cid, 'test2' txt FROM dual UNION ALL SELECT 345 id, To_Date('2/2/2010', 'mm/dd/yyyy') dt, 112 cid, 'test3' txt FROM dual UNION ALL SELECT 345 id, To_Date('2/3/2010', 'mm/dd/yyyy') dt, 162 cid, 'test4' txt FROM dual UNION ALL
as you can see, i want to join both tables (table1 and ov_dates) and take dt from ov_dates table look it up in table1 and thengrap ov_dt and looking up in table1 and copy values of one row to the other.
for example, in ov_dates i have 3/31 dt and 4/7 ov dt. i will look for 3/31 and 4/7 row in table 1 and copy columns values from 4/7 to 3/31you can see that cid for 3/31 stay the same (since i dont want to replace the value) but txt value was replace with value from 4/7
another examplein ov_dates we have 1/31 dt and 2/5. so i go into table1 get 1/31 and 2/5 row and copy values from 2/5 into 1/31/ as you can see the txt column value for 1/31 becametest6 since it was taking from 2/5. the same thing for the rest ofdata
I've recieved a recent request wherein the requirement is to swap values between columns across multiple tables in a database.Following is a visual sample of what needs to be done.
I have 3 tables in the Oracle database( emp, employee, emp1) which has following record values in it.
empidenamejob 7369, 'SMITH', 'CLERK'
I would like to list these 3 tables thru SQL/PLSQL, having the above record values combination. Also, the name of the columns could be different in all the tables i.e. name could be 'ename' in Emp table , and 'name' in Employee table. Is there way to do this in SQL or PLSQL ?
Holiday_master table has the list of holiday dates as "From_Date"
I have the form based on the Leave_Transaction Table, and I have created the Process, as "On-submit-after computations and validations" and posted the following PLSQL code,
declare days number(3); ex_days emp_master.remaining_days%type; new_rem_days emp_master.remaining_days%type; begin
[code]....
If the Dates is between from_date and To_date comes in Saturday and sunday and/or if any Date is exist in the Hpliday_master table it will exclude and return the count(*) remaining dates, For example,
If the From_date is 04-may-2012' and To_date is 08-may-2012,
Here the dates 5th may and 6th may are "saturday" and "sunday"
and if any date between From_date and To_date is exist in Holiday_Master Table i.e say here it is 07-may-2012, Then the remaining dates are(excluding sat,sunday and dates in holiday_table),
04-may-2012, 08-may-2012.
so the count(*) is 2.
I am using the above code but still it returning 5,I think this
...where to_char(dt,'fmday') not in ('sunday','saturday') minus (select holiday_start from holiday_master))
We have employee salary table which will have salary of an employee on daily basis (only working days). Below is the table structure:
CODEemp_salary ---------- emp_id NUMBER(15) NOT NULL effective_date DATE NOT NULL salary NUMBER(15) NOT NULL
Primary key - emp_id, effective_date..This table is yearly partitioned...I have to find out how long the salary is not changed for an employee from given date, and last salary. I am using below query to do this:
CODEWITH salary_tab AS (SELECT effective_date, salary, (CASE WHEN (LAG (salary) OVER (PARTITION BY emp_id ORDER BY effective_date ASC) = salary
[code]....
For emp_id 1, if we ran this query for 10/31/2011, then it has to compare the 10/31 salary with 10/29 and do the same until the salary mismatches. In this case, salary salary mismatch occurs on 10/20, so the stale salary period is from 10/31 to 10/21 which is 7 days.Below query will give that result:
CODE WITH salary_tab AS (SELECT effective_date, salary, (CASE WHEN (LAG (salary) OVER (PARTITION BY emp_id ORDER BY effective_date ASC) = salary
We are trying insert records from a select query in to temporary table, some of the records is missing in the temporary table. The select statement is having multiple joins and union all which it little complex query. In simple terms the script contains 2 part 1st Part Insert in to temporary table 2nd part Select query with multiple joins, inline sub queries, unions and group by classes and conditions Eg. If we execute select statement alone it returns some count for example => 60000 After inserting into the temp table, in temp table the count is around 42000 why is the difference?
It is simple bulk inserts... insert in to temp table select * from xxx. also, there is no commit in between. The problem is all the records populated by the select statement are not inserted in to temp table. some records are not inserted.
Also, we had some other observation. It only happens in its 2nd execution and not its first run. Hope there might be some cache problem Even, we also did not believe that. We are wondering. In TOAD, we tested however at times it happens. In application jar file, after "insert in to temp select * from xxx" we take the i. record count of temp table and ii. record count of "select * from xxx" separately but both doesn't match. Match only at 1st time.
CREATE OR REPLACE TYPE MF_RECORD_TYPE IS OBJECT (name VARCHAR2(6), . . . CREATE OR REPLACE TYPE MF_TABLE_TYPE IS TABLE OF mf_record_type;
Then in my stored procedure:
v_mf_record MF_TABLE_TYPE := MF_TABLE_TYPE(); . . OPEN mf_detail; FETCH mf_detail BULK COLLECT INTO v_mf_record; CLOSE mf_detail;
[code]....
I am getting the error: PLS-00386: type mismatch found at 'V_MF_RECORD' between FETCH cursor and INTO variables.
The thing is, that type I defined is like 90 columns, and I'm trying to avoid having to list all those columns individually in the FETCH or when I retrieve the data.
I had two installations of Oracle on my server (10.2.0.4 and 11.2.0.1) under different linux users. The Databases used different listeners on different ports.
I upgraded my Oracle 11g to 11.2.0.3 successfully two weeks ago. However today I just checked that I couldnt reload my Oracle 10g Listener. On further analysis (lsnrctl status) I discovered that my 10g listener's version was "TNSLSNR for Linux: Version 11.2.0.3.0" . My Start Date from lsnrctl gives me the date when my Oracle 11g was upgraded.
Now I have tried to reload my 11g listener which works normally. I cannot reload my 10g listener (TNS-01190: The user is not authorized to execute the requested listener command). When i run ps command there is no process on my server for my 10g listener. I can only see my 11g listener process after running ps command. However everybody can ping my databases on Oracle 10g but i cannot identify or kill my listener process even on server level.
select profilename from PROFILE where user_data like '%DATE_RULE!115%';
Output will be "Test A".Now, this is just a single value from RULES table used to find the data of PROFILE table.I will have to run the query on multiple values of RULES tables to find records containing a string format of sort "DATE_RULE!<rule_no>". How to search on WILD CARDs like these?
I am using an query to fetch the data from oracle DB and fill dataset using oledb dataadapter in ASP.net.When i run the same query in PL/SQL i am getting 14952 records,but when i am filling it to dataset i am getting only 13700 records.
ORA-31180: DOM Type mismatch in invalid PL/SQL DOM handle
I am getting this error while debugging one of the package in PL/SQL developer or in TOAD. Is there any setting which we need to perform at the database level to debug the packages which have the code related to XML DOM. I am asking as the same code works exactly fine at one of the test database and it gives the above error on the other database.
DECLARE JOBSFILE UTL_FILE.FILE_TYPE; CURSOR JOBSCUR IS SELECT * -- DDOCNAME,DDOCTITLE,DSECURITYGROUP,DDOCAUTHOR,DDOCTYPE,DINDATE,PRIMARYFILE,EXTRACTIONDATE,BATCH_ID FROM TARGET_UCM ; BEGIN JOBSFILE := UTL_FILE.FOPEN('FILES','JOBS.TXT','W'); UTL_FILE.PUT_LINE(JOBSFILE,'Action = insert'); FOR REC IN JOBSCUR [code]....
is there anyway to print the values of full table .i have used all column names to print .
I'm trying to create an output statement that will show that the update was successful, but everything that I'm trying doesn't seem to be working.
I have a procedure and an anonymous block that calls on the procedure.
So far after the begin in my anonymous block I have.
BEGIN procedure_name(variable1, variable2); dbms_output.put_line('Successfully Updated'); END;
Now I know that the procedure and the anonymous block without the dbms output works as the update takes place in the table, but I can't get any text string output to confirm this.