SlideShare une entreprise Scribd logo
1  sur  4
Anar Godjaev
http://anargodjaev.wordpress.com/

Conditional Control
if <condition> then
...
elsif conditions then
...
else
...
end if;
EX:
if upper(v_last_name) = 'GETZ' then
v_mgr := 102;
end if;
case
when
when
...
else
end;

selector
expression then result
expression then result
result

EX:
declare
v_grade char(1) := 'B';--upper(g_p_grade);
v_appraisal varchar2(20);
begin
v_appraisal :=
case v_grade
when 'A' then 'Excellent'
when 'B' then 'Very Good'
when 'C' then 'Good'
else 'No grade'
end;
dbms_output.put_line('grade ' || v_grade || ' apraisal ' ||v_appraisal);
end;

Loop:
Basic loop, for loop, while loop
Loop
...
Exit when condition;
End loop
While condition loop
...
End loop
For counter in [reverse] lower bound ... upper bound loop
End for

Cursors:
Declare -> open -> fetch -> if empty then -> close
Create cursor -> open it –> load the current row into variables -> test for empty -> close
EX:
declare
Anar Godjaev
http://anargodjaev.wordpress.com/
cursor emp_cursor is
select employee_id, last_name from employees;
cursor dept_cursor is
select * from departments where location_id=170;
begin
open emp_cursor;
open dept_cursor;
loop
exit when emp_cursor%NOTFOUND;
fetch emp_cursor into v_id , v_last;
end loop;
close emp_cursor;
close dept_cursor;
end;

Cursor Attributes:
<cursor_name>%ISOPEN
<cursor_name>%NOTFOUND
<cursor_name>%FOUND
<cursor_name>%ROWCOUNT
EX:
/**
SQL%ROWCOUNT number of rows affected by the most recent sql satement
SQL%FOUND returns true if the most recent sql statement affected any rows
SQL%NOTFOUND returns true if the most recent sql statement affected no rows
SQL%ISOPEN returns true if the cursor is open, if close then returns false

**/
declare
v_employee_id employees.employee_id%TYPE := 176;
rows_deleted varchar2(30);
begin
delete from employees where employee_id = v_eployee_id ;
rows_deleted := sql%ROWCOUNT || ' rows deleted';
dbms_output.put_line(rows_deleted);
end;

Cursor and Records:
EX:
declare
cursor emp_cursor is
select employee_id, last_name from employees;
emp_record emp_cursor%ROWTYPE;
begin
open emp_cursor;
loop
fetch emp_cursor into emp_record;
exit when emp_cursor%NOTFOUND;
insert into temp_list
(emp_id, emp_name)
values
(emp_Record.employee_id, emp_record.last_name);
end loop;
commit;
Anar Godjaev
http://anargodjaev.wordpress.com/
close emp_cursor;
end;
EX:
Declare
type cur_type is ref cursor;
c1 cur_type;
r1 v$datafile%ROWTYPE;
Begin
open c1 for select * from v$datafile;
loop
fetch c1 into r1;
exit when c1%NOTFOUND;
Dbms_output.put_line(r1.name);
end loop;
/*
For r1 in c1
Loop
Dbms_output.put_line(r1.name);
End loop;
*/
End;

Cursors with parameters:
EX:
declare
cursor emp_cursor (p_deptno number, p_job varchar2) is
select employee_id, last_name from employees
where department_id = p_deptno
and job_id = p_job;
begin
open emp_cursor (80,'sales_rep');
close emp_cursor;
open emp_cursor (60,'it_prog');
-- ..
end;

Exception Handling:
1- predefined oracle server error
2- non predefined oracle server error
3- user defined error
predefined oracle server errors:
no_data_found //single row select returned no data
too_many_rows //single row select returned more than one row
invalid_cursor //illegal cursor operation
zero_devide //attempted to devide by zero
dup_val_on_index //attempted to insert a duplicate value
cursor_already_open
invalid_number //convertion of char string to a number
login_denied
EX:
begin
--...
Anar Godjaev
http://anargodjaev.wordpress.com/
null;
exception
when no_data_found then
--...
null;
when too_many_rows then
--...
null;
end;

