Review Gadget

descriptions of all the gadgets specification.

12

Basic Operation Data Base

Basic Operation Data Base
In a disk, the database can be created and can also be eliminated. In a disk, we can also put some (more than one) database. While in a database we can put one or more files / tables. In the file / table is in fact the data is stored / placed.
A general database created to represent a specific universe of data. For example databases of personnel, academic databases, inventory databases (warehousing) and so on. In academic databases, for example, we can put the files of subjects, teachers' files, schedule files, the file value and so on.
Therefore, the basic operations we can do regarding the databases may include:
- Creating a new database (create database) which is identical to the creation rasip new cabinet.
- Elimination of the database (drop database) which is identical with the destruction rasip closet.
- Making the file / new table to a database (create table), identical with the addition of new file folder.
- Elimination of the file / table from a database (drop table).
- Addition / new data charging to a file / table in a database.
- Retrieving data from a file / table.
- Changing the data from a file / table.
- Elimination of data from a file / table.

Operations relating to the making of the object (and database tables) is an initial operation performed only once and applies onwards, while the operations associated with filling the table is the routine operations carried out repeatedly and therefore operations This represents a more appropriate management activities (Management) and processing (processing) data in the database.
Destination Database
It was mentioned that the main purpose of the database pengelolaaan in a database is that we can rediscover our search ynag data easily and quickly. A more complete utilization of the database is to fulfill some purpose (objective) such as:
1. The speed and ease (speed)
Utilization of the database allows us to be able to save data or make changes / manipulation of data or display the returned data faster and easier, than we store data manually (non electronic).
2. Storage Space Efficiency (Space)
Because of close linkages between groups in the database, then the redundancy (repetition) of data must always be there. With databases, the efficiency / optimalisai use of storage space can be done because we can do emphasis the amount of data redundancy, either apply a number of encoding or creating relationships (in the form of files) between groups of interconnected data.
3. Accuracy (Accuracy)
Utilization of the coding or the formation of relationships between the data together with the application of rules / constraints (constraints) data type, data domain, the uniqueness of the data and the like which can be applied strictly in a database, it is useful to suppress the inaccuracies / data storage.
4. Availability (Availability)
The growth of data over time will increasingly require large storage space. And not all the data we always use / need. Hence, we can perform sorting of data, so the data we use is rare that we can move into the storage media off-line. On the other hand, because the interests of data usage, a database may have data spread across many geographic locations. For example, a bank customer data separated and stored in separate locations in accordance with the presence of customers. With the use of computer network technology, data residing in a location / branch, can also be accessed (to be available / avaible) for other locations.
5. Completeness (Completeness)
To accommodate the needs of the completeness of data is growing, so we are not only able to add data records, but also can make changes in database structure, both in the addition of new objects (tables) or by the addition of new field-filed at a table.
6. Security (Security)
There are a number of systems (applications) database managers that do not implement the security aspects in a database. But for a large system and serious, security aspects can also be applied strictly. That way, we can determine no one (user) is allowed to use its database objects in it and determine the types of operations what to do.
7. Togetherness Usage (Sharebility)
The user database is often not limited to one user only, or in one location only by a single application system. Employee data in the personnel database, for example, can be used by many users, from a number of departments within the company or by multiple systems (payroll systems, accounting systems, inventory systems and so on). The database is managed by the system (application) which supports multiuser environments will be able to meet this need, but still with maintaining / avoid the emergence of new problems such as data inconsistencies (due to the same data can be modified by many users at a time bers0amaan) or a deadlock condition ( because many users wait for each other to use the data)

Database Application

Database Application
Almost perangakat in all aspects of computer use in an organization is always associated with the database. Computing devices are usually used to perform the function of Management Information Systems, which today has become a necessity, in order to improve efficiency, competitiveness, kekuratan, organizations operating speed. And the database is one of the main components in each system information. There is no information system can be created / executed without any database.
In more technical areas of common yan has used the database for efficiency, accuracy and speed of operation include:

�� Officer, for a variety of companies that have many employees.
�� warehousing (inventory), for manufacturing firms (manufacturers), wholesalers (resellers), pharmacies, etc..
�� Accounting for various companies.
�� Reservation, for hotels, planes, trains, etc. APAI
�� customer service (customer care), to companies associated with bnayaknya customers (banks, consultants, etc.)
Are forms of organization that uses the database (as a component information system) can be:
�� Banking, in conducting customer data management / data saving / borrowing, making accounting reports, accounting, customer information services / prospective customers.
�� Insurance, in conducting customer data management / data premium payments, processing insurance claims filing, etc..
�� Hospital, in managing the disease history / treatment pasen, handling maintenance payments.
�� Goods Manufacturers, in managing the data in and out, of goods (inventory).
�� manufacturing industry, in order to help the management of goods, managing employee data.
�� Education / schools, in helping students pengelola0an data, scheduling.
�� Telecommunications, in doing administration data cable management / customer data, etc. to handle noise.

select (oracle)

One of the most important syntax in SQL is select. Select function to display the data in the tables contained in the database. This is where there are many differences between regular SQL and Oracle SQL. Oracle lot summarizes syntax into simpler syntax although also remain memerima oracle SQL strandar.

