This question already has answers here:
How to print lines between two patterns, inclusive or exclusive (in sed, AWK or Perl)?
(9 answers)
Closed 5 years ago.
I need to capture the content of my alert log for lines starting with ORA-01555 and their related SQL statements.
The file content is below:
Sat Oct 21 12:11:40 2017
Thread 1 advanced to log sequence 143 (LGWR switch)
Current log# 5 seq# 143 mem# 0:
Sat Oct 21 12:12:22 2017
Thread 1 cannot allocate new log, sequence 144
Private strand flush not complete
Current log# 5 seq# 143 mem# 0:
Sat Oct 21 12:12:22 2017
ORA-01555 caused by SQL statement below (SQL ID: 1sfgms7z66zrs, SCN: 0x0401.1e45bbc4):
Sat Oct 21 12:11:48 2017
CREATE INDEX AAD_SAA_ADB_RESULTS_AUD_GTI1 ON AAD_PS_SAA_ADB_RESULTS_AUD_GT (
rpt_date
)
Sat Oct 21 12:20:56 2017
Thread 1 advanced to log sequence 153 (LGWR switch)
Current log# 6 seq# 153 mem# 0:
+REDO_VOL1/DSS1STG/ONLINELOG/group_6.262.957710915
Current log# 6 seq# 153 mem# 1:
+REDO_VOL1/DSS1STG/ONLINELOG/group_6.263.957710917
Sat Oct 21 12:21:11 2017
ORA-01555 caused by SQL statement below (SQL ID: 9ad5awvfvsfd9, Query
Duration=6444 sec, SCN: 0x0401.1e53de65):
Sat Oct 21 12:21:11 2017
SELECT a.EMPLID, a.TEST_ID, a.TEST_COMPONENT, a.SCORE
FROM
ODS_PSE.PS_STDNT_TEST_COMP a,
DSS_RDS.IR_STU_TST_SCR_SAT_VLD_DT_ST b
where
a.TEST_COMPONENT in ('VE','MA')
AND a.EMPLID = b.PRSN_UNIV_ID
AND ROUND(a.SCORE) = a.SCORE
AND a.TEST_ID = b.STU_TST_CD
AND a.TEST_DT = b.TEST_DT
AND a.LS_DATA_SOURCE = b.LS_DATA_SOURCE
UNION
SELECT a.EMPLID, a.TEST_ID, a.TEST_COMPONENT, a.SCORE
FROM
ODS_PSE.PS_STDNT_TEST_COMP a,
DSS_RDS.IR_STU_TST_SCR_SAT_VLD_DT_ST b
where
a.TEST_COMPONENT in ('ERWS','MSS','MT','RT','WLT')
AND a.EMPLID = b.PRSN_UNIV_ID
AND (
(ROUND(a.SCORE) = a.SCORE and a.TEST_COMPONENT in
('ERWS','MSS','RT','WLT'))
or (a.SCORE BETWEEN 10 AND 40 and a.TEST_COMPONENT in ('MT'))
)
AND a.TEST_ID = b.STU_TST_CD
AND a.TEST_DT = b.TEST_DT
AND a.LS_DATA_SOURCE = b.LS_DATA_SOURCE
Sat Oct 21 13:05:01 2017
Thread 1 advanced to log sequence 173 (LGWR switch)
Current log# 5 seq# 173 mem# 0: +REDO_VOL1/DSS1STG/ONLINELOG/group_5.257.957710909
Current log# 5 seq# 173 mem# 1: +REDO_VOL1/DSS1STG/ONLINELOG/group_5.256.957710911
The content I want to capture is:
ORA-01555 caused by SQL statement below (SQL ID: 1sfgms7z66zrs, SCN: 0x0401.1e45bbc4):
Sat Oct 21 12:11:48 2017
CREATE INDEX AAD_SAA_ADB_RESULTS_AUD_GTI1 ON AAD_PS_SAA_ADB_RESULTS_AUD_GT (
rpt_date
)
ORA-01555 caused by SQL statement below (SQL ID: 9ad5awvfvsfd9, Query
Duration=6444 sec, SCN: 0x0401.1e53de65):
Sat Oct 21 12:21:11 2017
SELECT a.EMPLID, a.TEST_ID, a.TEST_COMPONENT, a.SCORE
FROM
ODS_PSE.PS_STDNT_TEST_COMP a,
DSS_RDS.IR_STU_TST_SCR_SAT_VLD_DT_ST b
where
a.TEST_COMPONENT in ('VE','MA')
AND a.EMPLID = b.PRSN_UNIV_ID
AND ROUND(a.SCORE) = a.SCORE
AND a.TEST_ID = b.STU_TST_CD
AND a.TEST_DT = b.TEST_DT
AND a.LS_DATA_SOURCE = b.LS_DATA_SOURCE
UNION
SELECT a.EMPLID, a.TEST_ID, a.TEST_COMPONENT, a.SCORE
FROM
ODS_PSE.PS_STDNT_TEST_COMP a,
DSS_RDS.IR_STU_TST_SCR_SAT_VLD_DT_ST b
where
a.TEST_COMPONENT in ('ERWS','MSS','MT','RT','WLT')
AND a.EMPLID = b.PRSN_UNIV_ID
AND (
(ROUND(a.SCORE) = a.SCORE and a.TEST_COMPONENT in
('ERWS','MSS','RT','WLT'))
or (a.SCORE BETWEEN 10 AND 40 and a.TEST_COMPONENT in ('MT'))
)
AND a.TEST_ID = b.STU_TST_CD
AND a.TEST_DT = b.TEST_DT
AND a.LS_DATA_SOURCE = b.LS_DATA_SOURCE
Here is the grep I'm using but as you can see in the result it isn't capturing the content for each ORA-01555 line and its entire SQL statement. Not sure why my negative lookahead isn't quite working:
grep -Pzo 'ORA-01555.*\n(^.*[0-9]{2}:[0-9]{2}:[0-9]{2}.*)\n.*(?!.*[0-9]{2}:[0-9]{2}.*\n).+' alert.log
ORA-01555 caused by SQL statement below (SQL ID: 1sfgms7z66zrs, SCN: 0x0401.1e45bbc4):
Sat Oct 21 12:11:48 2017
CREATE INDEX AAD_SAA_ADB_RESULTS_AUD_GTI1 ON AAD_PS_SAA_ADB_RESULTS_AUD_GT (
ORA-01555 caused by SQL statement below (SQL ID: 9ad5awvfvsfd9, Query Duration=6444 sec, SCN: 0x0401.1e53de65):
Sat Oct 21 12:21:11 2017
SELECT a.EMPLID, a.TEST_ID, a.TEST_COMPONENT, a.SCORE
You can try this sed command.
sed -E '/ORA-01555/!d;:A;N;/\n[A-Za-z]{3} [A-Za-z]{3} [0-9]{2} [0-9]{2}:[0-9]{2}:[0-9]{2} [0-9]{4}$/!bA;:B;N;/\n[A-Za-z]{3} [A-Za-z]{3} [0-9]{2} [0-9]{2}:[0-9]{2}:[0-9]{2} [0-9]{4}$/!bB;s/(.*)\n.*/\1/' infile
If a line contain ORA-01555 --> keep in patern space.
Take the next line in patern space while it's not a date.
Keep the first date in the patern space.
Continue to take the next line while it's not a date.
Delete the last line in the patern space which is a date.
Print the patern space and return to the start to find a new line with ORA-01555.
awk solution:
awk '/ORA-01555/{ f=1 }f && /^[A-Z][a-z]{2} .* [0-9]{4}$/{ date++; if(date>=2) f=date=0 }f' alert.log
Related
I need to figure out a query that will compare two EFFECTIVE dates for a given patient number with different HMOs and determine which is the later date of the two and then populate a TERMINATION date field for only the older of the two effective dates with the last day of the previous month of the newer effective date of the two. This needs to be done across multiple patient, HMO, effective date combinations in a table.
SELECT * FROM tablename
The output is this:
HMO PATIENT EFFECTIVE TERMINATION
16 221135 01-APR-18
18 221135 01-OCT-17
12 251181 01-SEP-16
16 251181 01-MAR-15
12 271126 01-MAR-15
16 271126 01-DEC-16
12 291141 01-DEC-16
16 291141 01-FEB-19
12 391134 09-MAY-13
16 391134 01-APR-18
What I am trying to do via a query or queries is this:
HMO PATIENT EFFECTIVE TERMINATION
16 221235 01-APR-18
18 221235 01-OCT-17 3/31/2018
12 251381 01-SEP-16
16 251381 01-MAR-15 8/31/2016
12 2711126 01-MAR-15 11/30/2016
16 2711126 01-DEC-16
12 292241 01-DEC-16 1/31/2019
16 292241 01-FEB-19
12 391534 09-MAY-13 31-MAR-19
16 391534 01-APR-18
I've tried using a case statement but it is unsurprisingly creating four rows per patient, hmo combo and populating two of the rows with dates and leaving two blank:
SELECT DISTINCT
S.HMO
,S.PATIENT
,S.EFFECTIVE
,CASE WHEN S.EFFECTIVE > E.EFFECTIVE THEN LAST_DAY(ADD_MONTHS(S.EFFECTIVE, -1))
WHEN S.EFFECTIVE < E.EFFECTIVE THEN LAST_DAY(ADD_MONTHS(E.EFFECTIVE, -1))
ELSE NULL END AS TERMINATION
FROM tablename S INNER JOIN tablename E ON S.PATIENT=E.PATIENT
WHERE S.PATIENT =221135
Any ideas or advice would be welcome.
With sample data you posted:
SQL> select * from tablename order by patient, effective;
HMO PATIENT EFFECTIVE TERMINATIO
---------- ---------- ---------- ----------
18 221135 10/01/2017
16 221135 04/01/2018
16 251181 03/01/2015
12 251181 09/01/2016
12 271126 03/01/2015
16 271126 12/01/2016
6 rows selected.
such a MERGE might do:
SQL> merge into tablename a
2 using (select patient, max(effective) max_effective,
3 min(effective) min_effective
4 from tablename
5 group by patient
6 ) x
7 on (a.patient = x.patient)
8 when matched then update set
9 a.termination = x.max_effective - 1
10 where a.effective = x.min_effective;
3 rows merged.
Result is then
SQL> select * from tablename order by patient, effective;
HMO PATIENT EFFECTIVE TERMINATIO
---------- ---------- ---------- ----------
18 221135 10/01/2017 03/31/2018
16 221135 04/01/2018
16 251181 03/01/2015 08/31/2016
12 251181 09/01/2016
12 271126 03/01/2015 11/30/2016
16 271126 12/01/2016
6 rows selected.
SQL>
oracle version: 11.2.0.1.0
When I try to generate an AWR Report in Oracle use sysdba,
exec dbms_workload_repository.create_snapshot();
I keep getting this error:
ORA-00600: [kewrose_1], [600], [ORA-00600: [13013], [5001], [6213], [8465936], [5], [8447794], [17], [], [], [], [], []
], [], [], [], [], [], [], [], [], []
I am searching for a long time on net. But no use. Please help or try to give some ideas how to achieve this
conn / as sysdba
SQL> #$ORACLE_HOME/rdbms/admin/awrrpt.sql
SQL> #$ORACLE_HOME/rdbms/admin/awrrpt.sql
Current Instance
DB Id DB Name Inst Num Instance
----------- ------------ -------- ------------
3400239050 TEP 1 TEP
Specify the Report Type
AWR reports can be generated in the following formats. Please enter the
name of the format at the prompt. Default value is 'html'.
'html' HTML format (default)
'text' Text format
'active-html' Includes Performance Hub active report
Enter value for report_type: dec
Type Specified: dec
Instances in this Workload Repository schema
DB Id Inst Num DB Name Instance Host
------------ -------- ------------ ------------ ------------
* 3400239050 1 TEPCBC TEP oldman
Using 3400239050 for database Id
Using 1 for instance number
Specify the number of days of snapshots to choose from
Entering the number of days (n) will result in the most recent
(n) days of snapshots being listed. Pressing without
specifying a number lists all completed snapshots.
Entering the number of days (n) will result in the most recent
(n) days of snapshots being listed. Pressing without
specifying a number lists all completed snapshots.
Enter value for num_days: 1
Listing the last day's Completed Snapshots
Snap
Instance DB Name Snap Id Snap Started Level
TEP TEP 38542 20 Dec 2022 00:30 1
38543 20 Dec 2022 01:30 1
38544 20 Dec 2022 02:30 1
38545 20 Dec 2022 03:30 1
38546 20 Dec 2022 04:30 1
38547 20 Dec 2022 05:30 1
38548 20 Dec 2022 06:30 1
38549 20 Dec 2022 07:30 1
38550 20 Dec 2022 08:30 1
38551 20 Dec 2022 09:30 1
38552 20 Dec 2022 10:30 1
38553 20 Dec 2022 11:30 1
38554 20 Dec 2022 12:30 1
38555 20 Dec 2022 13:30 1
38556 20 Dec 2022 14:30 1
38557 20 Dec 2022 15:30 1
38558 20 Dec 2022 16:30 1
38559 20 Dec 2022 17:30 1
38560 20 Dec 2022 18:30 1
38561 20 Dec 2022 19:30 1
38562 20 Dec 2022 20:30 1
Specify the Begin and End Snapshot Ids
Enter value for begin_snap: 38542
Begin Snapshot Id specified: 38542
Enter value for end_snap: 38544
End Snapshot Id specified: 38544
Specify the Report Name
~~~~~~~~~~~~~~~~~~~~~~~
The default report file name is awrrpt_1_38542_38544.html. To use this name,
press <return> to continue, otherwise enter an alternative.
Enter value for report_name: test2
Using the report name test2
<html lang="en"><head><title>AWR Report for DB: TEP, Inst: TEP, Snaps: 38542-38544</title>
<style type="text/css">
body.awr {font:bold 10pt Arial,Helvetica,Geneva,sans-serif;color:black; background:White;}
I would like to add on to this code so that the value of the last measurement according to the "date" column in the "measurement" column is divided by the lowest value recorded in the measurement column and the result forms a new column. The current working code adds a column that subtracts the initial measurements from the other measurements in the "measurement" column if the "subject", "type" and "procedure" columns match. Thank you in advance.
data have;
input Subject Type Date $ 5-12 Procedure $ 15-22 Measurement;
datalines;
500 Initial 15 AUG 2017 Invasive 20
500 Initial 18 SEPT 2018 Surface 35
500 Followup 12 SEPT 2018 Invasive 54
428 Followup 2 JUL 2019 Outer 29
765 Seventh 3 JUL 2018 Other 13
500 Followup 6 NOV 2018 Surface 98
428 Initial 23 FEB 2018 Outer 10
765 Initial 20 AUG 2019 Other 19
610 Third 21 AUG 2018 Invasive 66
610 Initial 27 Mar 2018 Invasive 17
;
data want (drop=rc _Measurement);
if _N_ = 1 then do;
declare hash h (dataset : "have (rename=(Measurement=_Measurement) where=(Type='Initial'))");
h.definekey ('Subject');
h.definedata ('_Measurement');
h.definedone();
end;
set have;
_Measurement=.;
if Type ne 'Initial' then rc = h.find();
NewMeasurement = ifn(Measurement=., ., sum (Measurement, -_Measurement));
run;
Our Employee benefits have 5 Plan_Types, I need to put all the data into a view that looks like this:
`EMPLID YEAR SK PB VTO BV CT VC
-----------------------------------------------------
0199990 2017 23 22 5 0 169
0000004 2018 22 0 2 5 65
0199990 2017 5 34 34 0 55
0000004 2018 23 0 19 5 0
----------------------------------------------------
`
Here is the SQL for the above pivot table
`SELECT * FROM (SELECT b.emplid,
b.empl_rcd,
EXTRACT (YEAR FROM B.ACCRUAL_PROC_DT)
AS year,
DECODE (b.plan_type,
'50', 'SK',
'52', 'PB',
'5V', 'VTO',
'5Y', 'BV',
'5Z', 'CT',
'51', 'VC')
BANK,
B.HRS_CARRYOVER
+ B.HRS_EARNED_YTD
- B.HRS_TAKEN_YTD
+ B.HRS_ADJUST_YTD
+ B.HRS_BOUGHT_YTD
- B.HRS_SOLD_YTD
- B.HRS_TAKEN_UNPROC
+ B.HRS_ADJUST_UNPROC
+ B.HRS_BOUGHT_UNPROC
- B.HRS_SOLD_UNPROC
BALANCE
FROM ps_leave_accrual b)
PIVOT (SUM (balance) AS bal
FOR (bank)
IN ('SK', 'PB', 'VTO', 'BV', 'CT', 'VC'))
WHERE emplid in ('0199990','0000004');`
How do I turn this into a view I can use in PS Query. If I put this code into the view SQL, It fails at the Pivot point - "SQL command not properly ended "
To use non-standard code in views, we have different options:
We create the record definition and in the SQL we put the SQL, but comment it out, and reference our migration package information. When we build, we build manually as part of the migration process. I've seen folks use DMS to build the views.
We can create a SQL Object and reference it in the view sql using %SQL(M_CUSTOM_VIEW_SQL), that way the code is migrated with the project.
I have a table total_count with the following structure:
id studid month year acls_id total_p total_a
1 30 08 2015 12 5 2
2 35 08 2015 12 5 2
3 52 08 2015 12 5 2
4 53 08 2015 12 5 2
5 54 08 2015 12 5 2
6 55 08 2015 12 5 2
7 30 09 2015 12 3 0
In my view page, this table displays a list of all studid with their details.
Here is my edit method in controller.php:
foreach ($student as $student) {
$queryt= DB::table($wys_attendence_table)->where('studid', $student->id)
->where('adate', $date_exploded[0])
->where('amonth', $date_exploded[1])
->where('ayear', $date_exploded[2])
->update(array(
'attendence'=>Input::get($student->id),
));
}
My edit function works.
$lastUpdatedId= $queryt->id;
$lastUpdatedStudid= $queryt->studid;
var_dump($lastUpdatedId);
var_dump($lastUpdatedStudid);
Does not work..
How to get and display updated field id and studid value.
for eg: if I am editing studid=30 and studid=52,
I want to display id=1,3 and studid = 30,52.