Oracle Code Examples

SQL Code Examples

DML Statements


Data Control Language

  • Create an Oracle User

  • --once you create an user the user can login to the database after granting resource to that user. There are many types of grants you can assign to the users. When we create the user we have to specify the password after that user can chage the password at any time.
    Create user JON identified by monday

  • Create a Role

  • --A role is an oracle object where we can grant a set of permissions as a collection to a particular job. Example for all customer representatives we can have a role, when a person joins the company we can assign the role instead of granting permissions to each table . It easy to maintenance.
    Create Role CUSTINFO.
    Grant select on customer, cust_address, cust_hist....

  • Create a Role

  • --In the previous example we created the role and granted set of permissions on some objects. Now we will write a DCL to assign that role to the user. You can assign any number of roles to the user
    Grant CUSTINFO to JON

    PL/SQL Code Examples

    You can create a temporary tables in your select statements. You can write a select statement and call that as table a, create another select statement call that as table b and join those two temp tables for your result.

    Select
        a.col1, a.col2, a.col3, b.col1, b.col2
    from ( select col1, col2, col3 from table1 where col1 = 123 ) a,
            ( select col1, col2, col3 from table2 where col1 = 345 ) b
    where a.col1 = b.col1;

    In the above example the first select statement results is nothing but a temporary table a and the next one is called b and then join those two temp tables to get your selects.