Monday, November 18, 2019

Oracle: UNION, MINUS, INTERSECTION

1. SELECT ename,sal,comm FROM emp
   where ename like 'A%'
   UNION
   SELECT ename,sal,comm FROM emp
   where ename like 'E%'


2. SELECT ename,sal,comm FROM emp
   where ename like 'A%'
   UNION ALL
   SELECT ename,sal,comm FROM emp
   where ename like 'A%'


3. SELECT ename,sal,comm FROM emp
   where ename like 'E%'
   MINUS
   SELECT ename,sal,comm FROM emp
   where ename like 'E%'
   AND Comm IS NULL


4. SELECT ename,sal,comm FROM emp
   where ename like 'A%'
   INTERSECTION
   SELECT ename,sal,comm FROM emp
   where ename like 'A%'
   and sal < 2000

Oracle: Group Functions, Group Clause, Having Clause:


1. SELECT COUNT(*) FROM emp;

2. SELECT COUNT(hiredate) FROM emp;

3. SELECT COUNT(2) FROM  emp;

4. SELECT SUM(sal) FROM  emp;

5. SELECT AVG(sal) FROM emp;

6. SELECT MIN(sal) FROM emp;

7. SELECT MAX(sal) FROM emp;

8. SELECT STDDEV(sal) FROM emp;

9. SELECT VARIANCE(sal) FROM emp;

10. SELECT COUNT(*) FROM emp
      WHERE SAL < 4000;

12. SELECT COUNT(*) FROM emp
      WHERE HIREDATE > '11-Apr-1990';

13. SELECT SUM(sal) FROM emp
      WHERE ename LIKE'%A%';

14. SELECT  MAX(AMOUNT) FROM  ORDER
      WHERE SNUM IN(1002,1007)


Oracle: Sub Queries

1. Single Line SubQueries
 SELECT * FROM EMP
 WHERE DEPTNO  = (SELECT DEPTNO
                                       FROM DEPT
                                    WHERE  DNAME = 'OPERATION')



2.Multi Line SubQueries 
1. SELECT * FROM EMP
 WHERE DEPTNO  IN (SELECT DEPTNO
                                       FROM DEPT
                                    WHERE  DNAME LIKE  'A%')



2. SELECT * FROM DEPT
 WHERE DEPTNO  IN (SELECT DEPTNO
                                       FROM EMP
                                    WHERE  ENAME LIKE  '%E%')

Oracle: DDL Statement


5. Alter, Drop, Delete, Update, Commit, Rollback

1.  DELETE  FROM  player
     WHERE sal BETWEEN 1 AND 100;

2. DELETE  FROM  player
     WHERE sal IN(1000,2000);

3.  ROLLBACK;

4.  COMMIT;

5.  DROP TABLE    TEST_0

6.  ALTER TABLE test_0
     ADD   add_name  VARCHAR2(30);

7.  ALTER TABLE test_0
     MODIFY add_name  VARCHAR2(20);

8.  ALTER TABLE test_0
     DROP COLUMN  add_name ;

9.  RENAME TEST_0 TO new_Table;

10. TRUNCATE TABLE test_0;

11. UPDATE test_0
      SET   add_name =  'Your Name'
      WHERE ROLLNO = 101;

12. UPDATE test_0
       SET   add_name =  'Your Name'

Oracle: Date Function

4. Date Function

1. SELECT SYSDATE FROM DUAL.;

2. SELECT TO_CHAR(SYSDATE  ,'DD:MON:YY HH:MI:SS' )  FROM DUAL.;

3. SELECT TO_CHAR(SYSDATE ,'DD/MON/YY HH:MI:SS' )  FROM DUAL.;

4. SELECT TO_CHAR(SYSDATE,'DD/MM/YY HH:MI:SS') FROM DUAL.;

5. SELECT TO_CHAR(SYSDATE ,'DD/MONTH/YYYY' ) FROM DUAL.;

6. SELECT TO_CHAR(SYSDATE  ,'MONTH' ) FROM DUAL.;

7. SELECT TO_CHAR(SYSDATE ,'YYYY' ) FROM DUAL.;

8. SELECT TO_CHAR(SYSDATE  ,'DD' ) FROM DUAL.;

9. SELECT TO_CHAR(SYSDATE,'Day') FROM DUAL.;

10. SELECT TO_CHAR(SYSDATE ,'DAY') FROM DUAL.;

11. SELECT TO_CHAR(SYSDATE ,'DAY MONTH YEAR') FROM DUAL.;

11. SELECT
    TO_CHAR(SYSDATE ,'DAY MONTH YEAR')
     FROM DUAL.;