user defined oracle server errors:
EX:
declare
e_invalid_department exception;
begin
update departments set department_name = g_v_department_name
where department_id = g_v_department_number;
if sql%NOTFOUND then
raise e_invalid_department;
end if;
commit;
exception
when e_invalid_department then
dbms_output.put_line ('no such dept id ');
end;
EX:
delete from employees where manager_id = v_mngr;
if sql%NOTFOUND then
raise_application_error (-20202, 'not valid manager');
end if;
--OR
...
Exception
when no_data_found then
Raise_application_error ('no data found');
End;

Contenu connexe

Tendances

C++ control structure
C++ control structureC++ control structure
C++ control structurebluejayjunior
 
Checking Wine with PVS-Studio and Clang Static Analyzer
Checking Wine with PVS-Studio and Clang Static AnalyzerChecking Wine with PVS-Studio and Clang Static Analyzer
Checking Wine with PVS-Studio and Clang Static AnalyzerAndrey Karpov
 
LET US C (5th EDITION) CHAPTER 4 ANSWERS
LET US C (5th EDITION) CHAPTER 4 ANSWERSLET US C (5th EDITION) CHAPTER 4 ANSWERS
LET US C (5th EDITION) CHAPTER 4 ANSWERSKavyaSharma65
 
Conditional statements
Conditional statementsConditional statements
Conditional statementsNabishaAK
 
paraproject_Markov_Chain
paraproject_Markov_Chainparaproject_Markov_Chain
paraproject_Markov_Chain? ?
 
Datastructures asignment
Datastructures asignmentDatastructures asignment
Datastructures asignmentsreekanth3dce
 
Data structure circular list
Data structure circular listData structure circular list
Data structure circular listiCreateWorld
 
C Language - Switch and For Loop
C Language - Switch and For LoopC Language - Switch and For Loop
C Language - Switch and For LoopSukrit Gupta
 
Exception handling c++
Exception handling c++Exception handling c++
Exception handling c++Jayant Dalvi
 

Tendances (18)

Loops
LoopsLoops
Loops
 
C++ control structure
C++ control structureC++ control structure
C++ control structure
 
Exceptions
ExceptionsExceptions
Exceptions
 
Checking Wine with PVS-Studio and Clang Static Analyzer
Checking Wine with PVS-Studio and Clang Static AnalyzerChecking Wine with PVS-Studio and Clang Static Analyzer
Checking Wine with PVS-Studio and Clang Static Analyzer
 
LET US C (5th EDITION) CHAPTER 4 ANSWERS
LET US C (5th EDITION) CHAPTER 4 ANSWERSLET US C (5th EDITION) CHAPTER 4 ANSWERS
LET US C (5th EDITION) CHAPTER 4 ANSWERS
 
Conditional statements
Conditional statementsConditional statements
Conditional statements
 
paraproject_Markov_Chain
paraproject_Markov_Chainparaproject_Markov_Chain
paraproject_Markov_Chain
 
Datastructures asignment
Datastructures asignmentDatastructures asignment
Datastructures asignment
 
Decision Making and Looping
Decision Making and LoopingDecision Making and Looping
Decision Making and Looping
 
Catch and throw blocks
Catch and throw blocksCatch and throw blocks
Catch and throw blocks
 
Data structure circular list
Data structure circular listData structure circular list
Data structure circular list
 
C Language - Switch and For Loop
C Language - Switch and For LoopC Language - Switch and For Loop
C Language - Switch and For Loop
 
StewartPlatform_cpp
StewartPlatform_cppStewartPlatform_cpp
StewartPlatform_cpp
 
Exception handling c++
Exception handling c++Exception handling c++
Exception handling c++
 
Fila de caracteres
Fila de caracteresFila de caracteres
Fila de caracteres
 
C lab programs
C lab programsC lab programs
C lab programs
 
DHow2 - L6 VHDL
DHow2 - L6 VHDLDHow2 - L6 VHDL
DHow2 - L6 VHDL
 
Handling
HandlingHandling
Handling
 

En vedette

