Skip to content

Instantly share code, notes, and snippets.

@Javvadilakshman
Last active August 29, 2015 14:20
Show Gist options
  • Select an option

  • Save Javvadilakshman/4d1b02061b2863fe5a0e to your computer and use it in GitHub Desktop.

Select an option

Save Javvadilakshman/4d1b02061b2863fe5a0e to your computer and use it in GitHub Desktop.
Few Oracle Related Stuff ,Commands ,Tricks .......

Oracle

SNIPPETS

##### Oracle.com
I. Commands

ORACLE QUERIES

1.Create Table

Syntax : 
	CREATE [OR REPLACE] <table name> (column name datatype(size),....);
Example :
	CREATE TABLE employee 
		( eno number(7),ename varchar2(20),job varchar2(20),doj date,sal number(8),comm number(6),deptno number(5));
Out Put :
	SQL> CREATE TABLE employee ( eno number(7),ename varchar2(20),job varchar2(20),doj date,sal number(8),comm number(6),deptno 		             number(5));

	Table created.

2.Table Description

Syntax : 
	DESC <table name>;
Example :
	DESC employee;
Output : 
		SQL> desc employee
	 Name					   Null?    Type
	 ----------------------------------------- -------- ----------------------------
	 ENO						    NUMBER(7)
	 ENAME						    VARCHAR2(20)
	 JOB						    VARCHAR2(20)
	 DOJ						    DATE
	 SAL						    NUMBER(8)
	 COMM						    NUMBER(6)
	 DEPTNO 					    NUMBER(5)

3.Insert record in to table

Syntax : 	
	INSERT into < table name > values (&colname1,&colname2,......);
Example :
	INSERT into employee values (&eno,'&ename','&job','&doj',&sal,&comm,&deptno);
Output :
	SQL> INSERT into employee values (&eno,'&ename','&job','&doj',&sal,&comm,&deptno);
		Enter value for eno: 001
		Enter value for ename: Lakshman
		Enter value for job: Developer
		Enter value for doj: 22JAN1989
		Enter value for sal: 50000
		Enter value for comm: 1000
		Enter value for deptno: 001
		old   1: INSERT into employee values (&eno,'&ename','&job','&doj',&sal,&comm,&deptno)
		new   1: INSERT into employee values (001,'Lakshman','Developer','22JAN1989',50000,1000,001)

		1 row created.

4.Select records in table

Syntax :
	SELECT * FROM < table name >[where <condition>];
Example : 
	SELECT * FROM employee;
	
Output :

SQL>SELECT * FROM employee;

       ENO ENAME		JOB		     DOJ	     SAL  COMM      DEPTNO
---------- -------------------- -------------------- -------- ----------- --------- ----------
        1  Lakshman		Developer	     22-01-89	   50000   1000	    1

ORACLE COMMANDS

CREATE USER

CREATE USER MIG61 IDENTIFIED BY test_usr;

GRANTING PERMISSION

GRANT CONNECT,RESOURCE,DBA TO  test_usr;
GRANT UNLIMITED TABLESPACE TO test_usr;

CHECK LOGED IN USER

SELECT USER FROM DUAL;

CONNECT TO TARGET SCHEMA

ALTER SESSION SET CURRENT_SCHEMA = test_usr;

CHECK DIRECTORIES

SELECT * FROM dba_directories;

DROPING TABLE & DIRECTORY'S

DROP TABLE testdata_BFILE;
DROP DIRECTORY test_usr;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment