oracledba.help
QuickStarts

Scripting Quickstart

<- QuickStarts

Overview

When tackling a new scripting or programming language for use with Oracle there are a recurring set of core topics. If you simply focus on these you will get up-to-speed more quickly and it will be a lot less stressful. Maybe even enjoyable!

This is focused on Oracle System DBA support. If you need to have a script to calculate Pi to the last digit or extract stock prices of Eastern Prussian investments it is not covered here. I have found focusing on this small set of topics really jump starts one getting to the point of practicality in Oracle production environment support.

Core Oracle Scripting Topics

  • Output to console\device.
  • Assigning and outputting variables.
  • Get input via user and script parameter.
  • If\Else comparisons and operators.
  • Case or Switch statements.
  • Loops (including looping through an array).
  • Test if a directory and file exists.
  • Delete a file.
  • Create\append to a log file.
  • Get a value from a config file (.xml, .ini, .conf etc.).
  • Put a small file's contents into a variable.
  • Output date and time in multiple common formats.
  • Extract the running scripts name.
  • Include File and\or code reuse structure.
  • Run an executable program and pass it parameters.
  • Send an email.
  • String manipulation (contains, length, position, substring, trim, toLower, toUpper etc.).
  • Error block dispatching (usually a try-catch derivative).
  • Oracle
    • Connect to an Oracle database.
    • Get a specific value from the database (like the version number etc.).
    • Output values in an Oracle table.
    • Execute a SQL statement.
  • If OOP can be used:
    • Create an object (AKA class).
    • Get and set an object value.
    • Call an object method.
    • Use a constructor (set default values for object, AKA initialize).

Create a Core Script Library

A great investment in time is to create a script for each of these. From that point you have a model all the core topics for quick retrieval. Furthermore, in each language you must use, if you create each of these using the same file prefix name you can learn even faster having a cross reference.

Example:

  • FileExists.bat
  • FileExists.php
  • FileExists.py

Each in there own directory of course. Respectively: \bat, \php, \py.

File List for Core Topics

HelloWorld.x
Vars.x
Input.x
If-Else.x
Case-Switch.x
Loops.x
DirExists.x
FileExists.x
FileDelete.x
LogWrite.x
File2Var.x
FileValue2Var.x
DateTime.x
ScriptName.x
Include1.x
Include2.x
App_run.x
Email_send.x
Strings.x
ErrorBlock.x
Oracle_connect.x
Oracle_getValue.x
Oracle_getTable.x
Oracle_execSQL.x
oop_createObj.x
oop_getObjValue.x
oop_setObjValue.x
oop_runObjMethod.x
oop_initObj.x

Update Your Script Examples After the First Pass

The programmer that started learning the new computer language\script is not the same programmer that completed creation of all these example scripts. Going back and taking the minimal time to tweak them, applying what you learned, sets the model for best practices and standardization in your environment. This will come back to you many fold.

Also, all developers\DBAs that come on board can get up-to-speed faster in a manner that promotes enterprise implementation of the language\script.

<- QuickStarts