SELECT
[tb1].[nama_kolom1],
[tb2].[nama_kolom2], . . .
FROM
[nama_tabel1] [tb1],
[nama_tabel2] [tb2]
WHERE
[kondisi_join]
[operator_boolean] [kondisi_select]
ORDER BY [nama_kolom_order]
GROUP BY [nama_kolom_group];

Description:
tb: Alias of [nama_tabel1]
nama_kolom: Name columns to display
kondisi_join: If the FORM clause there are two or more tables then there should be this condition is menjoinkan table-table in clause
operator_boolean: operator-like kondisi_join operator for AND and OR
kondisi_select: Conditions addition to perfecting this SELECT operation. Usually using comparison operations, such as:>, <,> =, <=, BETWEEN, <>
nama_kolom_order: SELECT results to the sort by the nama_kolom.
nama_kolom_group: SELECT Results to nama_kolom classified based. So all the records of the same value will be issued only one record only. Noteworthy is that all fields must be in the SELECT GROUP BY a.

Before clarified with an example is better for us to fill the data for the tables we have made in the article Create Table "Teaching-Learning System" - (Analysis & Design). Script to fill in the data please download it here.

1. Displaying all students with grade I sorted by student name.

SELECT
NAMA,
ALAMAT
FROM
TEST.MURID
WHERE
KELAS_ID = ‘I’ /*[kondisi_select]*/
ORDER BY NAMA, NIS; /*[nama_kolom_order]*/

2. Displaying the teachers who teach biology.

SELECT
g.NIG,
b.NAMA
FROM
TEST.GURU g,
TEST.BELAJAR b
WHERE
g.NIG = b.NIG /*[kondisi_join]*/
AND b.KODE_MP = ‘DA0007′ /*[kondisi_select]*/
GROUP BY g.NIG, g.NAMA; /*[nama_kolom_group]*/

Insert, Update, Delete (Oracle)

Standard operation is a database insert, delete and update. The three so-called DML stands for Data Manipulation Language. SQL is a standard language for database processing. Of course, any use Oracle-SQL, only a few characteristics that differ from standard SQL.

Once we started discussing the "Try-try" Oracle, then we have a separate user is a user named TEST. Please go to your page or in Oracle XE to SQL + (if you install another version of the oracle, for example: 8i, 9i, 10g, and you also must enter hostring / tnsnames your database) and login with the user, namely:

User TEST
Password test

INSERT

Insert is used to enter data into a table in the user (schema) specific. Insert syntax can be written as follows:

INSERT INTO [nama_user].[nama_table]

([nama_kolom1], [nama_kolom2], . . .)

VALUES

([nilai1], [nilai2], . . .);

Description:
username: user name or schema name when logged in
nama_tabel: Name of the table contained in the user (schema) is
nama_kolom: Name of the column that will contain the data in [nama_tabel]
value: The value that will be filled in [nama_kolom], eg: [value1] will be populated into the [nama_kolom1], [value2] will be populated into the [nama_kolom2]
UPDATE

Update is used to change the data in a table in the user (schema) based on certain specific conditions. Update syntax can be written as follows:

UPDATE [nama_user].[nama_table]SET

[nama_kolom1] = [nilai1],

[nama_kolom2] = [nilai2],

[nama_kolom3] = [nilai3],

. . .

WHERE

[kondisi_update];

Description:
username: user name or schema name when logged in
nama_tabel: Name of the table contained in the user (schema) is
nama_kolom: Name of the column that will contain the data in [nama_tabel]
value: The value that will be filled in [nama_kolom]
kondisi_update: A condition that the filter (filter) which records all that will be updated
DELETE

Delete is used to delete data on a table in the user (schema) based on certain specific conditions. Delete syntax can be written as follows:

DELETE [nama_user].[nama_table]WHERE

[kondisi_delete];

Description:
username: user name or schema name when logged in
nama_tabel: Name of the table contained in the user (schema) is
kondisi_delete: A condition that the filter (filter) the records to be anywhere in the delete

Before reading the example below, a good idea to read the article first Create Table-Teaching and Learning System - (Analysis & Design). The article will help you to understand the examples given, because the tables used are based on case studies.

Insert:

INSERT INTO TEST.MURID (

NIS,
NAMA,
TGL_LAHIR,
JENIS_KELAMIN,
ALAMAT,
ORTU)

VALUES (

‘000001′,
‘MUKHTARUL UMAM’,
TO_DATE(‘23-04-1993′,‘DD-MM-YYYY’),
‘L’,
‘JL. P. DIPENOGORO, TEGAL’,
‘SULAIMAN’);

Update :


UPDATE TEST.MURID SET

NAMA = ‘MUKHTARUL UMAM SHOLEH’,
TGL_LAHIR = TO_DATE(‘25-04-1993′,‘DD-MM-YYYY’)

WHERE

NIS = ‘000001′;

Delete :


DELETE TEST.MURID

WHERE

NIS = ‘000001′;

NB:

* If you want to change the database kept by the end of each DML syntax to execute COMMIT;
* If you do not want to change the alias stored restored to the end with the execution of a ROLLBACK;
* Any DML syntax in COMMIT that it will not be in

Install Oracle Express on Ubuntu

As a step to prepare theses, today I accidentally leave to install Oracle Express on Ubuntu I am. Since yesterday trying to install it but failed because the package must connect to the Internet to install it.

From the results of the download at www.oracle.com installer package [oracle-xe-universal_10.2.1-1.0_i386.deb] and then right-click the Open With GDebi Package Installer.