How to protect your sensitive data using oracle database vault / Creating and...
How to protect your sensitive data using oracle database vault / Creating and...How to protect your sensitive data using oracle database vault / Creating and...
How to protect your sensitive data using oracle database vault / Creating and...Anar Godjaev
 
Oracle Golden Gate
Oracle Golden GateOracle Golden Gate
Oracle Golden GateAnar Godjaev
 
Asm disk group migration from
Asm disk group migration from Asm disk group migration from
Asm disk group migration from Anar Godjaev
 
Backup and Recovery
Backup and RecoveryBackup and Recovery
Backup and RecoveryAnar Godjaev
 
Database Vault / Verinin Güvenliği
Database Vault /  Verinin GüvenliğiDatabase Vault /  Verinin Güvenliği
Database Vault / Verinin GüvenliğiAnar Godjaev
 
Audit Mekani̇zmasi
Audit Mekani̇zmasiAudit Mekani̇zmasi
Audit Mekani̇zmasiAnar Godjaev
 
Backup and Recovery Procedure
Backup and Recovery ProcedureBackup and Recovery Procedure
Backup and Recovery ProcedureAnar Godjaev
 
how to protect your sensitive data using oracle database vault
how to protect your sensitive data using oracle database vaulthow to protect your sensitive data using oracle database vault
how to protect your sensitive data using oracle database vaultAnar Godjaev
 

En vedette (12)

Oracle GoldenGate
Oracle GoldenGateOracle GoldenGate
Oracle GoldenGate
 
Wait Interface
Wait InterfaceWait Interface
Wait Interface
 
Tuning SGA
Tuning SGATuning SGA
Tuning SGA
 
Table Partitions
Table PartitionsTable Partitions
Table Partitions
 
How to protect your sensitive data using oracle database vault / Creating and...
How to protect your sensitive data using oracle database vault / Creating and...How to protect your sensitive data using oracle database vault / Creating and...
How to protect your sensitive data using oracle database vault / Creating and...
 
Oracle Golden Gate
Oracle Golden GateOracle Golden Gate
Oracle Golden Gate
 
Asm disk group migration from
Asm disk group migration from Asm disk group migration from
Asm disk group migration from
 
Backup and Recovery
Backup and RecoveryBackup and Recovery
Backup and Recovery
 
Database Vault / Verinin Güvenliği
Database Vault /  Verinin GüvenliğiDatabase Vault /  Verinin Güvenliği
Database Vault / Verinin Güvenliği
 
Audit Mekani̇zmasi
Audit Mekani̇zmasiAudit Mekani̇zmasi
Audit Mekani̇zmasi
 
Backup and Recovery Procedure
Backup and Recovery ProcedureBackup and Recovery Procedure
Backup and Recovery Procedure
 
how to protect your sensitive data using oracle database vault
how to protect your sensitive data using oracle database vaulthow to protect your sensitive data using oracle database vault
how to protect your sensitive data using oracle database vault
 

Similaire à Conditional Control

Oracle - Program with PL/SQL - Lession 06
Oracle - Program with PL/SQL - Lession 06Oracle - Program with PL/SQL - Lession 06
Oracle - Program with PL/SQL - Lession 06Thuan Nguyen
 
The Story About The Migration
 The Story About The Migration The Story About The Migration
The Story About The MigrationEDB
 
Oracle - Program with PL/SQL - Lession 04
Oracle - Program with PL/SQL - Lession 04Oracle - Program with PL/SQL - Lession 04
Oracle - Program with PL/SQL - Lession 04Thuan Nguyen
 
Lecture05 abap on line
Lecture05 abap on lineLecture05 abap on line
Lecture05 abap on lineMilind Patil
 
Good Evils In Perl (Yapc Asia)
Good Evils In Perl (Yapc Asia)Good Evils In Perl (Yapc Asia)
Good Evils In Perl (Yapc Asia)Kang-min Liu
 
java compilerCompiler1.javajava compilerCompiler1.javaimport.docx
java compilerCompiler1.javajava compilerCompiler1.javaimport.docxjava compilerCompiler1.javajava compilerCompiler1.javaimport.docx
java compilerCompiler1.javajava compilerCompiler1.javaimport.docxpriestmanmable
 