12. SELECT ENAME
                      ,HIREDATE
                      ,ADD_MONTHS(HIREDATE,3)
         FROM EMP;

13. SELECT ENAME
                      ,HIREDATE
                      ,ADD_MONTHS(HIREDATE,-3)
                      ,TO_CHAR(ADD_MONTHS(HIREDATE,-3)
                                          ,'Month')
         FROM EMP;

14. SELECT ENAME
                      ,HIREDATE
                      ,LAST_DAY(HIREDATE)
                      ,LAST_DAY('11-APR-2015')
         FROM EMP;

15. SELECT ENAME
                      ,HIREDATE
                      ,MONTHS_BETWEEN('11-APR-2015','31-SEP-2015')         FROM EMP;

16. SELECT  NEXT_DAY('31-JAN-2015','SATURDAY')
         FROM  DUAL;

17. SELECT  NEXT_DAY('31-JAN-2015','SATURDAY') + 10
         FROM  DUAL;

18. SELECT  SYSDATE - 5
         FROM  DUAL;

Orace: Number Built Function


3. Number Function

1. SELECT ABS(-56) FROM DUAL;

2. SELECT ABS(+56) FROM DUAL;

3. SELECT MOD(56,6) FROM DUAL;

4. SELECT MOD(17,4) FROM DUAL;

5. SELECT MOD(23,2) FROM DUAL;

6. SELECT POWER(2,2) FROM DUAL;

7. SELECT POWER(5,3) FROM DUAL;

8. SELECT POWER(8,8) FROM DUAL;

9. SELECT SQRT(64) FROM DUAL;

10. SELECT SQRT(8) FROM DUAL;

11. SELECT SQRT(23) FROM DUAL;

12. SELECT SIGN(-98) FROM DUAL;

13. SELECT SIGN(98) FROM DUAL;

14. SELECT CEIL(86.50) FROM DUAL;

15. SELECT CEIL(86.23) FROM DUAL;

16. SELECT CEIL(86.75) FROM DUAL;

17. SELECT FLOOR(86.50)FROM DUAL;

18. SELECT FLOOR(86.23) FROM DUAL;

19. SELECT FLOOR(86.75) FROM DUAL;

20. SELECT ROUND(86.50)FROM DUAL;

21. SELECT ROUND(86.23) FROM DUAL;

22. SELECT ROUND(86.75) FROM DUAL;

23. SELECT TRUNC(86.50) FROM DUAL;

24. SELECT TRUNC(86.23) FROM DUAL;

25. SELECT TRUNC(86.75) FROM DUAL;

Oracle: String Function

2. String Function
1. SELECT  NAME
               ,LOWER(NAME)
               ,UPPER(NAME)
               ,INITCAP(NAME)
               ,ASCII(NAME)
               ,LENGTH(NAME)
               , CONCAT(LOWER(NAME),UPPER(NAME))
               ,LPAD(NAME,20,'*')
               ,RPAD(NAME,20,'*')
               ,LTRIM(NAME,'A')
               ,RTRIM(NAME,'E')
               ,REPLACE(NAME,'EE','I')
               ,SUBSTR(NAME,1,3)
               ,SUBSTR(NAME,2,5)
               ,SUBSTR(NAME,2,2)
FROM emp;

2. SELECT    CHR(34)  FROM DUAL;



1. LOWER (NAME)
;g bufcYV vksjsdy QaD’ku gS A bldk mi;ksx fLVªax dks vaxzsth ds dsfiVy ysVjksa dks Leky ysVj esa ifjofrZr djrk gSA

Oracle: IN, NOT IN, BETWEEN, NOT BETWEEN, Range Searching Query:

1. SELECT ENAME, SAL FROM EMP
WHERE  SAL  NOT BETWEEN 1000 AND 3500;

2. SELECT ENAME, SAL FROM EMP
WHERE  SAL NOT  IN(1000,3500,1100,1500);

3. SELECT ENAME, SAL FROM EMP
WHERE  SAL NOT  IN(1000,3500,1100,1500)
ORDER BY ENAME, SAL ASC;

4. SELECT ENAME, SAL FROM EMP
WHERE  SAL NOT  IN(1000,3500,1100,1500)
ORDER BY ENAME DESC;

5. SELECT ENAME, SAL FROM EMP
   WHERE  sal  > 3000
   AND  sal  < 4000;

6. SELECT ENAME, SAL FROM EMP
WHERE  sal  > 3000  OR sal  < 4000;

7. SELECT ENAME, SAL FROM EMP
WHERE  SAL BETWEEN 1000 AND 3500;

8. SELECT ENAME, SAL FROM EMP
WHERE  SAL  IN(1000,3500,1100,1500);



