How to get table size in MB oracle ?

select segment_name,segment_type,bytes/1024/1024 MB
from dba_segments
where segment_type=’TABLE’ and lower(segment_name)=’your_table_name’;

Advertisements
Posted in oracle, sql | Tagged | Leave a comment

SQL Optimization Techniques

  • Optimize access structures:
    • Database design and normalization.
    • Tables: heap or index-organized tables, and table or indexed clusters.
    • Indexes.
    • Constraints.
    • Materialized views.
    • Partitioning schemes.
    • Statistics, including a comprehensive refresh strategy.
  • Rewrite SQL statements:
    • Exclude projections that are not required.
    • Minimize the amount of work done more than once.
    • Factor subqueries that are used multiple times in the same statement.
    • Use EXISTS instead of IN because the former stops processing once it has found a match.
    • Use CASE and/or DECODE to avoid having to scan the same rows over and over again, especially for aggregation functions that act on different subsets of the same data.
    • Use analytic functions to do multiple or moving/rolling aggregations with a single pass through the data.
    • Avoid scalar subqueries in the SELECT-list.
    • Use joins instead of subqueries, as it gives the optimizer more room to play around in.
    • Say what you mean and pick the right join: if you only need an inner join don’t write an outer join.
    • Add logically superfluous predicates that may still aid in the search for an optimal execution plan, particularly for outer joins.
    • Avoid implicit conversions of data types, especially in the WHERE clause.
    • Write WHERE clause predicates with a close eye on the indexes available, including the leading edge of a composite index.
    • Avoid, whenever possible, comparison operators such as <>, NOT IN, NOT EXISTS, and LIKEwithout a leading '%' for indexed columns in predicates.
    • Do not apply functions on indexed columns in the WHERE clause when there is no corresponding function-based index.
    • Don’t abuse HAVING to filter rows before aggregating.
    • Avoid unnecessary sorts, including when UNION ALL rather than UNION is applicable.
    • Avoid DISTINCT unless you have to use it.
    • Use PL/SQL, especially packages with stored procedures (and bind variables) and shared cursors to provide a clean interface through which all data requests are handled.
    • Add hints once you have determined that it is right and necessary to do so.
Posted in MysQl | Tagged , , , | Leave a comment

How to identify user idle state by minutes using javascript / JQuery?

Descrption:

i used with 20 minute of interval if user is in idle state from last 20 minute then it will call the timerIncrement() and then will check for 20 minutes if yes or not.

Why i need this?

i need to do this because of when i am creating an app using angular-4 then  i need to logout any user if he/she is in idle state from last 20 minutes.

$(document).ready(function () {
    var idleTime = 0;
    //Increment the idle time counter every minute.
    var idleInterval = setInterval(timerIncrement, 60000); // 1 minute

    //Zero the idle timer on mouse movement.
    $(this).mousemove(function (e) {
        idleTime = 0;
    });
    $(this).keypress(function (e) {
        idleTime = 0;
    });


function timerIncrement() {
    idleTime++;
    if (idleTime > 20) { // 20 minutes
         localStorage.removeItem('currentUser');

    }
}
});
Posted in angular-4, Javascript, jQuery | Tagged , , , , | Leave a comment

what is difference between oracle & mysql ?

Key difference: The Oracle Database is an object-relational database management system (ORDBMS). MySQL is an open source relational database management system (RDBMS). MySQL is the world’s most used RDBMS, and runs as a server providing multi-user access to a number of databases.

 