Control Structures in C
Control Structures in CControl Structures in C
Control Structures in Csana shaikh
 
Jangsehyun final requirement
Jangsehyun final requirementJangsehyun final requirement
Jangsehyun final requirementSehyun Jang
 
Programming in Oracle with PL/SQL
Programming in Oracle with PL/SQLProgramming in Oracle with PL/SQL
Programming in Oracle with PL/SQLlubna19
 
6 c control statements branching &amp; jumping
6 c control statements branching &amp; jumping6 c control statements branching &amp; jumping
6 c control statements branching &amp; jumpingMomenMostafa
 

Similaire à Conditional Control (20)

Verilog_Examples (1).pdf
Verilog_Examples (1).pdfVerilog_Examples (1).pdf
Verilog_Examples (1).pdf
 
Oracle - Program with PL/SQL - Lession 06
Oracle - Program with PL/SQL - Lession 06Oracle - Program with PL/SQL - Lession 06
Oracle - Program with PL/SQL - Lession 06
 
Pl sql programme
Pl sql programmePl sql programme
Pl sql programme
 
Pl sql programme
Pl sql programmePl sql programme
Pl sql programme
 
PLSQL
PLSQLPLSQL
PLSQL
 
The Story About The Migration
 The Story About The Migration The Story About The Migration
The Story About The Migration
 
Menu Driven programs in Java
Menu Driven programs in JavaMenu Driven programs in Java
Menu Driven programs in Java
 
Oracle - Program with PL/SQL - Lession 04
Oracle - Program with PL/SQL - Lession 04Oracle - Program with PL/SQL - Lession 04
Oracle - Program with PL/SQL - Lession 04
 
人力
人力人力
人力
 
PLSQL Cursors
PLSQL CursorsPLSQL Cursors
PLSQL Cursors
 
Lecture05 abap on line
Lecture05 abap on lineLecture05 abap on line
Lecture05 abap on line
 
PL/SQL Blocks
PL/SQL BlocksPL/SQL Blocks
PL/SQL Blocks
 
Sdl Basic
Sdl BasicSdl Basic
Sdl Basic
 
Good Evils In Perl (Yapc Asia)
Good Evils In Perl (Yapc Asia)Good Evils In Perl (Yapc Asia)
Good Evils In Perl (Yapc Asia)
 
java compilerCompiler1.javajava compilerCompiler1.javaimport.docx
java compilerCompiler1.javajava compilerCompiler1.javaimport.docxjava compilerCompiler1.javajava compilerCompiler1.javaimport.docx
java compilerCompiler1.javajava compilerCompiler1.javaimport.docx
 
Plsql
PlsqlPlsql
Plsql
 
Control Structures in C
Control Structures in CControl Structures in C
Control Structures in C
 
Jangsehyun final requirement
Jangsehyun final requirementJangsehyun final requirement
Jangsehyun final requirement
 
Programming in Oracle with PL/SQL
Programming in Oracle with PL/SQLProgramming in Oracle with PL/SQL
Programming in Oracle with PL/SQL
 
6 c control statements branching &amp; jumping
6 c control statements branching &amp; jumping6 c control statements branching &amp; jumping
6 c control statements branching &amp; jumping
 

Plus de Anar Godjaev

Oracle 10g Database Server Kurulum
Oracle 10g Database Server KurulumOracle 10g Database Server Kurulum
Oracle 10g Database Server KurulumAnar Godjaev
 
DataPump ile Single Parititon Export
DataPump ile Single Parititon ExportDataPump ile Single Parititon Export
DataPump ile Single Parititon ExportAnar Godjaev
 
Redologlar ve Yöneti̇mi̇
Redologlar ve Yöneti̇mi̇Redologlar ve Yöneti̇mi̇
Redologlar ve Yöneti̇mi̇Anar Godjaev
 
Veri̇tabani ve Kullanici Yöneti̇mi̇
Veri̇tabani ve Kullanici Yöneti̇mi̇Veri̇tabani ve Kullanici Yöneti̇mi̇
Veri̇tabani ve Kullanici Yöneti̇mi̇Anar Godjaev
 