Oracle: Pattern Matching: Like Statement

Pattern Matching

1. SELECT ENAME, SAL FROM   EMP
WHERE ename LIKE   '%E%';

2. SELECT ENAME, SAL FROM   EMP
WHERE ename LIKE   'M%';

3. SELECT ENAME, SAL FROM   EMP
WHERE ename LIKE   '%M';

4. SELECT ENAME, SAL FROM   EMP
WHERE ename LIKE   'A%M';

5. SELECT ENAME, SAL FROM   EMP
WHERE ename LIKE   '__A%';


Oracle: Relational Operator

 Relational Operator 
1. SELECT ENAME, SAL FROM EMP
WHERE  sal < 3000;

2. SELECT ENAME, SAL FROM EMP
WHERE  sal > 3000;

3. SELECT ENAME, SAL FROM EMP
WHERE  sal = 3000;

4. SELECT ENAME, SAL FROM EMP
WHERE  sal <> 3000;

5. SELECT ENAME, SAL FROM EMP
WHERE  sal  <= 3000;

6. SELECT ENAME, SAL FROM EMP
WHERE  sal  >= 3000;



Monday, November 11, 2019

C++ "setf" using "basefield"

//5.  Program to print of Hexa Decimal, Octal, Decimal No.
int main()
{
    int x = 65;   
   cout.width(20);
   cout.setf(ios::hex,ios::basefield);
   cout<<"\n Hexa -> "<   cout.setf(ios::oct,ios::basefield);
   cout<<"\n Octal -> "<   cout.setf(ios::dec,ios::basefield);
   cout<<"\n Dec -> "<
}

C++ "setf" Scientific Application "floatfield"


//4.  Program shows the application scientific

int main()

{

   cout<   cout.width(20);

   cout.setf(ios::scientific,ios::floatfield);

   cout.fill('*');

   cout<

}


C++ "setf " Function

//2. Program shows the application of setf function right padding


int main()

{

   cout.width(20);

   cout.setf(ios::right,ios::adjustfield);

   cout.fill('*');

   cout<<"IT";

}


Sunday, November 10, 2019

C ++ "setf" function for left padding

/* This file contains program related to console input and output */


#include 

#include


// 1. Program shows the application of setf function for left padding

int main()

{

   cout.width(20);

   cout.setf(ios::left,ios::adjustfield);

   cout.fill('*');

   cout<<"IT";

}

C++ Multilevel Inheritance

* C++ program to demonstrate example of multilevel inheritance.*/

Ref: Kamthane.

#include

using namespace std;

//Base Class : class A
class A
{
    private:
        int a;
    public:
        void get_a(int val_a)
        { 

           a=val_a; 

         }
       
       void disp_a(void)
        {  

           cout << "Value of a: " << a << endl;  

        }
};


class B: public A
{
    private:
        int b;
    public:
        void get_b(int val_a, int val_b)
        {

              //assign value of a by calling function of class A
            get_a(val_a);     
            b=val_b;
        }


        void disp_b(void)
        {
            //display value of a
            disp_a();
            cout << "Value of b: " << b << endl;
        }
};


//Here class C is derived class and B is Base class


class C: public B
{
    private:
        int c;
    public:
        //assign value of a from here
        void get_c(int val_a, int val_b,int val_c)
        {
            /*** Multilevel Inheritance ***/
            //assign value of a, b by calling function of class B and Class A
            //here Class A is inherited on Class B, and Class B in inherited on Class B
            get_b(val_a,val_b);
            c=val_c;
        }
       
        void disp_c(void)
        {


            disp_b(); //display value of a and b using disp_b()

            cout << "Value of c: " << c << endl;
        }
};

int main()
{
    //create object of final class, which is Class C


    C objC;


    objC.get_c(10,20,30);
    objC.disp_c();


    return 0;
}

C++ Single Level Inheritance

/*C++ program to demonstrate example of private simple inheritance.*/

Ref: Kamthane



#include
using namespace std;


class A
{   

    private:
        int a;
    protected:
        int x;      //can access by the derived class
    public:
        void setVal(int v)

        { 

           x=v; 

        }
};


class B:private A
{
    public:
        void printVal(void)
        {  

           //accessing public member function here //protected data member direct access here
            setVal(10);  

            cout << "value of x: " << x << endl;
        }
};


int main()
{   

       //derived class creation


        B objB; 
        objB.printVal();        return 0;

}

Financial Year Oracle PLSQL Program

 CREATE OR REPLACE function FINANCIAL_YEAR(p_date DATE) return varchar2 IS    v_first     varchar2(4);    v_second    varchar2(4);    v_year...