Está en la página 1de 15

1* select substr('SIVA RAMA KRISHNA',-7) from dual

SQL> /
SUBSTR(
------KRISHNA
SQL> ed
Wrote file afiedt.buf
1* select substr('SIVA RAMA KRISHNA',-12,4) from dual
2 /
SUBS
---RAMA
SQL> clear screen
SQL> /
SUBS
---RAMA
SQL> ed
Wrote file afiedt.buf
1* select substr('SIVA RAMA KRISHNA',-12,4) from dual
2 /
SUBS
---RAMA
SQL> ed
Wrote file afiedt.buf
1* select substr('SIVA RAMA KRISHNA',-12,-4) from dual
2 /
S
SQL> clear screen
SQL> ed
Wrote file afiedt.buf
line 4 truncated.
1 Select Ename,Job
2
From Emp
3* Where Substr(Job,6)=Upper('man')
4
SQL>
SQL> ed
Wrote file afiedt.buf
1 Select Ename,Job
2
From Emp
3* Where Substr(Job,6)=Upper('MAN')
SQL> ed

Wrote file afiedt.buf


1 Select Ename,Job
2
From Emp
3* Where Substr(Job,6)=Upper('man')
SQL> /
ENAME
---------ALLEN
WARD
MARTIN
TURNER

JOB
--------SALESMAN
SALESMAN
SALESMAN
SALESMAN

SQL> clear screen


SQL> ed
Wrote file afiedt.buf
1
2
3
4*
5

Select Concat(Initcap(Ename),
Concat(' is a ',Concat(Initcap(Substr(Job,1,3)),' Eater.')))
From Emp
Where Substr(Job,4,3)=Upper('Age')
/

CONCAT(INITCAP(ENAME),CONC
-------------------------Jones is a Man Eater.
Blake is a Man Eater.
Clark is a Man Eater.
SQL> ed
Wrote file afiedt.buf
1
2
3
4*
SQL>
SQL>

Select Concat(Initcap(Ename),
Concat(' is a ',Concat(Initcap(Substr(Job,1,3)),' Eater.')))
From Emp
Where Substr(Job,4,3)=Upper('Age')
/

CONCAT(INITCAP(ENAME),CONC
-------------------------Jones is a Man Eater.
Blake is a Man Eater.
Clark is a Man Eater.
SQL> clear screen
SQL> /
CONCAT(INITCAP(ENAME),CONC
-------------------------Jones is a Man Eater.
Blake is a Man Eater.
Clark is a Man Eater.
SQL> ed
Wrote file afiedt.buf
1
2
3

Select Concat(Initcap(Ename),
Concat(' is a ',Concat(Initcap(Substr(Job,1,3)),' Eater.')))
From Emp

4* Where Substr(Job,4,3)=Upper('Age')
5 /
CONCAT(INITCAP(ENAME),CONC
-------------------------Jones is a Man Eater.
Blake is a Man Eater.
Clark is a Man Eater.
SQL> clear screen
SQL> /
CONCAT(INITCAP(ENAME),CONC
-------------------------Jones is a Man Eater.
Blake is a Man Eater.
Clark is a Man Eater.
SQL> clear screen
SQL> ed
Wrote file afiedt.buf
line 1 truncated.
1* Select Length('E.F CODD') From Dua
SQL>
SQL>
SQL> ed
Wrote file afiedt.buf
1* Select Length('E.F CODD') From Dual
2 /
LENGTH('E.FCODD')
----------------8
SQL>
SQL>
SQL> clear screen
SQL> /
LENGTH('E.FCODD')
----------------8
SQL> ed
Wrote file afiedt.buf
1* Select Length('E.F CODD') From Dual
SQL>
SQL>
SQL> clear screen
SQL> ed
Wrote file afiedt.buf
line 3 truncated.
1 select ename
2 from emp
3* where ename like '_____
SQL> /
ERROR:

ORA-01756: quoted string not properly terminated


SQL> ed
Wrote file afiedt.buf
1
2
3*
SQL>

select ename
from emp
where ename like '_____'
/

ENAME
---------SMITH
ALLEN
JONES
BLAKE
CLARK
SCOTT
ADAMS
JAMES
8 rows selected.
SQL> clear screen
SQL> /
ENAME
---------SMITH
ALLEN
JONES
BLAKE
CLARK
SCOTT
ADAMS
JAMES
8 rows selected.
SQL> ed
Wrote file afiedt.buf
1
2
3*
4

select ename
from emp
where length(ename)=5
/

ENAME
---------SMITH
ALLEN
JONES
BLAKE
CLARK
SCOTT
ADAMS
JAMES
8 rows selected.

SQL> clear screen


SQL> ed
Wrote file afiedt.buf
line
1
2
3*
4

4 truncated.
Select Initcap(Ename),Job
From Emp
Where Substr(Job,4,Length(Substr(Job,4,3)))='AGE'
/

INITCAP(EN
---------Jones
Blake
Clark

JOB
--------MANAGER
MANAGER
MANAGER

SQL> clear screen


SQL> ed
Wrote file afiedt.buf
line 1 truncated.
1* Select Instr('SIVA RAMA KRISHNA','A',1,1) From Dua
SQL>
SQL>
SQL> ed
Wrote file afiedt.buf
1* Select Instr('SIVA RAMA KRISHNA','A',1,1) From Dual
2 /
INSTR('SIVARAMAKRISHNA','A',1,1)
-------------------------------4
SQL> ed
Wrote file afiedt.buf
1* Select Instr('SIVA RAMA KRISHNA','A',17,2) From Dual
2 /
INSTR('SIVARAMAKRISHNA','A',17,2)
--------------------------------0
SQL> ed
Wrote file afiedt.buf
1* Select Instr('SIVA RAMA KRISHNA','A',-1,2) From Dual
SQL> /
INSTR('SIVARAMAKRISHNA','A',-1,2)
--------------------------------9
SQL> ed
Wrote file afiedt.buf
1* Select Instr('SIVA RAMA KRISHNA','A',-1,1) From Dual
2 /
INSTR('SIVARAMAKRISHNA','A',-1,1)

--------------------------------17
SQL> clear screen
SQL> ed
Wrote file afiedt.buf
1* Select Instr('SIVA RAMA KRISHNA','A',-1,1) From Dual
2 ed
3
SQL>
SQL> ed
Wrote file afiedt.buf
1* Select Instr('SIVA RAMA KRISHNA','A') From Dual
SQL> /
INSTR('SIVARAMAKRISHNA','A')
---------------------------4
SQL> clear screen
SQL> ed
Wrote file afiedt.buf
line 1 truncated.
1* Select Instr('SIVA RAMA KRISHNA','MA',7,1) From Dua
SQL>
SQL>
SQL> ed
Wrote file afiedt.buf
1* Select Instr('SIVA RAMA KRISHNA','MA',7,1) From Dual
SQL> /
INSTR('SIVARAMAKRISHNA','MA',7,1)
--------------------------------8
SQL> clear screen
SQL> ed
Wrote file afiedt.buf
line 3 truncated.
1 Select Instr(Job,'A',1,2)
2 From Emp
3* Where Job='MANAGER
SQL>
SQL>
SQL> ed
Wrote file afiedt.buf
1
2
3*
SQL>

Select Instr(Job,'A',1,2)
From Emp
Where Job='MANAGER'
/

INSTR(JOB,'A',1,2)
-----------------4
4

4
SQL> clear screen
SQL> /
INSTR(JOB,'A',1,2)
-----------------4
4
4
SQL> clear screen
SQL> ed
Wrote file afiedt.buf
1 Select Instr(Job,'A',2)
2* From Emp Where Job='MANAGER'
3 /
INSTR(JOB,'A',2)
---------------2
2
2
SQL> ed
Wrote file afiedt.buf
line 3 truncated.
1 Select Instr(Job,'A')
2
From Emp
3* Where Job='MANAGER
SQL>
SQL>
SQL> clear screen
SQL> ed
Wrote file afiedt.buf
1 Select Instr(Job,'A')
2
From Emp
3* Where Job='MANAGER
SQL>
SQL> clear screen
SQL> ed
Wrote file afiedt.buf
line 1 truncated.
1* Select Lpad('oracle',20) From Dua
SQL> /
Select Lpad('oracle',20) From Dua
*
ERROR at line 1:
ORA-00942: table or view does not exist
SQL> ed
Wrote file afiedt.buf
1* Select Lpad('oracle',20) From Dual
2 /

LPAD('ORACLE',20)
-------------------oracle
SQL> clear screen
SQL> /
LPAD('ORACLE',20)
-------------------oracle
SQL> ed
Wrote file afiedt.buf
1* Select Lpad('oracle',50) From Dual
SQL> /
LPAD('ORACLE',50)
-------------------------------------------------oracle
SQL> clear screen
SQL> /
LPAD('ORACLE',50)
-------------------------------------------------oracle
SQL> ed
Wrote file afiedt.buf
1* Select Lpad('oracle',50,'*') From Dual
2 /
LPAD('ORACLE',50,'*')
-------------------------------------------------********************************************oracle
SQL> ed
Wrote file afiedt.buf
1* Select rpad('oracle',50,'*') From Dual
2 /
RPAD('ORACLE',50,'*')
-------------------------------------------------oracle********************************************
SQL> clear screen
SQL> /
RPAD('ORACLE',50,'*')
-------------------------------------------------oracle********************************************
SQL> ed
Wrote file afiedt.buf
1* Select lpad('oracle',3) From Dual
2 /

LPA
--ora
SQL> ed
Wrote file afiedt.buf
1* Select rpad('oracle',3) From Dual
2 /
RPA
--ora
SQL> clear screen
SQL> /
RPA
--ora
SQL> clear screen
SQL> ed
Wrote file afiedt.buf
1* Select rpad('oracle',3) From Dual
2 /
RPA
--ora
SQL> ed
Wrote file afiedt.buf
1* Select rpad('oracle',36,'*') From Dual
2 /
RPAD('ORACLE',36,'*')
-----------------------------------oracle******************************
SQL> ed
Wrote file afiedt.buf
1* Select lpad(rpad('oracle',36,'*'),66,'*')
2 /

From Dual

LPAD(RPAD('ORACLE',36,'*'),66,'*')
-----------------------------------------------------------------******************************oracle******************************
SQL> clear screen
SQL> /
LPAD(RPAD('ORACLE',36,'*'),66,'*')
-----------------------------------------------------------------******************************oracle******************************
SQL> clear screen
SQL> desc cust

Name
Null?
Type
------------------------------- -------- ---CNAME
VARCHAR2(10)
SQL> drop table cust purge;
Table dropped.
SQL> create table cust
2
SQL>
SQL> ed
Wrote file afiedt.buf
1 create table cust
2 (cid number(6),
3* cname varchar2(20))
4 /
Table created.
SQL> create
2
SQL> ed
Wrote file afiedt.buf
1* create sequence s1
2 /
create sequence s1
*
ERROR at line 1:
ORA-00955: name is already used by an existing object
SQL> drop sequence s1;
Sequence dropped.
SQL> create sequence s1
2 /
Sequence created.
SQL> ed
Wrote file afiedt.buf
1* create sequence s1
2
SQL> insert into cust values
2
SQL>
SQL> ed
Wrote file afiedt.buf
1* insert into cust
2 /
1 row created.

values(1,'JAN')

SQL> select *from cust;

CID CNAME
--------- -------------------1 JAN
SQL> rollback;
Rollback complete.
SQL> insert into cust
2
SQL> ed
Wrote file afiedt.buf

values(1,'JAN')

1* insert into cust


SQL> /

values(00001,'JAN')

1 row created.
SQL> select *from cust;
CID CNAME
--------- -------------------1 JAN
SQL> rollback;
Rollback complete.
SQL> insert into cust
2
SQL> ed
Wrote file afiedt.buf

values(1,'JAN')

1* insert into cust values(lpad(s1.nextval,5,0),'&cname')


2 /
Enter value for cname: JAN
old
1: insert into cust values(lpad(s1.nextval,5,0),'&cname')
new
1: insert into cust values(lpad(s1.nextval,5,0),'JAN')
1 row created.
SQL> /
Enter value for cname: WARD
old
1: insert into cust values(lpad(s1.nextval,5,0),'&cname')
new
1: insert into cust values(lpad(s1.nextval,5,0),'WARD')
1 row created.
SQL> /
Enter value for cname: SMITH
old
1: insert into cust values(lpad(s1.nextval,5,0),'&cname')
new
1: insert into cust values(lpad(s1.nextval,5,0),'SMITH')
1 row created.
SQL> select *from cust;
CID
--------1
2

CNAME
-------------------JAN
WARD

3 SMITH
SQL> rollback;
Rollback complete.
SQL> ed
Wrote file afiedt.buf
line 1 truncated.
1* insert into cust values(lpad(s1.nextval,5,'0'),'&cname'
SQL> /
Enter value for cname: jan
old
1: insert into cust values(lpad(s1.nextval,5,'0'),'&cname'
new
1: insert into cust values(lpad(s1.nextval,5,'0'),'jan'
insert into cust values(lpad(s1.nextval,5,'0'),'jan'
*
ERROR at line 1:
ORA-00917: missing comma
SQL> /
Enter value for cname: jan
old
1: insert into cust values(lpad(s1.nextval,5,'0'),'&cname'
new
1: insert into cust values(lpad(s1.nextval,5,'0'),'jan'
insert into cust values(lpad(s1.nextval,5,'0'),'jan'
*
ERROR at line 1:
ORA-00917: missing comma
SQL> ed
Wrote file afiedt.buf
1* insert into cust values(lpad(s1.nextval,5,'0'),'&cname')
SQL> /
Enter value for cname: jan
old
1: insert into cust values(lpad(s1.nextval,5,'0'),'&cname')
new
1: insert into cust values(lpad(s1.nextval,5,'0'),'jan')
1 row created.
SQL> select *from cust;
CID CNAME
--------- -------------------4 jan
SQL> ed
Wrote file afiedt.buf
1* select *from cust
SQL>
SQL>
SQL>
SQL> rollback;
Rollback complete.
SQL> ed
Wrote file afiedt.buf

line 1 truncated.
1* insert into cust values('C'||lpad(s1.nextval,5,'0'),'&cname'
SQL> /
Enter value for cname: JAN
old
1: insert into cust values('C'||lpad(s1.nextval,5,'0'),'&cname'
new
1: insert into cust values('C'||lpad(s1.nextval,5,'0'),'JAN'
insert into cust values('C'||lpad(s1.nextval,5,'0'),'JAN'
*
ERROR at line 1:
ORA-00917: missing comma
SQL> ed
Wrote file afiedt.buf
1* insert into cust values('C'||lpad(s1.nextval,5,'0'),'&cname')
SQL> /
Enter value for cname: JAN
old
1: insert into cust values('C'||lpad(s1.nextval,5,'0'),'&cname')
new
1: insert into cust values('C'||lpad(s1.nextval,5,'0'),'JAN')
insert into cust values('C'||lpad(s1.nextval,5,'0'),'JAN')
*
ERROR at line 1:
ORA-01722: invalid number
SQL> ed
Wrote file afiedt.buf
1* insert into cust values('C'||lpad(s1.nextval,5,'0'),'&cname')
SQL>
SQL>
SQL>
SQL>
SQL> drop table cust purge;
Table dropped.
SQL> ed
Wrote file afiedt.buf
line 3 truncated.
1
create table cust
2
(cid varchar2(6),
3*
cname varchar2(20)
SQL> /
cname varchar2(20)
*
ERROR at line 3:
ORA-00907: missing right parenthesis
SQL> ed
Wrote file afiedt.buf
1
create table cust
2
(cid varchar2(6),
3*
cname varchar2(20))
SQL> /

Table created.
SQL> insert into cust values(lpad(s1.nextval,5,'0'),'&cname');
Enter value for cname: JAN
old
1: insert into cust values(lpad(s1.nextval,5,'0'),'&cname')
new
1: insert into cust values(lpad(s1.nextval,5,'0'),'JAN')
1 row created.
SQL> select *from cust;
CID
CNAME
------ -------------------00007 JAN
SQL> /
CID
CNAME
------ -------------------00007 JAN
SQL> drop sequence s1;
Sequence dropped.
SQL> create sequence s1;
Sequence created.
SQL> insert into cust values(lpad(s1.nextval,5,'0'),'&cname')
2 /
Enter value for cname: JAN
old
1: insert into cust values(lpad(s1.nextval,5,'0'),'&cname')
new
1: insert into cust values(lpad(s1.nextval,5,'0'),'JAN')
1 row created.
SQL> /
Enter value for cname: WARD
old
1: insert into cust values(lpad(s1.nextval,5,'0'),'&cname')
new
1: insert into cust values(lpad(s1.nextval,5,'0'),'WARD')
1 row created.
SQL> /
Enter value for cname: EFCODD
old
1: insert into cust values(lpad(s1.nextval,5,'0'),'&cname')
new
1: insert into cust values(lpad(s1.nextval,5,'0'),'EFCODD')
1 row created.
SQL> KING
unknown command "KING" - rest of line ignored.
SQL> /
Enter value for cname: KING
old
1: insert into cust values(lpad(s1.nextval,5,'0'),'&cname')
new
1: insert into cust values(lpad(s1.nextval,5,'0'),'KING')
1 row created.
SQL> select *from cust;

CID
-----00007
00001
00002
00003
00004

CNAME
-------------------JAN
JAN
WARD
EFCODD
KING

SQL> clear screen


SQL> ed
Wrote file afiedt.buf
1* select '
SQL> /

oracle' from dual

'ORACLE'
------------------------oracle
SQL> clear screen
SQL> /
'ORACLE'
------------------------oracle
SQL> ed
Wrote file afiedt.buf
1* select ltrim('
2 /

oracle')

from dual

oracle')

from dual

LTRIM(
-----oracle
SQL> ed
Wrote file afiedt.buf
1*
2
SQL>
SQL>
SQL>
2
SQL>
SQL>

select ltrim('
clear screen
create user username
exit

También podría gustarte