Instance ve Media Bozukluklarını Inceleme
Instance ve Media Bozukluklarını IncelemeInstance ve Media Bozukluklarını Inceleme
Instance ve Media Bozukluklarını IncelemeAnar Godjaev
 
Oracle Managed Files
Oracle Managed FilesOracle Managed Files
Oracle Managed FilesAnar Godjaev
 
Recovery Manager (RMAN)
Recovery Manager (RMAN)Recovery Manager (RMAN)
Recovery Manager (RMAN)Anar Godjaev
 
Oracle Enterprise Linux 5
Oracle Enterprise Linux 5Oracle Enterprise Linux 5
Oracle Enterprise Linux 5Anar Godjaev
 
Oracle Database 11g R2 Installation
Oracle Database 11g R2 InstallationOracle Database 11g R2 Installation
Oracle Database 11g R2 InstallationAnar Godjaev
 
Oracle Tablespace Yonetimi
Oracle Tablespace YonetimiOracle Tablespace Yonetimi
Oracle Tablespace YonetimiAnar Godjaev
 

Plus de Anar Godjaev (18)

Oracle 10g Database Server Kurulum
Oracle 10g Database Server KurulumOracle 10g Database Server Kurulum
Oracle 10g Database Server Kurulum
 
DataPump ile Single Parititon Export
DataPump ile Single Parititon ExportDataPump ile Single Parititon Export
DataPump ile Single Parititon Export
 
Redologlar ve Yöneti̇mi̇
Redologlar ve Yöneti̇mi̇Redologlar ve Yöneti̇mi̇
Redologlar ve Yöneti̇mi̇
 
Contraints
ContraintsContraints
Contraints
 
Oracle SQL
Oracle SQLOracle SQL
Oracle SQL
 
Veri̇tabani ve Kullanici Yöneti̇mi̇
Veri̇tabani ve Kullanici Yöneti̇mi̇Veri̇tabani ve Kullanici Yöneti̇mi̇
Veri̇tabani ve Kullanici Yöneti̇mi̇
 
Instance ve Media Bozukluklarını Inceleme
Instance ve Media Bozukluklarını IncelemeInstance ve Media Bozukluklarını Inceleme
Instance ve Media Bozukluklarını Inceleme
 
Parallel Server
Parallel ServerParallel Server
Parallel Server
 
Memory Management
Memory ManagementMemory Management
Memory Management
 
LogMiner
LogMinerLogMiner
LogMiner
 
Undo Management
Undo ManagementUndo Management
Undo Management
 
ASM
ASMASM
ASM
 
Oracle Managed Files
Oracle Managed FilesOracle Managed Files
Oracle Managed Files
 
Recovery Manager (RMAN)
Recovery Manager (RMAN)Recovery Manager (RMAN)
Recovery Manager (RMAN)
 
Oracle Enterprise Linux 5
Oracle Enterprise Linux 5Oracle Enterprise Linux 5
Oracle Enterprise Linux 5
 
Oracle Database 11g R2 Installation
Oracle Database 11g R2 InstallationOracle Database 11g R2 Installation
Oracle Database 11g R2 Installation
 
Change DB Name
Change DB NameChange DB Name
Change DB Name
 
Oracle Tablespace Yonetimi
Oracle Tablespace YonetimiOracle Tablespace Yonetimi
Oracle Tablespace Yonetimi
 

Dernier

Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...DianaGray10
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘RTylerCroy
 
HTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation StrategiesHTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation StrategiesBoston Institute of Analytics
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodJuan lago vázquez
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerThousandEyes
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FMESafe Software
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobeapidays
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024Rafal Los
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityPrincipled Technologies
 
Top 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live StreamsTop 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live StreamsRoshan Dwivedi
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...apidays
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MIND CTI
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonAnna Loughnan Colquhoun
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businesspanagenda
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)wesley chun
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoffsammart93
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsJoaquim Jorge
 

Dernier (20)

Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
HTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation StrategiesHTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation Strategies
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
Top 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live StreamsTop 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live Streams
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
 

