Skip to main content

Posts

Showing posts from May, 2021

Check Constraints In SQL

  Check Constraint::   ->to check values before accepting into a column with user defined condition at column level:: ================ >create table test1(eid int check(eid<5),ename varchar2(10)); EX:: SQL> create table test1(eid int check(eid<5),ename varchar2(10)); Table created. SQL> insert into test1 values(1,'dan'); 1 row created. SQL> insert into test1 values(2,'sam'); 1 row created. SQL> select * from test1;        EID ENAME ---------- ----------          1 dan          2 sam SQL> insert into test1 values(5,'sam'); insert into test1 values(5,'sam') * ERROR at line 1: ORA-02290: check constraint (SYSTEM.SYS_C007650) violated SQL> insert into test1 values(4,'sam'); 1 row created. SQL> select * from test1;        EID ENAME ---------- ----------          1 dan          2 sam          4 sam SQL> insert into test1 values(55,'sam'); insert into test1 values(55,'sam') * ERROR at line 1: ORA-02290

Not Null Constraint In SQL

 Not Null Constraint: ====================   -Restricted nulls but accepting duplicates      -Not null an not be applied at table level ex:: create table test1(eid int not null,ename varchar2(10) not null); EX:: SQL> create table test1(eid int not null,ename varchar2(10) not null); Table created. SQL> insert into test1 values(10,'raja'); 1 row created. SQL> insert into test1 values(20,'dan'); 1 row created. SQL> select * from test1;        EID ENAME ---------- ----------         10 raja         20 dan SQL> insert into test1 values(null,'dan'); insert into test1 values(null,'dan')                          * ERROR at line 1: ORA-01400: cannot insert NULL into ("SYSTEM"."TEST1"."EID") SQL> insert into test1 values(10,null); insert into test1 values(10,null)                             * ERROR at line 1: ORA-01400: cannot insert NULL into ("SYSTEM"."TEST1"."ENAME") SQL> select *

unique constraint in sql

Unique Constraint:: ================  -Restricted Duplicates values but accepting nulls into a column column level:: ============ >create table test1(sno int unique,name varchar2(10) unique); EX:: SQL> create table test1(eid int unique,ename varchar2(10) unique); Table created. SQL> insert into test1 values(10,'virat'); 1 row created. SQL> select * from test1;        EID ENAME ---------- ----------         10 virat SQL> insert into test1 values(10,'rohit'); insert into test1 values(10,'rohit') * ERROR at line 1: ORA-00001: unique constraint (SYSTEM.SYS_C007643) violated SQL> insert into test1 values(20,'virat'); insert into test1 values(20,'virat') * ERROR at line 1: ORA-00001: unique constraint (SYSTEM.SYS_C007644) violated SQL> insert into test1 values(20,'rohit'); 1 row created. SQL> select * from test1;        EID ENAME ---------- ----------         10 virat         20 rohit SQL> insert into test1(null,'

JDBC application For Delete Operation

 JDBC application For Delete Operation Create Table:: SQL> create table test1(eid int,ename varchar2(10)); Table created. SQL> insert into test1 values(1,'vijay'); 1 row created. SQL> insert into test1 values(2,'rajesh'); 1 row created. SQL> select * from test1;        EID ENAME ---------- ----------          1 vijay          2 rajesh SQL> commit; Commit complete. JDBC application::: import java.sql.*; class Test { public static void main(String[] args)throws Exception{ //load JDBC driver //get connection Connection con = DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:orcl","system","tiger"); //create statement obj Statement st = con.createStatement(); //prepare and execute query String query = "delete from test1 where eid=2"; int count = st.executeUpdate(query); if(count==0){ System.out.println("No Row is deleted"); }else{ System.out.println(count+&qu

JDBC Application For Insert Operation

  JDBC Application For Insert Operation  For Explanation watch Video:: Create Table:: SQL>  create table test2(eid int,ename varchar2(10)); Table created. SQL> insert into test2 values(1,'vijay'); 1 row created. SQL> select * from test2;        EID ENAME ---------- ----------          1 vijay SQL> commit; Commit complete. Code:: import java.sql.*; class Test { public static void main(String[] args)throws Exception{ //load JDBC driver  Connection con = DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:orcl","system","tiger"); //create statement obj Statement st = con.createStatement(); //prepare and execute SQL query String query = "insert into test2 values(2,'rajesh')"; //execute the query int count = st.executeUpdate(query); if(count==0){ System.out.println("No row inserted"); }else{ System.out.println("row is inserted"); } con.close(); }

Hackerrank Solve Me First Solution - Java | Hackerrank Algorithms

  Hackerrank Solve Me First Solution - Java For Explanation Watch Video:: Code:: import java.io.*; import java.util.*; import java.text.*; import java.math.*; import java.util.regex.*; public class Solution {     static int solveMeFirst(int a, int b) {       // Hint: Type return a+b; below            return a+b;    }  public static void main(String[] args) {         Scanner in = new Scanner(System.in);         int a;         a = in.nextInt();         int b;         b = in.nextInt();         int sum;         sum = solveMeFirst(a, b);         System.out.println(sum);    } }

Rename Command (DDL) in SQL Oracle With Implementation

 Rename Command (DDL) in SQL Oracle With Implementation For explanation watch Video:: Rename command :: Used to change the name of table SQL> desc emp01;  Name                                      Null?    Type  ----------------------------------------- -------- ----------------------------  FNAME                                              VARCHAR2(15)  SAL                                                NUMBER(10) SQL> rename emp01 to emp02; Table renamed. SQL> desc emp01; ERROR: ORA-04043: object emp01 does not exist SQL> desc emp02;  Name                                      Null?    Type  ----------------------------------------- -------- ----------------------------  FNAME                                              VARCHAR2(15)  SAL                                                NUMBER(10)

Average Population Hackerrank Solution SQL | Hackerrank SQL

 Average Population Hackerrank Solution SQL  For Explanation Watch Video:  Code:: select round(avg(population),0) from city;

ALTER Command (DDL) in SQL Oracle with Implementation on ORACLE

 ALTER Command (DDL) in SQL Oracle with Implementation on ORACLE For Explanation Watch video: 1)Alter Modify :: to modify column name or datatype EX:: SQL> create table emp01(name char(10),sal Number(10)); Table created. SQL> desc emp01;  Name                                      Null?    Type  ----------------------------------------- -------- ----------------------------  NAME                                               CHAR(10)  SAL                                                NUMBER(10) SQL> alter table emp01 modify name varchar2(10); Table altered. SQL> desc Emp01;  Name                                      Null?    Type  ----------------------------------------- -------- ----------------------------  NAME                                               VARCHAR2(10)  SAL                                                NUMBER(10) SQL> alter table emp01 modify name varchar2(15)/*to change the size of varchar2*/; Table altered. SQL> desc emp01;  Name               

Revising Aggregations - Averages Hackerrank Solution SQL | Hackerrank SQL

  Revising Aggregations - Averages Hackerrank Solution SQL  For Explanation Watch Video : Code:: select avg(population) from city where district = 'California';

Create table in SQL | How to see the Structure Of The table in SQL

 Create table in SQL For Explanation Watch Video:: EX:1: SQL> create table emp01(name varchar2(10),sal number(10)); Table created. How to see the Structure Of The table in SQL SQL> desc emp01;  Name                                      Null?    Type  ----------------------------------------- -------- ----------------------------  NAME                                               VARCHAR2(10)  SAL                                                NUMBER(10) EX2:: SQL> create table emp02(sno int,fname varchar2(10),lname varchar2(10),addr varchar2(10)); Table created. SQL> desc EMp02;  Name                                      Null?    Type  ----------------------------------------- -------- ----------------------------  SNO                                                 NUMBER(38)  FNAME                                           VARCHAR2(10)  LNAME                                           VARCHAR2(10)  ADDR                                              VARCHAR2(10)

JDBC basic example For Select Query

JDBC basic example For Select Query  For explanation watch video:  For Creating Table:: SQL> create table emp60(srno int,fname varchar2(10)); Table created. SQL> desc emp60;  Name                                      Null?    Type  ----------------------------------------- -------- ----------------------------  SRNO                                               NUMBER(38)  FNAME                                              VARCHAR2(10) SQL> insert into emp60 values(1,'allu'); 1 row created. SQL> insert into emp60 values(2,'vijay'); 1 row created. SQL> insert into emp60 values(3,'rajni'); 1 row created. SQL> select * from emp60;       SRNO FNAME ---------- ----------          1 allu          2 vijay          3 rajni TO check Service Id: SQL> commit; Commit complete. SQL> select * from global_name; GLOBAL_NAME -------------------------------------------------------------------------------- ORCL JDBC Program:: =========== import java.sql.*;

Revising Aggregations - The Sum Function Hackerrank Solution SQL

 Revising Aggregations - The Sum Function Hackerrank Solution SQL For Explanation Watch Video : Code:: select sum(population) from city where district = 'California';

Connect n ropes with minimum cost Java Code Solution

  Connect n ropes with minimum cost Java Code Solution Watch Video:: Code: import java.util.*; import java.lang.*; import java.io.*; class Test{     public static void main(String[] args) {                  //Taking input using class Scanner         Scanner in = new Scanner(System.in);                  //Taking count of testcases         int t = in.nextInt();         while (t-- > 0) {                          //takling count of elements             int n = in.nextInt();                          //Creating an array of size n             long arr[] = new long[n];             //inserting elements to the array             for (int i = 0; i < n; ++i) arr[i] = in.nextLong();             //calling minCost method of class solve             System.out.println(new Solution().minCost(arr, n));         }     } } // } Driver Code Ends class Solution{     long minCost(long arr[], int n) {        PriorityQueue<Long> heap = new PriorityQueue<>();        for(int i=0;i<n;i++){      

Hackerrank Super Reduced String Solution - JAVA

 Hackerrank Super Reduced String Solution - JAVA For explanation watch Video :: Code: import java.io.*; import java.math.*; import java.security.*; import java.text.*; import java.util.*; import java.util.concurrent.*; import java.util.function.*; import java.util.regex.*; import java.util.stream.*; import static java.util.stream.Collectors.joining; import static java.util.stream.Collectors.toList; class Result {     /*      * Complete the 'superReducedString' function below.      *      * The function is expected to return a STRING.      * The function accepts STRING s as parameter.      */     public static String superReducedString(String s) {         StringBuilder sb = new StringBuilder(s);         for(int i=1;i<sb.length();i++){             if(sb.charAt(i)==sb.charAt(i-1)){                 sb.delete(i-1,i+1);                 i=0;             }         }         String ans = sb.toString();         if(ans.length()==0){             return "Empty String";        

Revising Aggregations - The Count Function Hackerrank Solution SQL | Hackerrank SQL

 Revising Aggregations - The Count Function Hackerrank Solution SQL For Explanation Watch Video : Code: select count(*) from city where population > 100000;

Type of Triangle Hackerrank Solution SQL | Hackerrank SQL

 Type of Triangle Hackerrank Solution SQL  For Explanation Watch Video : Code: SELECT CASE WHEN A+B<=C OR B+C<=A OR C+A<=B THEN 'Not A Triangle' WHEN A=B AND B=C THEN 'Equilateral' WHEN A=B OR B=C OR C=A THEN 'Isosceles' ELSE 'Scalene' END FROM TRIANGLES;

Employee Salaries Hackerrank Solution SQL | Hackerrank SQL

 Employee Salaries Hackerrank Solution SQL For Explanation Watch Video:  Code: select name from Employee where salary>2000 and months < 10 order by employee_id;

Employee Names Hackerrank Solution SQL | Hackerrank SQL

Employee Names Hackerrank Solution SQL   For Explanation Watch Video : Code: select name from Employee order by name;

Higher Than 75 Marks Hackerrank Solution SQL | Hackerrank SQL

 Higher Than 75 Marks Hackerrank Solution SQL  for explanation watch Video: Code: select name from students where marks>75 order by substr(name,-3),id;

Weather Observation Station 12 Hackerrank Solution SQL | Hackerrank SQL

 Weather Observation Station 12 Hackerrank Solution SQL For Explanation Watch Videos:: Code: select distinct city from station where  not(city like 'A%' or city like 'E%' or city like 'I%' or city like 'O%' or city like 'U%') and not(city like '%A' or city like '%E' or city like '%I' or city like '%O' or city like '%U');

Weather Observation Station 11 Hackerrank Solution SQL | Hackerrank SQL

 Weather Observation Station 11 Hackerrank Solution SQL  For Explanation Watch video:: Code: select distinct city from station where not(city like 'A%' or city like 'E%' or city like 'I%' or city like 'O%' or city like 'U%') or not(city like '%A' or city like '%E' or city like '%I' or city like '%O' or city like '%U');

Weather Observation Station 10 Hackerrank Solution SQL | Hackerrank SQL

 Weather Observation Station 10 Hackerrank Solution SQL For Explanation Watch Video:: Code: select distinct city from station where not(city like '%A' or city like '%E' or city like '%I' or city like '%O' or city like '%U');

Weather Observation Station 9 Hackerrank Soluion SQL | Hackerrank SQL

 Weather Observation Station 9 Hackerrank Soluion SQL For Explanation Watch Video:: Code: select distinct city from station where not(city like 'A%' or city like 'E%' or city like 'I%' or city like 'O%' or city like 'U%');

Weather Observation Station 8 Hackerrank Solution SQL | Hackerrank SQL

 Weather Observation Station 8 Hackerrank Solution SQL For Explanation Watch Video: Code: select distinct city from station where (city like 'A%' or city like 'E%' or city like 'I%' or city like 'O%' or city like 'U%') and       (city like '%A' or city like '%E' or city like '%I' or city like '%O' or city like '%U');

Weather Observation Station 7 Hackerrank Solution SQL | Hackerrank SQL

 Weather Observation Station 7 Hackerrank Solution SQL  For Explanation Watch Video: Code: select distinct city from station where (city like '%A' or city like '%E' or city like '%I' or city like '%O' or city like '%U');

Weather Observation Station 6 Hackerrank Solution SQL | Hackerrank SQL

 Weather Observation Station 6 Hackerrank Solution SQL  For Explanation Watch Video: Code: select distinct city from station where (city like 'A%' or city like 'E%' or city like 'I%' or city like 'O%' or city like 'U%');

Weather Observation Station 5 Hackerrank Solution SQL | Hackerrank SQL

 Weather Observation Station 5 Hackerrank Solution SQL  For Explanation Watch Video: Code: select(city), length(city) from station order by length(city),city limit 1; select(city), length(city) from station order by length(city) desc ,city limit 1;

Weather Observation Station 4 Hackerrank Solution SQL | Hackerrank SQL

 Weather Observation Station 4 Hackerrank Solution SQL For Explanation Watch Video: Code: select count(city) - count(distinct city) from station;

Weather Observation Station 3 Hackerrank Solution SQL | Hackerrank SQL

 Weather Observation Station 3 Hackerrank Solution SQL For Explanation Watch Video: Code: select distinct city from station where mod(id,2)=0;

Weather Observation Station 1 Hackerrank Solution SQL

 Weather Observation Station 1 Hackerrank Solution SQL For Explanation Watch Video: Code: select city,state from station;

Japanese Cities' Names Hackerrank Solution SQL

 Japanese Cities' Names Hackerrank Solution SQL for Explanation Watch video: Code: select name from city where  COUNTRYCODE ='JPN';

Japanese Cities' Attributes Hackerrank Solution SQL

 Japanese Cities' Attributes Hackerrank Solution SQL For Explanation watch video: Code: select * from city where COUNTRYCODE='JPN';

Select By ID Hackerrank Solution SQL

 Select By ID Hackerrank Solution SQL For Explanation Watch Video: Code: select * from city where id = 1661;

Select All Hackerrank Solution SQL

 Select All Hackerrank Solution SQL For Explanation Watch Video: Code: select * from city;

Revising the Select Query II Hackerrank Solution SQL

 Revising the Select Query II Hackerrank Solution SQL If You want Explanation Watch Video: Code: select name from city where population > 120000 and CountryCode = 'USA';

Oracle Supporting Data Types With Examples

 *Oracle Supporting Data Types 1)Numeric Datatypes 2)Character/string 3)Long 4)Date 5)Raw & Long Raw 6)Lob (Large Object) ========================================================================= 1)Numeric DT: ============      i)INT      ii)Number i)INT:  =>To store Integer values Only =>when we use "int" DT at the time of table designing internally Oracle Server is converting into "Number" DT with max size 38 Digits.          int = Number(38) ii)Number(p,s):    =>To store Integer and float value         >Number(p) --------->INT         >Number(p,s)--------->Float    Precision(p): =============    =>Counting all digits (left + right) in the given Expression     ex:: i)98.34           precision = 4         ii)9878.34            precision = 6  scale(s): ========= =>Counting right side digit Only   ex:i)98.34        precision = 4        scale = 2      ii)8870.454        precision = 7         scale = 3 2)Character/string DT ==============

