Archive for the ‘Oracle’ Category

Compiling PL/SQL and using TOAD to write stored procedures

June 12th, 2013, posted in Oracle
Share

Compiling PL/SQL and using TOAD to write stored procedures :


  • PL/SQL compiler (version?) is quite stupid: ” Missing a semi-colon flags a line several lines below where the actual semi-colon is missing.”  Likewise for a missing single quote character
  • To escape the single quote character, double it.”  Therefore four consecutive single quotes is a string consisting of a single quote
  • When the compiler reports a compiler error at a certain line, that line # is relative to the start of the Body of stored procedure (assuming you are editing the Body and not the Spec)
  • To compile and “save” your stored procedure to the Oracle server in TOAD, be sure to use the “Execute As Script” button () in the Editor.  Do NOT use the “Execute/compile statement at caret” button.

    link : http://buildingaircastles.blogspot.com/2010/11/compiling-plsql-and-using-toad-to-write.html

  • Share

    Oracle : Activate Oracle on XAMPP for Windows : OCI8 : XAMPP ORACLE CONFIGURATION

    March 1st, 2013, posted in Oracle, PHP
    Share

    If you want to connect with Oracle database using PHP script you will have to do some effort. Because with the default installation of XAMPP for Windows, we don’t get PHP Oracle connectivity enabled. This can be enabled easily when you need to connect to a Oracle Database from your PHP application/script. PHP has got the OCI8 extension, which provides Oracle connectivity to PHP application, and OCI8 uses Oracle Instant Client Package to get Oracle specific functions.

    I had the need to connect to a Oracle Database from a PHP script in one of my recent projects, the following is what I did to enable Oracle connectivity in XAMPP for Windows.

    1. In your XAMPP Start Page, go to phpinfo, look for string oci8. If string found it indicate that connection to oracle is available, otherwise to activate connection do the following steps:
    2. Open the currently used php.ini file by looking at the phpinfo, from the XAMPP folder.
    3. Find string ;extension=php_oci8.dll. Remove the semicolon (;) ahead of the string to activate the oracle extension.
    4. Save the php.ini file.
    5. Download the “Instant Client Package – Basic” for Windows from the OTN Instant Client page. Unzip it to c:instantclient_11_1
    6. Edit the PATH environment setting and add c:instantclient_11_1 before any other Oracle directories. For example, on Windows XP, follow Start -> Control Panel -> System -> Advanced -> Environment Variables and edit PATH in the System variables list.
    7. Set desired Oracle globalization language environment variables such as NLS_LANG. If nothing is set, a default local environment will be assumed. See An Overview on Globalizing Oracle PHP Applications for more details.
    8. Unset Oracle variables such as ORACLE_HOME and ORACLE_SID, which are unnecessary with Instant Client (if they are set previously).
    9. Restart XAMPP (or Start if its not already started).
    10. To make sure that connection to oracle database has successfully activated, go to phpinfo. Find string: oci8. If found, then XAMPP can now communicate with Oracle Database.

    The steps to do the same on Linux are almost similar, except there you will use the Linux versions of the packages and setting PATH variables would be different.

    To test the connection you can use this script

    <?php
    $conn = oci_connect('username', 'password', 'host:port/servicename');
    $query = 'select table_name from user_tables';
    $stid = oci_parse($conn, $query);
    oci_execute($stid, OCI_DEFAULT);
    while ($row = oci_fetch_array($stid, OCI_ASSOC)) {
    foreach ($row as $item) {
    echo $item." | ";
    }
    echo "
    n";
    }
    oci_free_statement($stid);
    oci_close($conn);
    ?>

    *****************************************************************************************

    If you need to configure your xampp installation (on winXP) to connect to the oracle

    – first you need to download oracle basic instant client for windows

    – After unzipping the instant client on a selected directory (i.e. c:/instantclient_11_1) you need to copy all dlls from this directory to “xampp/apache/bin/”

    – Add instant client directory to windows system variable’s path : follow Start -> Control Panel -> System -> Advanced -> Environment Variables and edit PATH in the System variables list

    – now open up php.ini from “xampp/php” and remove semicolon from this line “;extension=php_oci8.dll”

    all you have to do is restarting apache and you’re all set

    Another wonderful link for this topic is : http://me2learn.wordpress.com/2008/10/18/connect-php-with-oracle-database/

    Share

    ORACLE : How to Calculate Average of Date Values ?

    February 25th, 2013, posted in Oracle Queries
    Share

    Are you getting trouble of calculating average time of a filed, where data type is date time ?
    Don’t worry. You are at right place to get right solution.

    I’m going to calculate average time of a filed.
    If there is two time value in a day, i will calculate the first one means minimum one.

    SELECT TO_CHAR(TRUNC(SYSDATE)+AVG(VDATE-TRUNC(VDATE)),’HH24:MI:SS’)
    FROM (SELECT MIN(DDATE) VDATE
    FROM DEPT
    GROUP BY TRUNC(DDATE))

    ****************************************************************************************************************
    Note : Please not do make backups before using these queries and also confirm them yourself or by aother means as
    well.
    *****************************************************************************************************************
    Share

    ORACLE :How to Configure Net8 in Non-RAC Database

    February 17th, 2013, posted in Oracle
    Share

    To access the database from other than the system in which database installed you need to configure oracle supplies Net8 for this purpose. It is a common interface to client application that needs to connect to the oracle database. It consists of the three files: tnsname.ora, listener.ora, sqlnet.ora.

    Steps or Process:
    1.      Edit the tnsname.ora file and add the new service name for use by the client software.
    2.      Edit the listener.ora file add an entry for another database instance.
    3.      Use the ping command to verify connectivity to the Host.
    4.      Use the tnsping command to verify the connectivity to the Net8 listener.
    5.      Start/Stop the Net8 listener to reload newly added DB instance.
    6.      Connect to a remote database over the network.

    tnsname.ora:
    The normal location for this file is D:oracleora92networkadmin. This file is located on both client and server. If you make configuration changes on the server ensure you can connect to the database through the listener if you are logged on to the server. If you make configuration change on the client ensure you can connect from your client workstation to the database through the listener running on the server.
    Add the following entry in your tnsname.ora file and change the value in the bracket according to your environment.
    RMAN.AL-SADHAN.COM =
    (DESCRIPTION =
    (ADDRESS_LIST =
    (ADDRESS = (PROTOCOL = TCP)(HOST = rmanbackup)(PORT = 1521))
    )
    (CONNECT_DATA =
    (SERVER = DEDICATED)
    (SERVICE_NAME = RMAN)
    )
    )

    Note: You can put either system name or directly static IP (192.168. 0.1) as HOST.
    C:tnsping rman
    Use the above command to verify the connectivity on windows environment.

    listener.ora:
    The normal location for this file is D:oracleora92networkadmin. This file is client side file (typically on remote PC). The client uses thistnsname.ora file to obtain connection details from the desired database. Add the following entry in your listener.ora file and changed the value in bracket as per your environment.
    SID_LIST_LISTENER =
    (SID_LIST =
    (SID_DESC =
    (SID_NAME = PLSExtProc)
    (ORACLE_HOME = D:oracleora92)
    (PROGRAM = extproc)
    )
    (SID_DESC =
    (GLOBAL_DBNAME = RMAN)
    (ORACLE_HOME = D:oracleora92)
    (SID_NAME = RMAN)
    )
    )

    Note: Provide the unique global name as you specify at the time of database creation. You can change it later with your own domain name.

    SQL>ALTER DATABASE rename global_name to rman.al-sadhan.com;
    C:lsnrctl
    Lsnrctl>stop listener
    Lsnrctl>start listener
    Lsnrctl>reload listener
    You can use above command to bounce the listener.

    sqlnet.ora:
    The normal location for this file is D:oracleora92networkadmin. The sqlnet.ora file is the profile configuration file, and it resides on the client machines and the database server. The sqnet.ora is text file that contain basic configuration details used by the SQL*Net.
    NAMES.DEFAULT_DOMAIN = al-sadhan.com
    SQLNET.AUTHENTICATION_SERVICES= (NTS)
    NAMES.DIRECTORY_PATH= (TNSNAMES, ONAMES, HOSTNAME)
    trace_level_client = OFF
    sqlnet.expire_time = 30
    names.default_domain:  If the net service name does not have a domain specified, this parameter value is appended to the service name.

    names_directory_path: This parameter specifies the order of naming methods used when a client attempts a connection to a database. Possible values include: LDAP; TNSNAMES; HOSTNAME; ONAMES; and EZCONNECT.
    sqlnet.expire_time:  This parameter, set on the server, enables dead connection detection.  After the specified time interval, expressed in minutes, the server checks to see if the client is still connected. If the client is not still connected, the server process exits.

    sqlnet.authentication_services: This parameter is used to enable one or more authentication services.  There is no default setting, so if authentication has been installed, it this parameter should be set to either NONE for no authentication methods or ALL for all authentication methods.

    trace_level_client: This parameter enables tracing unless it is set to OFF or 0, which is the default.  Use the following values to set tracing levels: USER (4); ADMIN (10); and SUPPORT (16).

    *********************************************************************************************************************
    Note : Please not do make backups before using these queries and also confirm them yourself or by aother means as
     well.
    *********************************************************************************************************************
    Share

    ORACLE : How to Check Only One Item In a Check Box ?

    February 7th, 2013, posted in Oracle Queries
    Share

    Here i will share a tricky PL/SQL code with you.
    If you want to use Check Box in oracle forms and want to restrict end user to select only one check box, how will you handle this ?

    Just customize the following code and you will get the result :

    declare
    l_current_record number;
    l_last_record    number;
    begin
    l_current_record := :system.trigger_record;

    last_record;
    l_last_record := :system.cursor_record;

    first_record;

    for i in 1 .. l_last_record loop
    if :system.cursor_record <> l_current_record then
    :SM_ACT_FLAG := 0;
    end if;
    next_record;
    end loop;

    go_record(l_current_record);
    end;

    *********************************************************************************************************************
    Note : Please not do make backups before using these queries and also confirm them yourself or by aother means as
     well.
    ********************************************************************************************************************
    Share