Conditional Control

  • 1. Anar Godjaev http://anargodjaev.wordpress.com/ Conditional Control if <condition> then ... elsif conditions then ... else ... end if; EX: if upper(v_last_name) = 'GETZ' then v_mgr := 102; end if; case when when ... else end; selector expression then result expression then result result EX: declare v_grade char(1) := 'B';--upper(g_p_grade); v_appraisal varchar2(20); begin v_appraisal := case v_grade when 'A' then 'Excellent' when 'B' then 'Very Good' when 'C' then 'Good' else 'No grade' end; dbms_output.put_line('grade ' || v_grade || ' apraisal ' ||v_appraisal); end; Loop: Basic loop, for loop, while loop Loop ... Exit when condition; End loop While condition loop ... End loop For counter in [reverse] lower bound ... upper bound loop End for Cursors: Declare -> open -> fetch -> if empty then -> close Create cursor -> open it –> load the current row into variables -> test for empty -> close EX: declare
  • 2. Anar Godjaev http://anargodjaev.wordpress.com/ cursor emp_cursor is select employee_id, last_name from employees; cursor dept_cursor is select * from departments where location_id=170; begin open emp_cursor; open dept_cursor; loop exit when emp_cursor%NOTFOUND; fetch emp_cursor into v_id , v_last; end loop; close emp_cursor; close dept_cursor; end; Cursor Attributes: <cursor_name>%ISOPEN <cursor_name>%NOTFOUND <cursor_name>%FOUND <cursor_name>%ROWCOUNT EX: /** SQL%ROWCOUNT number of rows affected by the most recent sql satement SQL%FOUND returns true if the most recent sql statement affected any rows SQL%NOTFOUND returns true if the most recent sql statement affected no rows SQL%ISOPEN returns true if the cursor is open, if close then returns false **/ declare v_employee_id employees.employee_id%TYPE := 176; rows_deleted varchar2(30); begin delete from employees where employee_id = v_eployee_id ; rows_deleted := sql%ROWCOUNT || ' rows deleted'; dbms_output.put_line(rows_deleted); end; Cursor and Records: EX: declare cursor emp_cursor is select employee_id, last_name from employees; emp_record emp_cursor%ROWTYPE; begin open emp_cursor; loop fetch emp_cursor into emp_record; exit when emp_cursor%NOTFOUND; insert into temp_list (emp_id, emp_name) values (emp_Record.employee_id, emp_record.last_name); end loop; commit;
  • 3. Anar Godjaev http://anargodjaev.wordpress.com/ close emp_cursor; end; EX: Declare type cur_type is ref cursor; c1 cur_type; r1 v$datafile%ROWTYPE; Begin open c1 for select * from v$datafile; loop fetch c1 into r1; exit when c1%NOTFOUND; Dbms_output.put_line(r1.name); end loop; /* For r1 in c1 Loop Dbms_output.put_line(r1.name); End loop; */ End; Cursors with parameters: EX: declare cursor emp_cursor (p_deptno number, p_job varchar2) is select employee_id, last_name from employees where department_id = p_deptno and job_id = p_job; begin open emp_cursor (80,'sales_rep'); close emp_cursor; open emp_cursor (60,'it_prog'); -- .. end; Exception Handling: 1- predefined oracle server error 2- non predefined oracle server error 3- user defined error predefined oracle server errors: no_data_found //single row select returned no data too_many_rows //single row select returned more than one row invalid_cursor //illegal cursor operation zero_devide //attempted to devide by zero dup_val_on_index //attempted to insert a duplicate value cursor_already_open invalid_number //convertion of char string to a number login_denied EX: begin --...
  • 4. Anar Godjaev http://anargodjaev.wordpress.com/ null; exception when no_data_found then --... null; when too_many_rows then --... null; end; user defined oracle server errors: EX: declare e_invalid_department exception; begin update departments set department_name = g_v_department_name where department_id = g_v_department_number; if sql%NOTFOUND then raise e_invalid_department; end if; commit; exception when e_invalid_department then dbms_output.put_line ('no such dept id '); end; EX: delete from employees where manager_id = v_mngr; if sql%NOTFOUND then raise_application_error (-20202, 'not valid manager'); end if; --OR ... Exception when no_data_found then Raise_application_error ('no data found'); End;