Revising the Select Query I Hackerrank Solution SQL

 Revising the Select Query I Hackerrank  Solution SQL  For Explanation Watch Video: Code: select * from city where population > 100000 and CountryCode = 'USA';

Birthday Cake Candles Hackerrank Solution Java

Birthday Cake Candles Hackerrank Solution Java For Explanation Watch Video: Sample Input 0 4 3 2 1 3 Sample Output 0 2 Code: import  java.io.*; import  java.math.*; import  java.security.*; import  java.text.*; import  java.util.*; import  java.util.concurrent.*; import  java.util.function.*; import  java.util.regex.*; import  java.util.stream.*; import   static  java.util.stream.Collectors.joining; import   static  java.util.stream.Collectors.toList; class  Result {      /*      * Complete the 'birthdayCakeCandles' function below.      *      * The function is expected to return an INTEGER.      * The function accepts INTEGER_ARRAY candles as parameter.      */      public   static   int  birthdayCakeCandles(List<Integer> candles) {      // Write your code here     Collections.sort(candles);      int  count =  1 ;      int  largest = candles.get(candles.size()- 1 );      for ( int  i=candles.size()- 2 ;i>= 0 ;i--){          if (candles.get(i)!=largest){             

How to set classpath to access oracle driver for Different Versions Of Oracle Software

 How to set classpath to access oracle driver  for Different Versions Of Oracle Software  For  More Details Watch Video: Solution: ====== setting classpath to access oracle driver ========================================= for different versions of Oracle ojdbc14.jar    -----> oracle 10g   ojdbc6.jar     -----> oracle 11g    ojdbc7.jar     -----> oracle 12c    ojdbc8.jar     -----> oracle 19c Step1 ::Go to The folder where you extract your Oracle Downloaded Zip File.             For Ex::I have Extracted Zip file in "C drive" in "App" Folder.         Step 2:: When We go to that folder then search for jar files acc. to your Oracle version           ojdbc14.jar    -----> oracle 10g           ojdbc6.jar     -----> oracle 11g           ojdbc7.jar     -----> oracle 12c           ojdbc8.jar     -----> oracle 19c For Ex::I have oracle 19c version so i will find for ojdbc8.jar simlarly you can find   ===================================================

Maps-STL Hackerrank Solution in C++

 Maps-STL Hackerrank Solution C++ For Explanation Watch Video:: Sample Input 7 1 Jesse 20 1 Jess 12 1 Jess 18 3 Jess 3 Jesse 2 Jess 3 Jess Sample Output 30 20 0 Code: #include   < cmath > #include   < cstdio > #include   < vector > #include   < iostream > #include   < set > #include   < map > #include   < algorithm > using   namespace  std; int  main() {      /* Enter your code here. Read input from STDIN. Print output to STDOUT */          int  q;     cin>>q;     map<string, int >m;      int  type;     string name;      for ( int  i= 0 ;i<q;i++){         cin>>type>>name;          if (type== 1 ){              int  mark;             cin>>mark;             m[name] += mark;         } else   if (type== 2 ){             m.erase(name);         } else   if (type== 3 ){             cout<<m[name]<< "\n" ;         }     }      return   0 ; }

Sets-STL Hackerrank Solution in C++

 Sets-STL Hackerrank Solution in C++ For Explanation Watch Video:: Sample Input 8 1 9 1 6 1 10 1 4 3 6 3 14 2 6 3 6 Sample Output Yes No No Code: #include <cmath> #include <cstdio> #include <vector> #include <iostream> #include <set> #include <algorithm> using namespace std; int main() {     /* Enter your code here. Read input from STDIN. Print output to STDOUT */      set<int>s;     int q;     cin>>q;     for(int i=0;i<q;i++){         int val;         cin>>val;         if(val==1){             int x;             cin>>x;             s.insert(x);         }else if(val==2){             int val;             cin>>val;             s.erase(val);         }else{             int val;             cin>>val;             auto it = s.find(val);             if(it!=s.end()){                 cout<<"Yes"<<endl;             }else{                 cout<<"No"<<endl;             }         }