Access Values from Previous or Following Rows in Oracle

Kiran P
Updated on 05-Dec-2020 06:34:42

194 Views

You want to use Oracle aggregate function XMLAGG for string aggregation.?Solution:You would like to include calculations based on preceding and following rows in the result set.Oracle supports the LAG and LEAD analytical functions to provide access to multiple rows in a table, utilizing preceding or following logic and you won’t need to resort to joining the source data to itself. To demonstrate the usage we will use the students data.The LAG function can be used to see which student/s joining followed another, and also to calculate the elapsed time between joining.SQL: Identify the student joining informationExampleSELECT first_name,       ... Read More

Run Multiple Async Tasks and Wait for Completion in C#

Nizamuddin Siddiqui
Updated on 05-Dec-2020 06:33:01

3K+ Views

The Task.WaitAll blocks the current thread until all other tasks have completed execution.The Task.WhenAll method is used to create a task that will complete if and only if all the other tasks have complete. In the 1st example, we could see that when using Task.WhenAll the task complete is executed before the other tasks are completed. This means that Task.WhenAll doesn’t block the execution. And in the 2nd example, we could see that when using Task.WaitAll the task complete is executed only after all the other tasks are completed. This means that Task.WaitAll block the execution.Examplestatic void Main(string[] args){   ... Read More

Generate Data Model from Data Dictionary Tables in Oracle

Kiran P
Updated on 05-Dec-2020 06:32:29

1K+ Views

Problem:You wanted to generate a data model from data dictionary tables in OracleSolution:The Oracle data dictionary is a collection of tables and related views that enable us to view the structure of the Oracle database. By querying these tables and views, we can obtain information about every object and every user of the database.IntroductionThe data dictionary is packaged with a series of views owned by the SYS user. These views, known as static data dictionary views, present information contained in tables that are updated when Oracle processes a Data Definition Language (DDL) statement.There is a second set of views known ... Read More

Difference Between All and Any in C# LINQ

Nizamuddin Siddiqui
Updated on 05-Dec-2020 06:30:58

2K+ Views

Any() method returns true if at least one of the elements in the source sequence matches the provided predicate. Otherwise, it returns false. On the other hand, the All() method returns true if every element in the source sequence matches the provided predicate. Otherwise, it returns falseExamplestatic void Main(string[] args){    IEnumerable doubles = new List { 1.2, 1.7, 2.5, 2.4 };    bool result = doubles.Any(val => val < 1);    System.Console.WriteLine(result);    IEnumerable doubles1 = new List { 0.8, 1.7, 2.5, 2.4 };    bool result1 = doubles1.Any(val => val < 1);    System.Console.WriteLine(result1);    Console.ReadLine(); }OutputFalse TrueExamplestatic ... Read More

Identify SQL Consuming More Resources in Oracle

Kiran P
Updated on 05-Dec-2020 06:30:12

2K+ Views

Problem:You want to identify the SQL statements consuming more resources in Oracle.Solution“V$SQLSTATS" view displays performance statistics for SQL statements that have recently executed. You can also use "V$SQL” and “V$SQLAREA" to report on SQL resource usage. "V$SQLSTATS” is faster and retains information for a longer period of time, but contains only a subset of the columns in “V$SQL" and "V$SQLAREA”.Exampleselect * from( select   sql_text  ,buffer_gets  ,disk_reads  ,sorts  ,cpu_time/1000000 cpu_sec  ,executions  ,rows_processed from v$sqlstats order by cpu_time DESC) where rownum < 20;

Dependency Inversion Principle and Its Implementation in C#

Nizamuddin Siddiqui
Updated on 05-Dec-2020 06:29:13

808 Views

High-level modules should not depend on low-level modules. Both should depend on abstractions.Abstractions should not depend on details. Details should depend on abstractions.This principle is primarily concerned with reducing dependencies among the code modules.ExampleCode Before Dependency Inversionusing System; namespace SolidPrinciples.Dependency.Invertion.Before{    public class Email{       public string ToAddress { get; set; }       public string Subject { get; set; }       public string Content { get; set; }       public void SendEmail(){          //Send email       }    }    public class SMS{       public ... Read More

Display SQL Execution Progress with Execution Plan in Oracle

Kiran P
Updated on 05-Dec-2020 06:23:46

3K+ Views

Problem:You want to view where Oracle SQL is taking time within a SQL execution plan.SolutionWith Oracle 11g version, we can view SQL execution plan progress while the SQL is running. The “V$SQL_PLAN_MONITOR” view contains a row for each step of a SQL statement’s execution plan. Below SQL will help to view the execution plan along with the progress.The “V$SQL_PLAN_MONITOR" provides you with information on the steps that are using the most resources. The statistics in "V$SQL_PLAN_MONITOR” are updated every second.We can also generate a real time text, HTML, or even a XML report of query progress within an execution plan ... Read More

Determine Approximate Amount of SQL Work Left in Oracle

Kiran P
Updated on 05-Dec-2020 06:22:48

1K+ Views

Problem:You want to know how much longer a long running SQL might ake to finish.SolutionWe can use “V$SESSION_LONGOPS" view to know the approximate time of a query left to execute. "V$SESSION_LONGOPS” view displays the status of various database operations that have been running for longer than six seconds. Please note that this view give you only a rough estimate of when a SQL might complete.Exampleselect   a.username  , a.opname  , b.sql_text  , to_char(a.start_time, 'DD-MON-YY HH24:MI') start_time  , a.elapsed_seconds how_long  , a.time_remaining secs_left  , a.sofar  , a.totalwork  , round(a.sofar/a.totalwork*100, 2) percent from v$session_longops a     ,v$sql         ... Read More

Monitor Real-Time SQL Execution Statistics in Oracle

Kiran P
Updated on 05-Dec-2020 06:22:04

3K+ Views

Problem:You want to monitor currently executing SQL statistics in Oracle.SolutionIf your database is Oracle Database 11g, you can use the following query to select from the “V$SQL_MONITOR” to monitor the near real time resource consumption of SQL queries.The statistics in “V$SQL_MONITOR” are updated every second. This helps us to view the resource consumption as it updates. These statistics are gathered by default when a SQL statement runs in parallel or consumes more than 5 seconds of CPU or I/O time.The “V$SQL_MONITOR" view includes a subset of statistics contained in the "V$SQL”, “V$SQLAREA", and "V$SQLSTATS” views.The “V$SQL_MONITOR" view displays real-time statistics ... Read More

Limit Database Resources Per Session in Oracle

Kiran P
Updated on 05-Dec-2020 06:21:10

3K+ Views

Problem:You want to limit the amount of resources a user can consume in your database.SolutionTo limit the resources, we can follow below steps.We can use below SQL statement to view the current setting of RESOURCE_LIMIT in our database.select name, value from v$parameter where name='resource_limit';Create a profile to limit the resources and assign it to a user. It won’t limit the CPU utilization though.ExampleCREATE PROFILE test_profile LIMIT    SESSIONS_PER_USER          2    CPU_PER_SESSION            UNLIMITED    CPU_PER_CALL               300000    CONNECT_TIME           ... Read More

Advertisements