Then the menu below



Installer package ready to run.



Get ready to walk Installing package file ....



Installing oracle-xe-universal


TRIGGER ORACLE

Ok yesterday, yesterday I was writing an article about Oracle. And this happened again today belajat about his Oracle trigger. Let trigger more applicable here would not talk about his theory, but what I've tried to make it n cases like this nie .... We had to make three tables of goods, transaction history ma. Now each of us to make transactions in the amount of data tables to update things as well. So let check this out ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ...

CREATE OR REPLACE TRIGGER barang

BEFORE INSERT OR UPDATE OR DELETE ON transaksi

FOR EACH ROW

DECLARE

vJum NUMBER(10);

vJum2 NUMBER(10);

vSelisih NUMBER(10);

BEGIN

SELECT jumlah INTO vJum FROM alat WHERE id_barang = :NEW.id_barang;

IF INSERTING THEN

UPDATE alat

SET jumlah = vJum – :NEW.jumlah

WHERE id_barang = :NEW.id_barang;

SELECT jumlah INTO vJum2 FROM alat WHERE id_barang = :NEW.id_barang;

INSERT INTO history (id_barang,tanggal,stock,tipe_transaksi) VALUES(:NEW.id_barang,:NEW.tanggal,vJum2,’Tambah Data’);

ELSIF UPDATING(‘jumlah’) THEN

IF :OLD.jumlah > :NEW.jumlah THEN

vSelisih := :OLD.jumlah – :NEW.jumlah;

UPDATE alat

SET jumlah = vJum + vSelisih

WHERE id_barang = :NEW.id_barang;

SELECT jumlah INTO vJum2 FROM alat WHERE id_barang = :NEW.id_barang;

INSERT INTO history (id_barang,tanggal,stock,tipe_transaksi) VALUES(:NEW.id_barang,:NEW.tanggal,vJum2,’Update Data’);

ELSIF :OLD.jumlah < :NEW.jumlah THEN

vSelisih := :NEW.jumlah – :OLD.jumlah;

UPDATE alat

SET jumlah = vJum – vSelisih

WHERE id_barang = :NEW.id_barang;

SELECT jumlah INTO vJum2 FROM alat WHERE id_barang = :NEW.id_barang;

INSERT INTO history (id_barang,tanggal,stock,tipe_transaksi) VALUES(:NEW.id_barang,:NEW.tanggal,vJum2,’Update Data’);

END IF;

ELSIF DELETING THEN

UPDATE alat

SET jumlah = vJum + :NEW.jumlah

WHERE id_barang = :NEW.id_barang;

INSERT INTO history (id_barang,tanggal,stock,tipe_transaksi) VALUES(:NEW.id_barang,:NEW.tanggal,vJum,’Hapus Data’);

END IF;

EXCEPTION

WHEN NO_DATA_FOUND THEN

DBMS_OUTPUT.PUT_LINE(‘Data tidak ada’);

END;

/

Step Install Oracle 10g R2 on Solaris 10 x86

Checking Requirement:

—————————-

#/usr/sbin/prtconf | grep “Memory size” [Check RAM size]
# /usr/sbin/swap -s [check swap]
# df -k /tmp [check /tmp size (>400mb)]
# uname -r [check solaris version]

# pkginfo -i SUNWarc SUNWbtool SUNWhea SUNWlibm SUNWlibms SUNWsprot SUNWsprox SUNWtoo SUNWi1of SUNWi1cs SUNWi15cs SUNWxwfnt

# cat /etc/nsswitch.conf | grep hosts
# hostname
# domainname

RUN INSTALL:
—————-
A. create group name “dba”, oracle inventory group “oinstall” and “oracle” user

# /usr/sbin/groupadd oinstall
# /usr/sbin/groupadd dba