MySQL Oracle
MySQL is an open source and MySQL is available for free download and installation. Only Oracle Express Edition is free of cost. But Oracle Express Edition has very limited features when compared to MySQL. For extensive features, either Oracle Standard Edition or Oracle Enterprise Edition has to be purchased.
User authentication is performed in MySQL by using only location, username and password. Oracle provides enhanced database security. User authentication is performed in Oracle by specifying global roles in addition to location, username and password. In Oracle, User authentication is performed by different authentication methods including database authentication, external authentication and proxy authentication.
Flexibility of creating stored procedures and functions using PL/SQL is very less in MySQL. Oracle provides more flexible features for creating stored procedures and functions using PL/SQL.
MySQL offers very few commands related to generating output as report and defining variables. MySQL includes only very simple SQL commands. Oracle includes extensive SQL commands in SQL*Plus including commands for generating output as report and defining variables.
MySQL does not have the audit vault feature in the server. Oracle provides audit vault facility.
MySQL does not offer tools at enterprise level. Oracle offers tools at enterprise level.
MySQL has only table locking facility. Oracle provides the row locking facility as well.
MySQL does not have extensive storage features like tablespace, synonym, packages and many others. Oracle has a very extensive storage features. Oracle supports tablespace, synonym, packages and all other features.
MySQL database does not support XML. Oracle supports and uses XML.
MySQL supports only two character types namely CHAR and VARCHAR. Oracle supports four different character data types namely: CHAR, VARCHAR2, NCHAR, NVARCHAR2.
In MySQL, temporary tables are visible only within the current active session. When the session expires, the temporary tables are removed automatically. In Oracle, temporary tables are persistent across sessions. The temporary table has to be explicitly removed by the User.
MySQL has only two backup mechanisms namely mysqlhotcopy and mysqldump. Oracle offers many backup mechanisms including hot backup, backup, import, export and many others.
Posted in database, MysQl, oracle | Tagged , , , | Leave a comment

Rest api cakephp -3 pagination

For web we are using Paginate component & for view we used the paginator helper,

what is the standard way to enable pagination i am using following technology.

  • Cakephp-3 php MVC framework as Back-end Tech
  • Angular-js 4 as fronted

Cakephp 3 code

 

public function beforeRender(Event $event)
{
    if ($this->request->param('paging') !== false &&
        in_array($this->response->type(), ['application/json', 'application/xml'])
    ) {
        $this->set('paging', current($this->request->param('paging')));
    }
    if (!array_key_exists('_serialize', $this->viewVars) &&
        in_array($this->response->type(), ['application/json', 'application/xml'])
    ) {
        $this->set('_serialize', true);
    }
}

Don’t forget to pass the paging parameter in url.

 

After that you should receive following array

"paging": {
    "Posts": {
        "finder": "all",
        "page": 1,
        "current": 6,
        "count": 6,
        "perPage": 10,
        "prevPage": false,
        "nextPage": false,
        "pageCount": 1,
        "sort": null,
        "direction": false,
        "limit": null,
        "sortDefault": false,
        "directionDefault": false
    }
}
Posted in API, cakephp-3 | Tagged , | Leave a comment

How do I install Sublime Text 2/3?

Install via the Package Manager(apt-get):

Simply add to your packages:

For Sublime-Text-2:

sudo add-apt-repository ppa:webupd8team/sublime-text-2
sudo apt-get update
sudo apt-get install sublime-text

For Sublime-Text-3:

sudo add-apt-repository ppa:webupd8team/sublime-text-3
sudo apt-get update
sudo apt-get install sublime-text-installer

Run Sublime-Text on terminal

subl
Posted in Ubuntu | Leave a comment

What is singleton in php ?

Singleton initiates only at once

A singleton is a particular kind of class that, as you correctly said, can be instantiated only once.

First point: it isn’t a PHP related concept but an OOP concept.

What “instantiated only once means?” It simply means that if an object of that class was already instantiated, the system will return it instead of creating new one. Why? Because, sometimes, you need a “common” instance (global one) or because instantiating a “copy” of an already existent object is useless.

Let’s consider for first case a framework: on bootstrap operation you need to instantiate an object but you can (you have to) share it with other that request for a framework bootstrap.

For the second case let’s consider a class that has only methods and no members (so basically no internal state). Maybe you could implement it as a static class, but if you want to follow design patterns, consider AbstractFactory) you should use objects. So, having some copy of the same object that has only methods isn’t necessary and is also memory-wasting.

Posted in PHP | Leave a comment