If you aim at querying finding the nearest AWR snapshot that may be near the time an issue is reported on GitHub for further analysis, then you will require a table structure comprising of AWR data with its time stamp. Let’s assume you have a table awr_snapshots with the following structure: snapshot_id (It represents the identification of particular snapshot.) snapshot time (time taken for the AWR snapshort) Some of them are database_name, instance_name and so on. Now, if you want to find the snapshot closest to a specific timestamp,
here’s an example SQL query that could work for you:
SELECT snapshot_id, timestamp
FROM awr_snapshots
ORDER BY ABS(timestamp – TO_TIMESTAMP(:github_issue_timestamp, ‘YYYY-MM-DD HH24:MI:SS’))
FETCH FIRST 1 ROWS ONLY;
Explanation:
github_issue_timestamp is a placeholder of the time stamp of the issue raised in GitHub. This should be replaced with the real time when the GitHub issue was filed. ABS(timestamp – TO_TIMESTAMP(:((to_char(V.gh_issue_timestamp, ‘YYYY-MM-DD HH24:MI:SS’) – to_char(snapshot_time, ‘YYYY-MM-DD HH24:MI:SS’)) returns the time difference between the timestamps of the AWR snapshots as compared to the date of the GitHub issue. The arrows in the above predicate list show that the difference is ordered in an ascending manner by the ORDER BY clause itself.
FETCH FIRST 1 ROWS ONLY restricts it to a single nearest AWR snapshot. Ensure that the format used in defining your timestamp column in your query corresponds to that of the timestamp format in your database. Use the TO_TIMESTAMP format string if the TO_CHAR function is required to be used to adjust the format string.
Conclusion:
Function is a basic component of program that is used for making the code reusable, modular and manageable. Since they result in the naming of discrete logic blocks, functions dramatically reduce the amount of repetitive code, complicate complicated operations, and improve the legibilit
ALSO READ THIS: Sebastian Wagner Carena: Analyzing the Contributions Made by Certain Developer on GitHub