{Determine oracle user exist or not
# id -a oracle
{if exist, should be look like this=
uid=440(oracle) gid=200(oinstall) groups=201(dba),202(oper)

{create oracle user=
# useradd -d /export/home/oracle -g dba -G oinstall -m -s /bin/ksh oracle

#mkdir /export/home/oracle
#chown oracle:dba /export/home/oracle

{set password=
# passwd -r files oracle

{to determine nobody user=
# id nobody
# /usr/sbin/useradd nobody >>run if does not exist

B. EDIT FILE /export/home/oracle/.profile
————————————–
umask 022
TMP=/tmp
TMPDIR=$TMP
DISPLAY=localhost:0.0
export TMP TMPDIR DISPLAY
ORACLE_BASE=/u01/app/oracle [replace with ur Oracle base Directory]
ORACLE_HOME=/u01/app/oracle/product/10.2.0/db_1 [replace with ur Oracle home Directory]

ORACLE_SID=jktdb [replace with your database]
PATH=$ORACLE_HOME/bin:$PATH
export ORACLE_BASE ORACLE_HOME ORACLE_SID PATH

C. Configure Kernel Parameter
—————————–
Note: Do not follow the official installation instruction, they contain misleading and out errors of fact!

#projadd oracle [This command will create a new 'resource project']
edit the /etc/user_attr file:
adm::::profiles=Log Management
lp::::profiles=Printer Management
root::::auths=solaris.*,solaris.grant;profiles=Web Console Management,All;lock_after_retries=no

oracle::::project=oracle [add this line]

then:

#su – oracle
$ id -p
$ prctl -n project.max-shm-memory -i project oracle

The display look like this:
project: 100: oracle
NAME PRIVILEGE VALUE FLAG ACTION RECIPIENT
project.max-shm-memory
privileged 126MB – deny -
system 16.0EB max deny -

leaving the oracle user still connected in the original one Then, as root in the new terminal, you can issue this command:

#prctl -n project.max-shm-memory -v 4gb -r -i project oracle [create max memory to 4GB]

As soon as you’ve issued that command, switch back to the oracle user’s session and re-issue the earlier command:

$ prctl -n project.max-shm-memory -i project oracle

Note:
#prctl -n project.max-shm-memory -v 4gb -r -i project oracle [this setting will lost after reboot]
to set permanently, run this: #projmod -s -K “project.max-shm-memory=(priv,4gb,deny)” oracle

D. Performing the Oracle Installation
————————————-
#su – oracle
$xhost +
$export DISPLAY=localhost;0.0
$ xhost + >>run this if you install from remote PC
$ cd /export/home/database/ [the source unzipped here]

./runInstaller

FOR SOLARIS SPARC:
====================
$ gunzip ship_rel10_sol64_db.cpio.gz
$ cpio -idm < ship_rel10_sol64_db.cpio

$./runInstaller

If you found unsufficient SWAP disk space on your disk, create folder under / then run this command:
—————————————————
$ TMP=/directory
$ TMPDIR=/directory
$ export TMP TMPDIR

Follow the screen>>NEXT>>NEXT

last, run this as root user:
—————————-
/u01/app/oracle/oraInventory/orainstRoot.sh
/u01/app/oracle/product/10.2.0/db_1/root.sh

Create db:
———-
orc1
jktdb

E. 6.0 On-going Administration
——————————–
Finally, it’s time to get the web-based Enterprise Manager database administration tool up and running.
Since we’re using 10g Release 2, you should be able to launch a browser (Launch -> Web Browser) and simply navigate to : http://localhost:1158/em

If you do not know the correct port number to use, look for the following line in the $ORACLE_HOME/install/portlist.ini file.

in order to be able to log on as SYS with a password of whatever you supplied to the first screen of the Oracle installation wizard. In fact, getting a meaningful result at this point relies on three things having been performed successfully:

1. starting a listener (lsnrctl start)
2. opening the database (sqlplus / as sysdba then startup)
3. starting the Enterprise Manager agent (emctl start dbconsole)

F. Automating Database Startup
———————————————–
edit file “/var/opt/oracle/oratab” script to find lines with ‘Y’ at their ends
Create file “/etc/init.d/dbora”
——-
#!/bin/sh
ORA_HOME=/u01/app/oracle/product/10.2.0/db_1
ORA_OWNER=oracle

if [ ! -f $ORA_HOME/bin/dbstart ]
then
echo “Oracle startup: cannot start”
exit
fi

case “$1″ in
’start’)
su – $ORA_OWNER -c “$ORA_HOME/bin/dbstart”
;;
’stop’)
su – $ORA_OWNER -c “$ORA_HOME/bin/dbshut”
;;
esac

———
#chmod 777 /etc/init.d/dbora
#/etc/init.d/dbora stop

To integrate dbora file to standart Solaris startup and shutdown process:
————————————————————————
#ln -s /etc/init.d/dbora /etc/rc0.d/K01dbora
#ln -s /etc/init.d/dbora /etc/rc2.d/S99dbora

IF u found error this:
———————–
ORACLE_HOME_LISTNER is not SET, unable to auto-stop Oracle Net Listener

edit file “dbstart” & “dbshut”, find line $ORACLE_HOME_LISTNER=$1

and change to = $ORACLE_HOME_LISTNER=/u01/app/oracle/product/10.2.0/db_1

RECOMMENDED DIRECTORY STRUCTURE:
———————————————-

[Oracle Base Directory:]
/u01/app/oracle
/u01/app/orauser
/opt/oracle/app/oracle

[Oracle Inventory Directory:]
ORACLE_BASE/oraInventory

[Oracle Home Directory:]

ORACLE_BASE/product/10.2.0/db_1

[Identify an existing oracle base directory:]
#more /var/opt/oracle/oraInst.loc
[the output should be:]

inventory_loc=/u01/app/oracle/oraInventory
inst_group=oinstall

# more /var/opt/oracle/oratab

*:/u03/app/oracle/product/10.2.0/db_1:N

*:/opt/orauser/infra_904:N

*:/oracle/9.2.0:N

COMMON INSTALLATION ERROR:
===========================
Unable to convert from “UTF-8″ to “646″ for NLS!
Solution: Install SUNWuiu8 package.

error adduser:
———————
UX: useradd: ERROR: Inconsistent password files. See pwconv(1M)

This is because the /etc/passwd and /etc/shadow files are out of synchronization on your machine. [CSCdi74894]
To fix this, run the pwconv command, and then rerun cwconfigure.

try to run:

wc -l /etc/passwd /etc/shadow

————–
ERROR Checking monitor: must be configured to display at least 256 colors >>> Could not execute auto check for
display colors using command /usr/openwin/bin/xdpyinfo. Check if the DISPLAY variable is set. Failed <<<<
Some requirement checks failed. You must fulfill these requirements before continuing with theinstallation, at which time they will be rechecked.

Solution(s):
1. Install SUNWxwplt package
2. Set DISPLAY variable
3. Execute xhost + on target (set in DISPLAY) computer

———————————————————-
Exception in thread “main” java.lang.UnsatisfiedLinkError:
… libmawt.so: ld.so.1: java: fatal: libXm.so.4: open failed: No such file or directory

Solution: Install the SUNWmfrun package.

—————————————————————————————————-
Can’t load ‘/usr/perl5/5.8.4/lib/i86pc-solaris-64int/auto/Sun/Solaris/Project/Project.so’ for module
Sun::Solaris::Project: ld.so.1: perl: fatal: libpool.so.1: open failed: No such file or directory at
/usr/perl5/5.8.4/lib/i86pc-solaris-64int/DynaLoader.pm line 230. at /usr/sbin/projadd line 19 Compilation
failed in require at /usr/sbin/projadd line 19. BEGIN failed–compilation aborted at /usr/sbin/projadd line 19.

Solution: Install the SUNWpool SUNWpoolr packages.

———————————————————————–
bash-3.00$ /u01/app/oracle/product/10.2.0/db_1/bin/./emctl start dbconsole
Exception in getting local host
java.net.UnknownHostException: -a: -a
at java.net.InetAddress.getLocalHost(InetAddress.java:1191)
at oracle.sysman.emSDK.conf.TargetInstaller.getLocalHost(TargetInstaller.java:4977)
at oracle.sysman.emSDK.conf.TargetInstaller.main(TargetInstaller.java:3758)
Exception in getting local host

Solution : check server hostname and /etc/hosts
————————————————————————-

UNINSTALL ORACLE 10G:
———————
1. remove all database, by running $dbca
2. stop any oracle process running:
Database Control : $ORACLE_HOME/bin/emctl stop dbconsole
Oracle Net listener : $ORACLE_HOME/bin/lsnrctl stop
iSQL*Plus : $ORACLE_HOME/bin/isqlplusctl stop
Ultra Search : $ORACLE_HOME/bin/searchctl stop

3. Start Oracle Universal installer:

$ORACLE_HOME/oui/bin/runInstaller

4. In the Welcome window, click Deinstall Products.
5. In the Inventory screen, select the Oracle home and the products that you want to remove,
then click Remove.

Saving Files to Oracle database

In SQL * Plus Oracle 11g, we can perform storage and retrieval operations from and to file an Oracle database, which previously could not do. In previous versions, if we try to query the type of blob field or bfile, SQL * Plus will display the message "SP2-0678: Column or attribute type can not be displayed by SQL * Plus". Here's my experiment in Oracle 11g to perform operations with the type of file storage BFILE in Oracle 11g using SQL * Plus:

SQL> create table album(id number(5) primary key, keterangan varchar(1000), foto bfile);

SQL> select * from album;

no rows selected

SQL> create or replace directory ALBUMDIR as ‘/home/oracle/Pictures’;

(jika ada pesan ORA-00990: missing or invalid privilege, berikan hak CREATE ANY DIRECTORY kepada userAnda).

SQL> create sequence albumseq;

SQL> insert into album values (albumseq.nextval, ‘komik koran spiderman’, bfilename(‘ALBUMDIR’, ‘2.png’));

SQL> col keterangan format a30;

SQL> select * from album;

ID KETERANGAN
———- ——————————
FOTO

1 komik koran spiderman
bfilename(‘ALBUMDIR’, ‘2.png’)

Thus for example the use BFILE. For BLOB data type, we can try to enter the EMPTY_BLOB function () to see that the SQL * Plus in Oracle 11g can also be displayed.

For example the Java programming of reading the contents of files stored in a BFILE column, please refer kehttp: / / www.oracle.com / technology / sample_code / tech / java / sqlj_jdbc / files / advanced / BFILESample / Readme.html. Thanks.

AutoNumber in Oracle

Basically, Oracle does not have facilities like Numer Auto AutoIncrement in SQLServer or mySQL. But could diakalin using a combination of sequence and trigger. And the following example:

1. CREATE SEQUENCE nama-sequence;
2. CREATE OR REPLACE TRIGGER nama-trigger
3. BEFORE INSERT ON nama-tabel
4. FOR EACH ROW
5. WHEN (NEW.nama-field IS NULL OR NEW.nama-field = ‘’)
6. BEGIN
7. SELECT ‘PR-’ || nama-sequence.NEXTVAL INTO :NEW.nama-field FROM DUAL;
8. END;
9. /

Or it could be in the following ways:

1. CREATE TABLE contoh (
2. latihan_id INTEGER PRIMARY KEY,
3. );
4.
5. CREATE SEQUENCE contoh_seq;
6. CREATE TRIGGER contoh_seq_trigger
7. BEFORE INSERT ON contoh FOR EACH ROW
8.
9. BEGIN
10. IF (:new.latihan_id IS NULL) THEN
11. SELECT contoh_seq.nextval INTO :new.latihan_id
12. FROM DUAL;
13. END IF;
14. END;
15. /

Variable manipulation PL / SQL in Oracle heterogeneous System

Oracle heterogeneous system. My Oracle HS agaar short easy to remember. What's that? Oracle HS is a system that allows for manipulation of other databases outside the system databse being contacted. Other systems can be an Oracle database, or a non-Oracle databases, such as SQL Server or MySQL.

With Oracle HS system settings, we can do SQL query on other databases on our Oracle session. For example we want to fetch the data in a table in another database, then query it will be like this:

SELECT * FROM rfq@hsmsql

There are additional @ hsmsql which shows HS Oracle database link that has been set-up before (HS Oracle setup is not discussed in this post).

Well, the problem occurs when the Oracle HS in the script used in PL / SQL. Oracle HS can not read or fill in the variables PL / SQL. Consider queries PL / SQL the following:

SELECT Count( * ) INTO v_count FROM rfq@hsmsql

SELECT * FROM rfq@hsmsql WHERE rfqnum = v_rfqnum

In the normal query with no Oracle HS, the query above can work well. v_count row will contain the number obtained from table RFQ, whereas the second query will be filtered for rows that have the same rfqnum with v_rfqnum. But the Oracle did not HS. Oracle HS can not enter the Count (*) into a variable v_count and can not filter the content rfqnum record variabel v_rfqnum.

The solution, we can use a mechanism called-SQL Passthrough. There are built-in package from Oracle named special DBMS_HS_PASSTHROUGH used to obtain data and / or vice versa from / to Oracle HS. Here is how to get results from Oracle HS and stored on variables PL / SQL

con := DBMS_HS_PASSTHROUGH.open_cursor@hsmsql.world;

DBMS_HS_PASSTHROUGH.parse@hsmsql.world (con,

‘SELECT COUNT( * ) FROM rfq_mxm
WHERE rfqnum = ”’
|| vrfq.rfqnum
|| ””
);

rs := DBMS_HS_PASSTHROUGH.fetch_row@hsmsql.world (con);

DBMS_HS_PASSTHROUGH.get_value@hsmsql.world (con, 1, vcount);

DBMS_OUTPUT.put_line (’count: ‘ || vcount);

If the code is described conceptually above, then the steps are as follows:

1. Open the cursor HS (meaning here is different cursor with the understanding PL / SQL cursor)
2. Parse the query with the function
3. Pull the results of each line and enter into a variable and PL / SQL function get_value

It is much more complicated, but this is the safest way to manipulate the variables PL / SQL with heterogeneous systems (Oracle HS).

SQL Tuning: EXISTS Clause vs. IN

Still on the issue on Oracle performance tuning SQL Query. In the case of correlated subquery, we used to use IN and NOT IN. Eg

SELECT * FROM tabel1 a
WHERE a.kolom1 NOT IN
( SELECT b.kolom1 FROM tabel2 b)

In the same case, we can also use the EXISTS clause and NOT EXISTS. Eg

SELECT * FROM tabel1 a
WHERE a.kolom1 NOT EXISTS
( SELECT b.kolom1 FROM tabel2 b)

What is the difference of two this SQL statement? IN clause and NOT IN check if a value contained in the list (can be array, can be correlated subquery in the example above), while clause EXISTS and NOT EXISTS check only whether or not the existence of a list row. In performance, certainly much faster than IN EXISTS correlated subquery in the case.

When do we use IN? Wherever possible, use EXISTS, IN used in the case such as this example below:

SELECT * FROM tabel1 a
WHERE a.kolom1 IN (’1′, ‘2′, ‘3′)

SQL Tuning: String Functions in the WHERE clause

This is the Oracle SQL Performance Tuning tips and trick from Mas FF. Say we have a SQL like this,

SELECT *
FROM tabel t
WHERE LOWER(t.kol)
LIKE ‘%hehe%’ AND SUBSTR(t.kol2,2,4) = ‘AB’

Look familiar? This is a standard query kok. But do you know the implications and substr LOWER function in velocity problem? Apparently the LOWER and substr is to lower-case an entire row in the column and t.kol substring to an entire row in the column before comparing it with t.kol2 hehe and AB. If the number of line too much, of course, speed degradation will occur very significant (read: insignificant).

Solution: Use the sort function and substr LOWER wisely. If you are sure of a column in lowercase, then the right input (in this case hehe) should be changed to lowercase as well. Similarly to substr function.

Tips and tricks so short SQL Tuning. : D

copy Database to the Same Machine

copy of the database on another machine, it was the same as conventional backup & recovery. Copying a database on the same machine, there is little difference because in one machine may not have 2 (or more) the same database; a step to change the name of the database.

I have 1 database development, database name is ts2. For test purposes, I need another database on the development machine. New database content is the same as the previous database. How do I make it, there are two ways:

1. Creating a new database, export from the old database, then import into new database.
2. Copying the old database to the new one, as if the backup and recovery

The first way, of course, takes a long time, especially if a large enough data. Then I choose the latter; my first database backup, then I raise (restore & recovery) with a different name (I named tsrep). Here are the steps:

1. Prepare (copy) init file. Examples here, I use UNIX. In Windows, the location of the file init in% ORACLE_HOME% \ database

cd $ORACLE_HOME/dbs
cp -rp initts2.ora inittsrep.ora

Suppose inittsrep.ora content is the following:

### Parameter ini perlu disesuaikan ###
audit_file_dest='/data1/oracle/admin/ts2/adump'
background_dump_dest='/data1/oracle/admin/ts2/bdump'
core_dump_dest='/data1/oracle/admin/ts2/cdump'
user_dump_dest='/data1/oracle/admin/ts2/udump'
control_files='/oradata/oracle/ts2/control01.ctl', '/oradata/oracle/ts2/control02.ctl', '/oradata/oracle/ts2/control03.ctl'
log_archive_dest_1='LOCATION=/oradata/oracle/ts2/arc'
db_name='ts2'
####################################
log_archive_dest_state_1=enable
log_archive_format=%s_%t_%r.arc
compatible='10.2.0.3.0'
db_block_size=8192
db_domain=''
pga_aggregate_target=209715200
sga_target=1610612736
undo_management='AUTO'
undo_tablespace='UNDOTBS1'
remote_login_passwordfile='EXCLUSIVE'

I adjust some parameters, especially db_name and related directories. Here are the parameters I have been customized:

audit_file_dest='/data1/oracle/admin/tsrep/adump'
background_dump_dest='/data1/oracle/admin/tsrep/bdump'
core_dump_dest='/data1/oracle/admin/tsrep/cdump'
user_dump_dest='/data1/oracle/admin/tsrep/udump'
control_files='/oradata/oracle/tsrep/control01.ctl', '/oradata/oracle/tsrep/control02.ctl', '/oradata/oracle/tsrep/control03.ctl'
log_archive_dest_1='LOCATION=/oradata/oracle/tsrep/arc'
db_name='tsrep'

Prepare a directory for files and other data

mkdir /data1/oracle/admin/tsrep
mkdir /data1/oracle/admin/tsrep/adump
mkdir /data1/oracle/admin/tsrep/bdump
mkdir /data1/oracle/admin/tsrep/cdump
mkdir /data1/oracle/admin/tsrep/udump
mkdir /oradata/oracle/tsrep
mkdir /oradata/oracle/tsrep/arc

Prepare script to create database
In the old database (source):

SQL> alter database backup controlfile to trace resetlogs;

See trace file in the directory user_dump_dest, / data1/oracle/admin/ts2/udump
SQL> sho parameter user_dump_dest

Copy the trace file

cd /data1/oracle/admin/ts2/udump
cp ts2_ora_18762.trc /oradata/oracle/tsrep/crdbtsrep.sql

Edit crdbtsrep.sql file, remove "trace file entry", to be like this

STARTUP NOMOUNT
CREATE CONTROLFILE REUSE DATABASE "TS2" RESETLOGS ARCHIVELOG
MAXLOGFILES 16
MAXLOGMEMBERS 3
MAXDATAFILES 100
MAXINSTANCES 8
MAXLOGHISTORY 292
LOGFILE
GROUP 4 '/oradata/oracle/ts2/redo04.log' SIZE 5M,
GROUP 5 '/oradata/oracle/ts2/redo05.log' SIZE 5M,
GROUP 6 '/oradata/oracle/ts2/redo06.log' SIZE 5M
-- STANDBY LOGFILE
DATAFILE
'/oradata/oracle/ts2/system01.dbf',
'/oradata/oracle/ts2/undotbs01.dbf',
'/oradata/oracle/ts2/sysaux01.dbf',
'/oradata/oracle/ts2/users01.dbf'
CHARACTER SET WE8ISO8859P1
;

Edit crdbtsrep.sql file again.
Replace this entry

CREATE CONTROLFILE REUSE DATABASE “TS2″ RESETLOGS ARCHIVELOG

Become

CREATE CONTROLFILE SET DATABASE “TS2REP” RESETLOGS ARCHIVELOG

Adjust the directory-related directory. In this example I changed

/oradata/oracle/ts2/

become

/oradata/oracle/tsrep/

After some editing, crdbtsrep.sql files will be

STARTUP NOMOUNT
CREATE CONTROLFILE SET DATABASE "TSREP" RESETLOGS ARCHIVELOG
MAXLOGFILES 16
MAXLOGMEMBERS 3
MAXDATAFILES 100
MAXINSTANCES 8
MAXLOGHISTORY 292
LOGFILE
GROUP 4 '/oradata/oracle/tsrep/redo04.log' SIZE 5M,
GROUP 5 '/oradata/oracle/tsrep/redo05.log' SIZE 5M,
GROUP 6 '/oradata/oracle/tsrep/redo06.log' SIZE 5M
-- STANDBY LOGFILE
DATAFILE
'/oradata/oracle/tsrep/system01.dbf',
'/oradata/oracle/tsrep/undotbs01.dbf',
'/oradata/oracle/tsrep/sysaux01.dbf',
'/oradata/oracle/tsrep/users01.dbf'
CHARACTER SET WE8ISO8859P1
;

Copy (backup and restore) a database source
If NOARCHIVELOG database, do a cold (off line) backups. Because ts2 ARCHIVELOG database, then I can do is hot (on line) backups. In this example I use hotbackup.Lihat list datafile and tempfile that needs to be copied

select name as file_name from
(select name from v$tempfile union
select name from v$datafile);
/oradata/oracle/ts2/sysaux01.dbf
/oradata/oracle/ts2/system01.dbf
/oradata/oracle/ts2/temp01.dbf
/oradata/oracle/ts2/undotbs01.dbf
/oradata/oracle/ts2/users01.dbf

See tablespace to the backup

SQL> select distinct tablespace_name from dba_data_files;
TABLESPACE_NAME
------------------------------
SYSTEM
USERS
SYSAUX
UNDOTBS1

Before running BEGIN backup, see "Current log sequence". This information we need to see any archived logs are later required to raise the database. In this instance, "Current log sequence" is 17.

SQL> archive log list

Run BEGIN BackUp-tablespaces in the tablespace (if cold backup, this step is replaced by a database shutdown):

SQL> alter tablespace SYSTEM begin backup;
SQL> alter tablespace USERS begin backup;
SQL> alter tablespace SYSAUX begin backup;
SQL> alter tablespace UNDOTBS1 begin backup;

Copy datafile and tempfile

cd /oradata/oracle/ts2/
cp -rp sysaux01.dbf /oradata/oracle/tsrep
cp -rp system01.dbf /oradata/oracle/tsrep
cp -rp temp01.dbf /oradata/oracle/tsrep
cp -rp undotbs01.dbf /oradata/oracle/tsrep
cp -rp users01.dbf /oradata/oracle/tsrep

After a datafile copy process is complete, run the BackUp END tablespace tablespace-related (if cold backup, this step is replaced with a startup database):

SQL> alter tablespace SYSTEM end backup;
SQL> alter tablespace USERS end backup;
SQL> alter tablespace SYSAUX end backup;
SQL> alter tablespace UNDOTBS1 end backup;

When finished END backups, see the value of "Current log sequence". In this example the value was 18.

SQL> archive log list

Run "archive log current" to create archived logs from sequence 18.

SQL> alter system archive log current

Archived logs required to raise the database is archived log sequence before BEGIN END seteleh backups and backups. Thus, sequences 17 and 18.

Further copies of the required archived log is

cd /oradata/oracle/ts2/arc/
cp -rp 17_1_658171224.arc /oradata/oracle/tsrep/arc
cp -rp 18_1_658171224.arc /oradata/oracle/tsrep/arc

Preparation before raising database
Setting ORACLE_SID, in csh shell

setenv ORACLE_SID tsrep

Ksh shell

export ORACLE_SID=tsrep

In Windows

set ORACLE_SID=tsrep

Especially in Windows, for instance (service) oradim use. Make sure that the file was created inittsrep.ora.

cd %ORACLE_HOME%\database
oradim -NEW -SID tsrep

Raise (create) the database

SQL> @/oradata/oracle/tsrep/crdbtsrep.sql

Perform recovery. With automatic specify, Oracle will search for archived log files alone.

SQL> RECOVER AUTOMATIC DATABASE USING BACKUP CONTROLFILE;

In this example, the required archived log is sequence 17 to 18. After a sequence of 18-apply, Oracle still asking squence 19. Because the sequence 19 does not exist, then the error recovery. Ignore these errors. Next:

SQL> RECOVER DATABASE until cancel;

If the database in sync, the above command should work. If Oracle is still asked archived logs for recovery, copy it again from its source databases. If the source database archived log has not been create, yes run "alter system archive log current", or if you want, just stop using the logfile recover the source database (not archived log). Suppose still required archived log sequence 19, while sequence is not dicreate archived logs. Use the following command to get logfilenya

SQL> -- di database source (ts2)
SQL> select member from v$logfile where GROUP# in
(select GROUP# from v$log where SEQUENCE#=19);

Next, use the logfile above for recovery in tsrepSetelah database recovery process is successful, open the database:

SQL> ALTER DATABASE OPEN RESETLOGS;

Next, add the temp files:

SQL> ALTER TABLESPACE TEMP ADD
TEMPFILE '/oradata/oracle/tsrep/temp01.dbf'
SIZE 20971520 REUSE AUTOEXTEND OFF;
Posted by audio at 2:21 PM 0 comments
Labels: copy Database to the Same Machine
PHP with Oracle Connection 2: Sample Program
In this tutorial, we will use the following oracle table as its data source. Table name is test.

nama
kota
Prothelord
New York
Strawberi
Bangkok

Our goal is to display the name and city data from the table. But before you start, you need to seek prior information about the Oracle login information is usually called the TNS name (you can compare with the user, password and IP dariMySQL server). TNS name consists of:

- IP Server Oracle
- Port is in use (if MySQL 3306, remember?)
- SID
- User
- Password
Try asking the same Oracle admin at your place on such information.

If it can, try the following programs to edit the configuration TNS Name which you have from your Oracle admin. In this example, we use the TNS name configuration as follows:

- IP: 10.2.2.2
- Port: 1523
- SID: TEST
- User: your name
- Password: pwd

Here's an example program to access the Oracle tables:

$ db = "(DESCRIPTION = (ADDRESS_LIST = (ADDRESS = (PROTOCOL = TCP) (HOST = 10.2.2.2) (PORT = 1523))) (CONNECT_DATA = (SID = TEST)))";
$ c1 = ocilogon ( "name", "pwd", $ db);
$ code = "select * from test";
$ stmt = ociparse ($ c1, $ code);
ociexecute ($ stmt, OCI_DEFAULT);

/ / Displaying data from test table

while (ocifetch ($ stmt)) (
ociresult echo ($ stmt, 0 ).",". ociresult ($ stmt, 1);
echo ( "
");
)
ocilogoff ($ c1);
?>
When finished, save the name and call coba_oracle.php from the browser. You should see the following results:


Prothelord, New York
Strawberry, Bangkok


Bye, cuman kok gitu doang. Easy yach?

Good luck, and hopefully useful.
Best regards.
Prothelord.