Articles on Trending Technologies

Technical articles with clear explanations and examples

How to validate the syntax of a Oracle dynamic SQL before execution ?

Kiran P
Kiran P
Updated on 04-Dec-2020 2K+ Views

Problem Statement:You want to validate the syntax of a SQL before execution.Solution: The DBMS_SQL default package allows SQL to be dynamically executed. Owned by SYS it has been defined with the AUTHID CURRENT_USER keyword so it runs with the privileges of the invoker. We can leverage DBMS_SQL.PARSE function to validate the syntax.We will first define a function to accept the SQL statement as the parameter and parse the SQL statement./*  * ---------------------------------------------------------------------------  *  Function : check_syntax  *    Input  : sql statement  *   Output  : Number  * ---------------------------------------------------------------------------  */    FUNCTION check_syntax     ( p_query IN CLOB ) ...

Read More

How to produce group subtotals for all combinations of the dimensions specified in Oracle?

Kiran P
Kiran P
Updated on 04-Dec-2020 322 Views

Problem Statement:You want to find out subtotals for all combinations of the dimensions specified in Oracle.Solution:The CUBE function will generate subtotals for all combinations of the dimensions specified. If “n” is the number of columns listed in the CUBE, there will be 2n subtotal combinations.We will begin by create the necessary data for this requirement.Example-- Drop table DROP TABLE atp_titles; -- Create table CREATE TABLE atp_titles (   player             VARCHAR2(100) NOT NULL,   title_type         VARCHAR2(100) NOT NULL,   titles             NUMBER NOT NULL);Example-- insert ...

Read More

How to produce group subtotals and a grand total in Oracle?

Kiran P
Kiran P
Updated on 04-Dec-2020 5K+ Views

Problem Statement:You want to find out totals, subtotals and a grand total in Oracle.Solution:Oracle ROLLUP function performs grouping at multiple levels, using a right to left method of rolling up through intermediate levels to any grand total. To demonstrate the ROLLUP function we will create a table to hold tennis player along with the ATP tour titles and Grandslam titles acheived by the player.We will begin by create the necessary data for this requirement.Example-- Drop table DROP TABLE atp_titles; -- Create table CREATE TABLE atp_titles (   player             VARCHAR2(100) NOT NULL,   title_type ...

Read More

How to find and replace text in Oracle?

Kiran P
Kiran P
Updated on 04-Dec-2020 7K+ Views

Problem Statement: You want to find and replace a string in Oracle.Solution:Function: TRANSLATESyntax: TRANSLATE(expr, from_string, to_string)TRANSLATE funtion in oracle allows you to make many single character, one on one substitutions in a single operation.However, the to_string and from_string values must not be empty, if an empty string is passed to TRANSLATE Function, Oracle Database interprets the empty string as null and returns null./* replace all occurances of b with j in below string */ SELECT 'back and bill ' AS original_string        , TRANSLATE('back and bill', 'b', 'j') AS replaced_string   FROM dual;Outputback and bill   jack and ...

Read More

How to identify rows that are not parents of any other rows in a Hierarchy table in Oracle?

Kiran P
Kiran P
Updated on 04-Dec-2020 327 Views

Problem Statement: How to identify leaf rows in a Hierarchy table i.e. rows that are not parents of any other rows.Solution: Oracle provides CONNECT_BY_ISLEAF clause to identify rows that are not parents of any other rows. To begin with let us see how does a connect_by_isleaf works.SQL:/*   Function - Example to show if the row is parent of any other rows or not   Tables Used - students Data - Documented below */ SELECT student_id,        level,        CASE WHEN connect_by_isleaf = 0             THEN 'Yes'         ...

Read More

How to remove a branch with in a hierarchy of data in Oracle?

Kiran P
Kiran P
Updated on 04-Dec-2020 667 Views

Problem Statement: You need to traverse the hierarchy data from top to bottom but doesn’t want a particular branch in the output.Solution: We will look at couple of examples for this problem statement.Oracle provides CONNECT BY clause to specify a hierarchical query i.e. how to connect the parent nodes and child nodes and the PRIOR operator to define the join condition/s between the parent nodes, and the LEVEL pseudo-column to indicate how far from the root/parent row the current row is.Additionally, we can use the START WITH clause to indicate where to start the tree navigation. We must use the PRIOR ...

Read More

How to traverse Hierarchical data in Oracle?

Kiran P
Kiran P
Updated on 04-Dec-2020 965 Views

Problem Statement: You need to traverse the hierarchy data from top to bottom marking the level of each row in the hierarchy.Solution:Oracle provides CONNECT BY clause to specify a hierarchical query i.e. how to connect the parent nodes and child nodes and the PRIOR operator to define the join condition/s between the parent nodes, and the LEVEL pseudo-column to indicate how far from the root/parent row the current row is.Additionally, we can use the START WITH clause to indicate where to start the tree navigation. We must use the PRIOR operator to specify the column/s in the parent row that have ...

Read More

Count of operations to make a binary string "ab" free in C++

Sunidhi Bansal
Sunidhi Bansal
Updated on 02-Dec-2020 384 Views

We are given a string which can contain “ab” and the task is to calculate the count of operations required to remove or delete “ab” from the string. So, our task is to firstly check whether the string contains “ab” or not if yes then we have to make string “ab” free.Input − string str = "ababaa"Output − Count of operations to make a binary string “ab” free are − 4Explanation − As we can see in the string “ab” pattern is occurring two times so we will replace “ab” with “bba” so the count of operations is 1 and ...

Read More

Count rotations of N which are Odd and Even in C++

Sunidhi Bansal
Sunidhi Bansal
Updated on 01-Dec-2020 242 Views

We are given a number N. The goal is to count the rotations of N that make an odd number and rotations that make an even number. If the number N is 123 its rotations would be 123, 321, 132. The odd rotations are 123 and 321 ( 2 ) and even rotation is 132 ( 1 ).Let us understand with examples.Input − N= 54762Output −Count of rotations of N which are Odd are − 2Count of rotations of N which are Even are − 3Explanation − Rotations are −54762, 25476, 62547, 76254, 47625.Even rotations are 3 − 54762, 25476, ...

Read More

How to use SharedPreferences on Android to store, read and edit values using Kotlin?

Azhar
Azhar
Updated on 01-Dec-2020 406 Views

This example demonstrates how to use SharedPreferences on Android to store, read and edit values using Kotlin.Step 1 − Create a new project in Android Studio, go to File ⇒ New Project and fill all required details to create a new project.Step 2 − Add the following code to res/layout/activity_main.xml.                             Step 3 − Add the following code to src/MainActivity.ktimport android.content.SharedPreferences import android.os.Bundle import android.view.View import android.widget.EditText import android.widget.TextView import android.widget.Toast import androidx.appcompat.app.AppCompatActivity class MainActivity : AppCompatActivity() {    lateinit var editTextName: EditText    private lateinit ...

Read More
Showing 50801–50810 of 61,297 articles
Advertisements