Subscribe

RSS Feed (xml)

Powered By

Skin Design:
Free Blogger Skins

Powered by Blogger

Monday, March 17, 2008

Questions and Answers Create Oracle Host

I'm new to Oracle, I downloaded Oracle 9i and want to use the SQL applications.

It asks me for user name and password and host string. It didn't ask me to create these when I installed the software.

So what is a host string and how do I create it and create a username and password for it.

Mohammad

simply type in host string as "scott" and pwd as "tiger".

Lokesh Bohra

There are default accounts created, following are their user name and passwords
user name: sys password:change_on_install
system p/w manager
scott p/w tiger
host string is used when you have more than one database or you want to connect to a database from remote location. There is no need of connect string at the moment.

Abdul Qadir

Thank you all.

But unfortunatlly it didn't work, I tried all of them

What do you think the problem is?

Mohammad

This means you have not configured your tnsnames. It is available in orahome/network/admin directory, insert the entry for your database and then try to connect. Alternately you can use net configuration assistant.

Sumit

If you are interested to create new user you must connect with dba right . So by default in oracle user system and user sys has dba right therefore initially you use user name as sys and by default sys password is change_on_install.

After connecting the above user name & password you write command on sqlplus is create user abc identified by xyz
after creating user you type a command
grant connect, dba to abc identified by xyz with admin option

Now you join with dba privileges

Khawaja

Follow the steps to access sql

1, create the service name using config. mgmt.(Net) while create the service name it will ask service name and hostname just enter your db name and your host ip address which is hosted oracle.

2, oracle provice some predefined un and pwd i.e scott and tiger. open the sqlplus environment and type the username, password and the service name.

3, after that it will connect, if not send me what error msg occur while connection.

Questions and Answers Change the Port number after the Installation

How to change the Port number after the installation of Oracle software?

Ports 1521/1526 are the default port numbers Oracle will listen on for SQL*Net (Oracle 7) or Net8 (Oracle 8) out of the box.

There is a file in directory:

%ORACLE_HOME%\network\admin (Oracle 7) or %ORACLE_HOME%\net8\admin(Oracle 8) called listener.ora that specifies the ports to listen on.

(if you change it you need to change the tnsnames.ora file on all clients that connect to it - including itself, that file usually resides in the same location- if you don't they will not know which port to try to connect to)

Questions and Answers Problems with Password File

I'm using Oracle 9i R2 installed on Windows XP Professional as a standard version.

I made a Password file like the below:

orapwd file="d:\oracle\amr\dbs\orapwd" password=admin entries=10

and then granted the SYSDBA permissions to user "HR". (GRANT SYSDBA TO HR;)

The value of "remote_login_passwordfile" in my PFile was "ESCLUSIVE" and also I was not connecting from a remote client.

So I could login to SQL *Plus like this:
connect HR/admin@TST as sysdba;

and everything was fine.

but, after that I removed the password file, revoke the sysdba permission from HR and changed the "remote_login_passwordfile" to SHARED, but still I could connect to the DB using HR as sysdba. (don't forget that I'm not connecting from a remote client)

I have even restarted the Instance.

----->
If the OS user you are logged in is member from the ORA_DBA group, then you will be allowed to connect from the local machine as SYSDBA. It's the way how the Oracle trusts the OS users.

If you comment out this line from sqlnet.ora file, you would get the desired effect:

SQLNET.AUTHENTICATION_SERVICES= (NTS)

----->
Also you may want to include the Oracle SID in the password file name for correct syntax:

orapwd file="d:\oracle\amr\dbs\orapwORCL" password=admin entries=10

Questions and Answers Fresh Install Done Login Problem

I did a Fresh install of 11i(11.5.9) on Win 2000 with Vision DB and all the test done by oracle in the post install is working fine. But whenever I go to http://hostname:8000 and type sysadmin/sysadmin in the user id password col, I get the log on screen again with the user id and pwd cols blank. If I retype the same sysadmin/sysadmin then I get the following :

Internal Server Error
The server encountered an internal error or misconfiguration and was unable to complete your request.
Please contact the server administrator, Administrator@lakshmiraj and inform them of the time the error occurred, and anything you might have done that may have caused the error.

More information about this error may be available in the server error log.

I checked the Apache error log and found this line :

Filename is not valid: d:/oracle/visncomn/portal/visn_hemasundar2/redirecturl$url=$|servlets$|weboam$|oam$|oamapps$$target$=visn

Can anyone of you help me out here to at least login to the oracle application managers screen


Try logging in directly to the applications via:

http://hostname:port/dev60cgi/f60cgi

Check out the values for profiles set at the system level. Some of them may reference the settings of the vision demonstration database that was installed at oracle corporation - which obviously may not apply to your environment. Also, Perhaps an incorrectly specified dbc file has been mentioned. This file is typically found in :

%FND_TOP%/secure

Check if some of your profile values are using values that are incorrect. I found the likes of this happened to me, when i installed the vision database. You may not experience this if you install a PROD or TEST instance.


I tried http://hostname:8000/dev60cgi/f60cgi and got "The page cannot be found" error.
I tried reformatting the Harddisk and reinstalling 2000 svr and Ora Appl but still no effect.

Am I missing some environment variables? What environment variables should I copy into the registry and make sure they are available to the system?


Oh I forgot What file name should I use for starting the applications in the http://hostname:port/dev60cgi/f60cgi link


1. Start oracle 9i database and net listener - like you would otherwise

2. %APPLCSF%/scripts/

contains scripts to start all app services , there is probably one called adstral.cmd that starts em all. you may want to use that instead.

Questions and Answers How to create a DBMS Job?

How do I create a dbms job, actually I want a job that should run at a specified time and do a specific job for me such as picking up data from a remote database and then dumping it into my database.
We are using windows as operating system and oracle 8i.
Can you give me an specific example as in I'm new to this...that would be of great help to me.

Thanks in anticipation.

Per your request. Example:

Quote:
This submits a new job to the job queue. The job calls the procedure DBMS_DDL.ANALYZE_OBJECT to generate optimizer statistics for the table DQUON.ACCOUNTS. The statistics are based on a sample of half the rows of the ACCOUNTS table. The job is run every 24 hours:

VARIABLE jobno number;
BEGIN
DBMS_JOB.SUBMIT(:jobno,
'dbms_ddl.analyze_object(''TABLE'',
''DQUON'', ''ACCOUNTS'',
''ESTIMATE'', NULL, 50);'
SYSDATE, 'SYSDATE + 1');
commit;
END;
/

Questions and Answers HP UX 11.0 - Oracle 7.3.4 linking libraries

I have a Corba Service that I have compiled and tested successfully on HP UX 11.0 and with Oracle 8.0.6 in my development environment. But our production boxes have Oracle 7.3.4 (also HP UX 11.0) installed on them. So I complied my server/client using Oracle 7.3.4 -specific libraries
(-L$(ORACLE_HOME)/lib
-lsql -lsqlnet -lncr -lsqlnet -lclient -lcommon -lgeneric -lsqlnet -lncr
-lsqlnet -lclient -lcommon -lgeneric -lepc -lnlsrtl3 -lc3v6
-lcore3 -lnlsrtl3 -lcore3 -lnlsrtl3 -lcma -lcl -lm -lcl -lm -lcma)

But now my program dies at the main line and core dumps with a Bus Error.
The backtrace in gdb shows
#0 0xc01339d0 in () from /usr/lib/libc.2
#1 0xc0206cb8 in __thread_atfork () from /usr/lib/libc.2
#2 0xc0204854 in __libc_init () from /usr/lib/libc.2
#3 0xc039fbbc in hp__pre_init_libc () from /usr/lib/libcma.2

DBD

The problem "Libraries need to be re-linked". As the application was developed using higher version of Oracle ..then the lower versions will have these kind of issues.

Also check whether Oracle8 you are using is a 64bit or 32bit...If you have used a 64bit version to develop the apps then I am sure you can't run this in a V7-32bit as the libraries don't match and you need to re-link them....and it's a messy process....but not impossible....be very careful if you wish to re-link the libs....I think the problem lies here.

Questions and Answers Explain plan and Autotrace on 8i

Can somebody please tell me how to get autotrace working on 8i? I tried to run the sql script found in %ORACLE_HOME%/sqlplus/admin/plustrce.sql but alot of the tables do not exist.

I'm also having a hard time with the explain plan.

Bryan

First check the following:
*PLAN_TABLE table in the user schema ur logging in.
sql > desc PLAN_TABLE - If it exists then u can run the explain plan for the query.
sql > desc PLAN_TABLE - If it doesn't exists then u need to create one.
In order to obtain the script for creating the table u can look in $ORACLE_HOME/rdbms/admin/utlxplan.sql file
or here is the script .....
*************
create table PLAN_TABLE (
statement_id varchar2(30),
timestamp date,
remarks varchar2(80),
operation varchar2(30),
options varchar2(30),
object_node varchar2(128),
object_owner varchar2(30),
object_name varchar2(30),
object_instance numeric,
object_type varchar2(30),
optimizer varchar2(255),
search_columns number,
id numeric,
parent_id numeric,
position numeric,
cost numeric,
cardinality numeric,
bytes numeric,
other_tag varchar2(255),
partition_start varchar2(255),
partition_stop varchar2(255),
partition_id numeric,
other long,
distribution varchar2(30));
*************
* If ur logging in as 'SYSTEM' or 'SYS' user the table will be already available as most of the DBA's activate it as soon the db is created.
* In order to use the Explain Plan u first need to have the PLAN_TABLE then once its there then u need to set the autotrace ON ..in order to activate this feature do this.....
sql > set AUTOTRACE ON;
Now ur all set to run the explain on any query.
In order to de-activate the AUTOTRACE do this...
sql > set AUTOTRACE OFF.
U can also use....additional to that ...
sql > set TIME ON
sql > set TIMINING ON
But remember PLAN_TABLE must EXISTS in the user ur loggin in as or else u get table not found error.
Also u can use OPTIMIZER features like RULE and COST based modes for better performance.

HTH

Questions and Answers Creating Dimensions in Oracle 8i

I have a normalized data base.
Now I have created a dimension using certain tables and defining levels in the dimension using certain columns in those tables. say for eg I created a dimension using courses table with course_id as a level.

Now if I want to create another dimension curriculum with course_id being a level of the dimension then oracle is posting an error saying that more than dimension can not be created on a single column.

Rajeev

I think this is your design issue because oracle will not allow you to define a level (the column of a particular table i.e. in your case course_id) in more than one dimension. What you can do is merge these levels in single dimension or you have to use that
column from some other table. You have to decide and make those changes accordingly in design.

Gairik Chakraborty

Thanks for the answers that you have provided me with and Gairik thats exactly what I did to solve the problem. I tried to merge the dimension levels and created one dimension that has multiple levels and that has solved my problem.

Questions and Answers Oracle Performance On Different Platforms

I have several Oracle databases running on older Sun servers which I will have to upgrade to new hardware in the near future. I haven't decided yet whether to stay with the Sun/Solaris platform or to make the move to Linux. The decisive factor in this case will have to be price and performance.

Does anyone have information about performance of Oracle servers on Sun-Sparc/Solaris 64-bit as compared to Intel-Xeon/Linux 32 bit? How do they both perform in multi-user environment?

I would very much appreciate a wise word of advice.

-------------------------

I prefer Solaris, mostly because I have found it to be remarkably stable. Linux is fairly stable, but I pretty quickly found ways to make it crash. On the other hand, you can expect the Linux community to be more responsive than a big, monolithic behemoth of a HW/SW/OS vendor who tends to hew more to their OWN agenda than their USERS' needs.
While Sun might not release driver updates to support the latest widget available for the x86 platform, someone might be developing it for Linux at the same time that you are looking for it.

-------------------------

Anytime you run an OS on a stable Hardware platform such as the Sun Computers, the system will be stable. PCs are inherently non-stable platforms. Linux seems to be changing rapidly to keep up with PC changes. Linux is similar enough to Solaris in lay out and stucture to be easy to work with. I support Solaris systems at work and I just recently built a Linux box at home. I love the configurability of UNIX. Linux is cheap and Solaris is expensive.

Make you own decision based on your needs. Good Luck.

-------------------------

How I do enjoy the unix techie sense of humor. I use both Solaris 7 x86 and Linux kernel 2.2.13. They both work reasonably well. Of course I also use BeOS 4.5.2, Windows NT (not very often though), and am thinking about FreeBSD. I have an affinity for operating systems that I can't quite explain. I am always interested in seeing how the features are implemented among the different systems.

For a stable platform without any thrills that won't be changing much Solaris is the way to go especially if you expect to be running any mission critical stuff on it. For example we would not even consider running our database servers that track the history of all our legal cases on a Linux box. It would be much to risky and the equivalent of playing with a cigarette lighter while waist deep in napalm. However, the personal workstation in my office runs primarily linux which I find to be stable enough and provides much better hardware support than Solaris x86. Relative to Solaris x86 Linux supports an etraordinary number of hardware periphereals.

Questions and Answers Small Select Statement

If I execute a query which returns 100 records but I want the record from 20 to 30. How is it possible to filter the specific results as the row number can only return top records but what will I have to do if I want results from 30 to 40 or etc and want to ignore some of the top records.

You first select 30 rows in a query using rownum<30 after that make another query for rownum<20
and now subtract second query from first query.

Example:
select * from emp where rownum<30
minus
select * from emp where rownum<20;>

Muzammil Husain

How to select the alternative rows in the table?

Jaii

select * from emp where rownum <10;>

*so the result will appear less then 10 record

Hazlina Kamilan

You cannot rely on rownum and what do you mean by alternate rows, as oracle doesn't store the records in any predifined sequence.

Sumit

This is not right. You can use the following

select rownum,sku from win_store where mod(rownum,2) = 0

Seetha

In Oracle, you can use the query as:
Select rownum, * From where mod (rownum,2) <> 0

In SQL Server, you can use the query as:
Select id, * from where (id % 2 <> 0 ).
Here id is the identity Column.

Ratikanta

This will always return 0 rows.

Sunil Bhardwaj

rownum won't work with any operator, other than <(less than).

So the query can be :

select b.* from (select rownum cnt, a.* from emp a) b where mod(cnt,2)<>0;

Questions and Answers java.sql.SQLException: ORA-12154

We are getting java.sql.SQLException: ORA-12154: TNS:could not resolve
service exception. It comes allof a sudden. It was working fine. But the issue got resolved once we recycle our Sunone Application server.

Any idea ..Is it something to do with momentary network issue, after which SunApplication server not able to connect to
database. At the time when we got this exception, we tried connnectig to database using sqlplus, it worked fine.

Oracle Troubleshooting
--------------------------------------------------------------------------------
ORA-12154: TNS:could not resolve service name
--------------------------------------------------------------------------------
Symptom:
When trying to connect to Oracle the following error is generated:

ORA-12154: TNS:could not resolve service name

Cause:
This error indicates that the service (or TNS alias) specified when trying to connect does not exist.

TNS aliases or service names are defined locally to each workstation. Thus different workstations could have a completely different alias to refer to the same database.

Remedy:
Check what aliases are defined on the workstation, either use one that is defined or add an appropriate one.

The following methods can be used to view the TNS names:

Look in the file ORANT\ Network\ Admin\ Tnsnames.ora (for versions of Oracle prior to 8.1) or Oracle\
Ora81\ Network\ Admin\ Tnsnames.ora (for versions of Oracle from 8.1 onwards). In this file each defined
name will normally have.world appended to it.

For Oracle 8, run Oracle Net8 Easy Config. This will list the available service names.

For Oracle 7, run SQL Net Easy Configuration. This provides the option to list the available service names.

For Oracle 8.1 onwards: Try specifying the full service name, i.e. as it appears in the tnsnames file.

If a connection alias is not being explicitly provided then try to identify what alias Oracle thinks you are
using. This will typically be contained in the sqlnet.log file that the Oracle client will produce.
Possible places where Oracle could be getting this (default) alias from:
The environment variableLOCAL

Chaz S

1.what version of oracle?
-------------------------------------------------------
You stated:
java.sql.SQLException: ORA-12154: TNS:could not resolve service name
------------------------------------------------------------------
Most probable case:
This may happen when a Java client requests a database connection but the database server has not started or
not listening.

Solution1. Make sure the service name in the host string is correct. e.g.

jdbc:oracle:oci8:@kesdee.world

Solution2. Start the Oracle Server

Solution3. Start the Listener. Under MS-DOS:
lsnrctl.exe
start

Soution4. The tnsname specified in jdbc url is incorrect, check if the names match in ORACLE_HOME/network/admin/tnsnames.ora

Your problem must be solved by now:if not go down
further!!!!
--------------------------------------------------------------------
If not solved yet:RUN THE FOLLOWING CHECKS:

1>You mustve missed some vital info in SQLNET.ORA:
for egs:
NAMES.DEFAULT_DOMAIN entry missed Due to which you cannot start the application and the The JRE runs into Exception Errors!

2>Verify that a TNSNAMES.ORA file exists and is in the proper directory and is accessible.
- Check that the net service name used as the connect identifier exists in the TNSNAMES.ORA file.
- Make sure there are no syntax errors anywhere in the TNSNAMES.ORA file. Look for unmatched parentheses or
stray characters. Errors in a TNSNAMES.ORA file may make it unusable.

3>Verify that the host or database name is correct and that it is listed in the TNSNAMES.ORA file.This file
keeps a list of available databases and related information required to connect to them.

4>If you are using directory naming:
- Verify that &quo;LDAP&quo; is listed as one of the values of the NAMES.DIRETORY_PATH parameter in the
Oracle Net profile (SQLNET.ORA)
-Verify that the LDAP directory server is up and that it is accessible.
-Verify that the net service name or database name used as the connect identifier is configured in the directory.
- Verify that the default context being used is correct by specifying a fully qualified net service
name or a full LDAP DN as the connect identifier - If you are using easy connect naming:
- Verify that &quo;EZCONNECT&quo; is listed as one of the values of the NAMES.DIRETORY_PATH parameter in the
Oracle Net profile (SQLNET.ORA).
- Make sure the host, port and service name specified are correct.
- Try enclosing the connect identifier in quote marks.
---------------------------------------------------------------------

Questions and Answers Find How Much Time Left For Query Completion

Need to find out how long will a query take to run or when I am running the query where can I check to see that X% of my query is complete.

I know there is some place in Oracle Enterprise manager or something like that which shows a progress bar once the query is started, but I dont exactly recollect it can somebody help me with this..

Also when do we run analyze plan estimate statistics and how does this help if I have to run a complex query. does estimating statistics on a table increase the query performance if so how ?

You can use this query to find out the information you want to know:

CODE

REM Displays the long running operations

SET LINESIZE 200

COLUMN operation FORMAT a15
COLUMN username FORMAT a15
COLUMN object FORMAT a25

SELECT a.sid,
a.serial#,
b.username ,
opname OPERATION,
target OBJECT,
TRUNC(elapsed_seconds, 5) "ET (s)",
TO_CHAR(start_time, 'HH24:MI:SS') start_time,
ROUND((sofar/totalwork)*100, 2) "COMPLETE (%)"
FROM v$session_longops a,
v$session b
WHERE a.sid = b.sid AND
b.username not IN ('SYS', 'SYSTEM') AND
totalwork > 0
ORDER BY elapsed_seconds;

Needed some clrafication regrding this

"when do we run analyze plan estimate statistics and how does this help if I have to run a complex query. Does estimating statistics on a table increase the query performance if so how ?"

Your last post contains three questions:
1>when I am running the query where can I check to see that X% of my query is complete
2>predict the time to answer of a query
3>estimating statistics on a table increase the query performance if so how ?

My point of view is
1>Answers to the first question have given above..

2>The second and the third questions implie to understand what is a CBO (cost based optimizer) and a RBO (rule based optimizer). Are you familiar with that? The ROB might not be used any more by oracle (it is an another story). You cannot predict the time of answer of a sql request. There are too many factors.

3>Regarding the third question, the Analyze is useful if the sql request is analyzed by the COB engine. And it should be.
Yes, Analyzing the table allows oracle to know the volume and the repartition of the tables. Therefore it performs the appropriate tasks to compute the data together. But sometimes some complex sql requests are not really well written. In that case you need to analyze the plan table.

Questions and Answers Finding How Much Data Has Been Filled

I would like to know how can one identify the current location that oracle is writing for transaction ie. extent location has reached the maximum allocated for it within the tablespace.

In plain words finding if the extents have reached the maxextent?

----->
You can use the view dba_extents and dba_tables for that

CODE

select b.table_name,a.used,b.max_extents-a.used remaining from
(select segment_name,count(extent_id) used from dba_extents group by segment_name) a,
(select table_name,max_extents from dba_tables) b
where a.segment_name=b.table_name

----->
Are you sure extent_id identifies the used extents?

I thought its just an identification

----->
extent_id identifies extents that are allocated to the table. so max_extents-count(extend_id) would give the number of extents yet to be allocated.

That is what you wanted to know? isn't it?

Questions and Answers Query about Data Storage and Retrieval

Is there any database parameter that we can set, which controls the way data is stored and retrieved for display purpose.

Or to put it other way round,

When we retrieve the data using select * statement, is the data displayed always in the chronological order ?

Context here is:

We have a table that contains past 2 months data (say 200 rows - 100 rows loaded on 1st June as May data, 100 for June data loaded on 1st July). Using some DB feature/parameter can we seprate out the recently inserted rows i.e. June data ?

PS: there is no date-time stamp related column in the row.

Just a blind shot:
If I do select * from table, and copy the last 100 of the displayed records, will it always serve my objective?

When you want to querry data from a table you have to know the structure of the table(i.e the columns in the table) these are what you need to restrict your select.

For example if you have a table called urtable has column like

name
address
salary
date_loaded

You can query for data loaded in june this way:

select name,address,salary,date_loaded from urtable
where date_loaded like '%06-01-2005%'

You can play around with several this query to achieve your desired result.

Questions and Answers Why this Query Returns null

Why this query returns null? Why rownum does not work with equality?

select * from emp where rownum = 10;

SQL> select rowid,rownum from emp ;
ROWID ROWNUM
------------------ ----------
AAAHcIAABAAAMuiAAA 1
AAAHcIAABAAAMuiAAB 2
AAAHcIAABAAAMuiAAC 3
AAAHcIAABAAAMuiAAD 4
AAAHcIAABAAAMuiAAE 5
AAAHcIAABAAAMuiAAF 6
AAAHcIAABAAAMuiAAG 7
AAAHcIAABAAAMuiAAH 8
AAAHcIAABAAAMuiAAI 9
AAAHcIAABAAAMuiAAJ 10
AAAHcIAABAAAMuiAAK ! 11

ROWID ROWNUM
------------------ ----------
AAAHcIAABAAAMuiAAL 12
AAAHcIAABAAAMuiAAM 13
AAAHcIAABAAAMuiAAN 14
AAAHcIAABAAAMuiAAO 15
AAAHcIAABAAAMuiAAP 16
16 rows selected.

SQL> select * from emp where rowid='AAAHcIAABAAAMuiAAJ' ;
EMPNO ENAME JOB MGR HIREDATE SAL COMM
---------- --------------- --------- ---------- --------- ---------- ----------
DEPTNO
----------
7844 TURNER SALESMAN 7698 08-SEP-81 1500 0
30

What I inquire is only this rowid is changed to rownumber for the userfriendly environment..and in order to retrieve it we should use only this rowid..This is what i feel and i may be right or wrong.just want to share what i feel.

Padma Raj

rownum is not stored in database, it is a pseudocolumn, and generated only when we try to retrieve data from the tables. oracle assigns the sequential number in the same order it retrieves the records from the table.

Now if you use "<" then oracle can find out the records rownum and returns the records. while in case of equality, its not possible to identify a record order in which it is going to be returned.

Sumit

Its wrong query

select * from emp where rownum = 10;

Right query is : select * from emp where (cloumn name) = 10;

Upendra Trivedi

To remove duplicate rows using rownum, do the following:

select rownum, from ;

you will get the list of records with unique rownum. Even the duplicate records will have different rownum.

Now, you can use the DELETE statement to remove one of the duplicate record.

delete
where rownum= X; ( where X is the rownum of the duplicate record)

Hope you have understood!!!

Questions and Answers Update statements in Query

I have one query,
Update the salary of the employees who has finished one year service with the company by 10% and who has service less than 1 yr with the company by only 5%.

Thesre are basically two Update statements in your Query:

1. Update the salary of the employees who has finished one year service with the company by 10%

Ans:
update table employee set salary = (salary + 0.10*salary) where (to_number(to_char(sysdate,'YYYY'))
- to_number(to_char(hiredate,'YYYY'))) > 1
/

2. and who has service less than 1 yr with the company by only 5%

Ans:
Update table employee set salary = (salary + 0.05*salary) where (to_number(to_char(sysdate,'YYYY'))
- to_number(to_char(hiredate,'YYYY'))) <>
/

I think this is what you needed else revert me back.

Petro.

Use Decode or Case to solve this problem

Naren

Give this inside a loop
{
UPDATE empincrement
SET salincrement =
(
SELECT decode(doj - sysdate >=1 ,sal*.10, sal*.05)
FROM emp
);
}
end loop

This is the way I have tried to solve this, but in the below part
doj - sysdate >=1 , its giving an error like right paranthesis missing.


Use this query in your loop.

update emp
set sal=
(SELECT case when (hiredate - sysdate) >=1 then
sal*.10 else sal*.05 end
FROM emp)

Questions and Answers Questions and Answers

Use user defined functions in SQL statements

Can we use user definbed functions in SQL statements, as we can use in built oracle function like date etc..?

Yeah.Of course provided there is no dml in your function

Thanks for reply, pls tell you can't we use functions with DML in it. What will hapen if it conatins dml in it.

We can use function which has only select statments in it, but it should not contain other DML statements like INSERT,UPDATE and DELETE oracle doesnot allow because it might get conflicts

Add A Function To User Defined Object

DATABASE: Oralce 9i
TOOL : OEM 9.2.0.1.0
Can I add a Function to a User Defined Object Type.
The User Defined Object Has Dependencies.
I tried adding the function using OEM but an error was reported,says, cannot alter the definition.
I tried Oracle Change Manager,but that does not display User defined Types.

This is well explained in the Oracle manuals. You cannot simple modify the already existing object type. In order to modify object attributes or methods, an object type must be dropped and re-created. An attempt to drop or replace a type with type or table dependents will result in an ORA-02303. Here is the manual part:

QUOTE:
The object types can be instantiated as types (nested tables or VARRAYs) or object tables. If data preservation is required, data depending on the type must be manually moved into temporary tables.
Per the SQL Reference guide, the DROP TYPE FORCE option is not recommended since this operation is not recoverable and could cause the data in the dependent tables to become inaccessible.

The following 3 queries can be run to determine dependencies:

-- Find nested tables
select owner, parent_table_name, parent_table_column
from dba_nested_tables
where (table_type_owner, table_type_name) in
(select owner, type_name
from dba_coll_types
where elem_type_owner = ''
and elem_type_name = '');

-- Find VARRAYs
select owner, parent_table_name, parent_table_column
from dba_varrays
where (type_owner, type_name) in
(select owner, type_name
from dba_coll_types
where elem_type_owner = ''
and elem_type_name = '

-- Find object tables
select owner, table_name
from dba_object_tables
where table_type_owner = ''
and table_type = ''
and nested = 'NO';

So first find the object dependencies on object types, make sure you have a means to backup the dependent object (nested tables, varrays, tables), drop the dependent object (nested tables, varrays, tables), modify the object type, re-create (restore) the object (nested tables, varrays, tables).

Hope that works for you - no OEM involved, so it would be a good practice.

Questions and Answers Need to write one PL/SQL procedure to housekeep a table

I'm running Oracle 8.1.7 on Windows 2000 Server.

I need to write one PLSQL procedure to housekeep a table, on daily basis.

There are 2 methods i can think of:
1. Use DBMS_SQL
...............
stmt_char := 'DELETE FROM TABLE_A WHERE TRUNC(DT) <= TRUNC(SYSDATE) - 3'; -- always keep 3 days
................
................

2. Use cursor
.............
CURSOR lv_delete_cur IS
SELECT column_A FROM TABLE_A -- where column_A is primary key
WHERE TRUNC(dt) <= TRUNC(SYSDATE) - 3;
.............
.............

..............

My questions are:
(a) Between approach 1 and 2, which is faster/better performance?
(b) In terms of performance, is there any difference if i modify to commit every 500 or 5000 records?
(c) Actually, currently i m using approach 1, which is considerably very slow!!!
[needs 5 - 7 hours to delete approx. 250000 records from table consisting approx. 800000 records.]

You can go for Dynamic SQL also and probably it helps you to improve the performance.

The performance of native dynamic SQL in PL/SQL is comparable to the performance of static SQL because the PL/SQL interpreter has built-in support for native dynamic SQL. Therefore, the performance of programs that use native dynamic SQL is much better than that of programs that use the DBMS_SQL package. Typically, native dynamic SQL statements perform 1.5 to 3 times better than equivalent statements that use the DBMS_SQL package. Of course, your performance gains may vary depending on your application.

The DBMS_SQL package is based on a procedural API and, as a result, incurs high procedure call and data copy overhead. For example, every time you bind a variable, the DBMS_SQL package copies the PL/SQL bind variable into its space for later use during execution. Similarly, every time you execute a fetch, first the data is copied into the space managed by the DBMS_SQL package and then the fetched data is copied, one column at a time, into the appropriate PL/SQL variables, resulting in substantial overhead resulting from data copying. In contrast, native dynamic SQL bundles the statement preparation, binding, and execution steps into a single operation, which minimizes the data copying and procedure call overhead and improves performance.

for e.g
BEGIN
EXECUTE IMMEDIATE 'TRUNCATE TABLE my_table;';
END;
/

Please let me know if any issues

I want to share a few ideas..
first of all you have said:

I need to write one PLSQL procedure to housekeep a table, on daily basis

here ,the question is why PLSQL procedure...as Tom Kyte would say often,we should use sql instead of pl/sql whereever possible...now here i think you can definately use simple sql statement like this.

DELETE FROM TABLE_A WHERE TRUNC(DT) <= TRUNC(SYSDATE) - 3

the thing to watch here is whether any indexes are being used or not....is there an index on the column DT?
pl post the execution plan of the query.
they might not get used i guess and you may need function based index as you are using the function trunc on the column DT.
alternately ,just for experiment try the following sql statement (pl. rollback the results ,as this is just experiment)
(pl. index the DT column if not already indexed)
DELETE FROM TABLE_A WHERE DT <= SYSDATE - 4

see if there is some performance gain.

--------------------------------------------------------------------------------------------------------------------------------
Basically I do agree with your saying, but if i use dynamic sql, how do i perform commit for every 1000 records (deleted), like wat i have explained in my first post?
--------------------------------------------------------------------------------------------------------------------------------
Perhaps i have tried most with and without TRUNC function, but the performance seems almost the same. Fyi, the DT column is indexed. But i guess u should not use:

DELETE FROM TABLE_A WHERE DT <= SYSDATE - 4

bcoz it is not accurate. If you really want to get rid off the TRUNC, i supposed you should use:

lv_sysdate_date := TRUNC(SYSDATE);

DELETE FROM TABLE_A WHERE DT >= lv_sysdate_date - 3 AND DT <>

Please correct me, if i am wrong.

And to your question why am i using PL/SQL instead of SQL statement. This is bcoz:
(a) Actually the "3" as in "TRUNC(dt) <= TRUNC(SYSDATE) - 3", i need to query from another table. It is not hardcoded.
(b) I need to commit after 1000 records have been deleted, due to rollback segment issue.

--------------------------------------------------------------------------------------------------------------------------------

Can u pl. post the execution plan of the query? what i would like to see is ,whether the index is being used or not..in fact i think that the index may not be used if this is not a function based index..so could u pl. post the execution plan of the query.for commiting,if i understand correctly,it really does not matter whether you commit after 1000 records or 10000 records..so don't expect any big gain in performance from that area...

Thats what i feel...key factor is ensuring & verifying that index is being used.also try NOT to use the index and see performance..and explain plan and post it and try TO USE the index and see performace and post the explain plan..i would like to compare the two plans..(PL. ROLLBACK if u are just experimenting)

Questions and Answers Questions and Answers

Problem Running 'ckrorole.sql' in Sqlplus

I've recently installed my Oracle 9i database and developers suite and I've created the repository owner and I've created my tablespaces to use in oracle 9i designer but I'm having problems granting roles to the repository owner.

I can login to sqlplus.exe but I can't seem to run the 'ckrorole.sql' file which as far as I know is used to grant roles to the repository owner. I keep getting the following message whenever I try to run it.

By the way, I'm using Windows XP.

SQL*Plus: Release 9.2.0.1.0 - Production on Fri Oct 22 19:05:07 2004

Copyright © 1982, 2002, Oracle Corporation. All rights reserved.

Enter user-name: sys@orcl as sysdba
Enter password:

Connected to:
Personal Oracle9i Release 9.2.0.1.0 - Production
With the Partitioning, OLAP and Oracle Data Mining options
JServer Release 9.2.0.1.0 - Production

SQL> @orahome1\repadm61\utl\ckrorole.sql
SP2-0310: unable to open file "orahome1\repadm61\utl\ckrorole.sql"
SQL>

The following happens whenever I try to run it the traditional way.

SQL> run d:\orahome1\repadm61\ckrorole.sql
SP2-0103: Nothing in SQL buffer to run.
SQL>

What do I need to do to get the 'ckrorole.sql' script to run?

Make sure this: orahome1\repadm61\utl\ is a valid directory -- try specifying the FULL path.

I did check. It is a valid directory. I found the file by searching for it in the windows XP search companion. The full path for that file is 'D:\OraHome1\REPADM61\UTL\CKROROLE.SQL'. This is exactly how windows recognises this file. ('D:\' being the 2nd partition of my 40 Gb Hard drive, 'C:\' being the 1st partition.)

What do you mean by 'full path' exactly? Add the 'd:\' onto the statement?

I found the problem. The code wasn't typed in properly. This is the correct code:

@ "D:\OraHome1\REPADM61\UTL\CKROROLE.SQL"

(Where 'D:' is the letter of the drive or hard disk partition that the database is installed on)

Questions and Answers List prerequisites to connect to oracle with a administrator previleges

1.User's O.S account has O.S previleges.

2.The user is granted the SYSDBA or SYSOPER previleges and database user the password files to authenticate database administration.

3.The database has a passsword for the internal login.

oracle server
/ \
Oracle database oracle instance
/ \
Physical database structure Logical database structure

(An oracle database's physical structure is datermined by the O.S files that constitute database)

Each oracle database is made of 3 types of files:

- one or more datafile
- 2 or more redo log files
- 1 or more control files

Oracle Instance
System global area(SGA) is an area of memory used for database admin. shared by the database servers.

The combinamtion of the background process and memory buffers is called an instance.

Oracle Instance
/ \
User process Oracle process
/ \
server process background process

A user process executes the code of an application program or an oracle tool.
Oracle process are server process and background process.
If the user and server process are on differrent computers of a network, if the user process connect to hares server process thro' dispatcher process, the user process and server process communicate thro' on using SQL* NET.

* Normally tablespace is online than offline.

b)Schemas and Schema objects
* Schema is collection objects
* Schema objects are the logical structures that directly refer to the database's data. Schema objects include structures as tables,views,sequence.
(There is no relationship between a tablespace and schema).
1. table
2.view - A view can also be thought of as a stored query.
3.sequences
4.program unit
5.synonyms
6.Index,cluster and hash clusters
7.database link

Datablocks, Extents and segments
*one datablock corresponds to a specific number of bytes of physical database space on disk.
*An extent is a specific number of continumous datablock obtained in a single allocation used to store a specific

Questions and Answers About Referential Integrity

First let me brief about the RF concept.

If you are thorough on this you will not have this doubt.So letz get going:

Referential integrity is about ensuring that relationships between rows in related tables are valid and that you do not accidentally delete or change related data.

When referential integrity is enforced in an Oracle database, you must observe the following rules:
<1>.You cannot enter a value in the foreign key column of the related table if that value does not exist in the primary key of the related table. However, you can enter a null in the foreign key column. For example, you cannot indicate that a job is assigned to an employee who is not included in the EMPLOYEE table, but you can indicate that an employee has no assigned job by entering a null in the JOB_ID column of the EMPLOYEE table.

<2>. You cannot delete a row from a primary key table if rows matching it exist in a related table. For example, you cannot delete a row from the JOBS table if there are employees assigned to the job represented by that row in the EMPLOYEE table. However, if cascading deletes are enabled, you can delete a primary key row; all matching rows in related tables are also deleted.

<3>. You cannot change a primary key value in the primary key table if that row has related rows. For example, you cannot delete an employee from the EMPLOYEE table if that employee is assigned to a job in the JOBS table.

Oracle supports only two kinds of referential integrity:

1. Enabling referential integrity to check values in related tables when you enter data. If the data value is not allowed (as determined by the rules above), the data entry fails and the data is not added to the database.

2. Cascading deletes.

By now you should have got the picture!!!

SOME MORE HINTS:
DELETE removes one or more records in a table, checking referential constraints (to see if there are dependent child records) and firing any DELETE triggers. In the order you are deleting (child first then parent) there will be no problems. TRUNCATE removes ALL records in a table. It does not execute any triggers.Also, it only checks for the existance (and status) of another foreign key pointing to the table. If one exists and is enabled, then you will get your error. This is true even if you do the
child tables first.

You should disable the foreign key constraints in the child tables before issuing the TRUNCATE command, then re-enable them afterwards.

Final XPLANATION:

QUESTION:Suppose I have the tables:Father(A, B, C),Son(X,Y)
Father.Primary Key (A)
Son.Foreign Key (X) refers Father.primarykey(A)
This implies that "Son" table has child records of the parent table "Father".
Now I'm trying to delete a row using the query:
delete from Father where A = 123;
jst as you were asking!!
So now what happens?

ANS:Primary and foreign keys are defined the parent/child relationship, you CANNOT delete a record from parent table until it has record in child table.If your parent table R1 has any child record oracle does not allow to delete this parent record
because oracle RESPECTS the parent/child relationship.
:+)
For your future reference you should define keyword ON DELETE CASCADE with your primary key, this key implicitly delete the child records when you try to delete parent record.

But for now the best way is to delete the associative child record of this primary key from the child table then delete it from parent table.

for more IDEAS ::::Also look at how to disable/enable constraints!!!!

A bit too detailed:but hope this helped you.

Questions and Answers Accessing Oracle Database

I have a oracle database out on my company's network which I need to access.

1. I have the IP address of where this oracle database is located.
2. I have the name of the database
3. I have username and password

How do I connect to this database. What all do I need to set up the enviroment on my computer to access this database.

Vijay R Dupati

You will need a tnsnames file. And you will some tool to connect with, either sqlplus, Toad or other similar products. In your tnsnames file on your machine there must be an entry for that database and ip address or host name. Then you can use one of the tools such as Toad or sqlplus to connect to the db. Login with your user name and password and try to connect in one of those tools or something similar. You can also tnsping the database to make sure you can reach it. on the command line in dos, c:\tnsping ip_address. Then make sure it gives you a return so that you know the db is there. This is just to start out to see if you can reach it.

Alex oleary

To access oracle database you need to installed oracle client software i.e. sqlplus or another tool like TOAD, SQL Navigator etc.

SQL*PLUS is the oracle client software ship along with u r oracle Enterprice cd. While Installing oracle select Oracle client it will install sql*plus & sql*net.

After Successful Installation Modify your tnsnames.ora file (resides in ORACLE_HOME/network/adin

dir).

db_alias =
(DESCRIPTION =
(ADDRESS_LIST =
(ADDRESS = (PROTOCOL = TCP)(HOST = )(PORT = ))
)
(CONNECT_DATA =
(SERVICE_NAME = )
)
)

After these setting use tnsping on command prompt :
tnsping

If tnsping reply correctly
use sqlplus to connect to database
sqlplus dbuser/dbpassword@db_alias

Questions and Answers What is PL/SQL tables?

What is PL/SQL tables. When and why they are used.

PL/Sql table is a virtual array(single array) table defined during runtime.These tables help u in storing,manipulating in a blocks thus removing the need to connect to the database for information except for the first time and later can be updated into the database.

eg
Assume I have a table emp

emp
------
empno
empname
empsal
saldate
empcomm

Now I would like to give the employees an increment/commission and will create a procedure with some logic.

Create procedure empinc
as
type v_empsal is table of emp%rowtype;
cursor as my_empsal is select * from emp
where empsal.empno=emp.empno;
begin
open my_emp
fetch my_emp into v_empsal;
exit when my_emp%notfound;

for i in v_empsal.first..v_empsal.last
loop
if v_empsal is not null then
v_empsal(i).empcomm:=v_empsal(i).empsal/100*10;
v_empsal(i).empsal= v_empsal(i).empsal
+v_emp(i).empcomm;
end if;
end loop;

begin
forall k in v_empsal.first..v_empsal.last
insert into empsal vlaues v_empsal(k)
end;

end;

In the above example as you see I didn't need to use any extra valrables nor define any data types. Both of these were as it was defined in the database and the array takes care of storing the values and insertion of the details in to the table was done by
the decalring the table type and the array with in it

Kiran Patil

Anyway you are using the cursor variable, so you can loop across the records and process one by one. The use of table type variable is not significant.

When you open the cursor, during first fetch use bulk collect and take the records into table variables declared. After this close the cursot. YOU NEED NOT LOOP across the cursor.

Table type variable is very useful when you need to select in the array.

Declare
type empno_list is table of emp.empno%;
empno_list_var empno_list ;
begin
select empno BULK COLLECT into empno_list_var from
scott.emp where empno > 100 ;

for v_empno in empno_list_var.first ..
empno_list_var.last
loop
...
;;;
---
end loop;

end;

Questions and Answers Using Trigger And Procedure Together

Table Name: INSTRUCTOR
INSTRUCTOR_ID INSTRUCTOR_NAME SALARY COMMISSION MENTOR_ID DATE_HIRE
------------- --------------- --------- ---------- --------- ---------
700 WAYNE 4500 300 16-MAY-81
628 MONROE 3000 700 16-JUN-84
790 NEWMAN 3100 300 700 16-DEC-82
795 BOGART 3200 700 16-DEC-83
515 SHELLEY 3500 200 700 20-JAN-91
222 CAINE 5500 350 02-NOV-76
978 STEEL 5000 250 222 16-JAN-80
560 LAUREL 5200 200 978 16-DEC-83
835 SPARKS 4000 200 978 16-DEC-84
243 TUCKER 2000 835 18-DEC-90
263 JOHNSON 4000 835 18-JUL-92
453 LODGE 2500 100 835 14-SEP-88

Table Name: AUTH
INSTRUCTOR_ID COURSE_ID AUTH_DATE
------------- --------- ---------
222 315 14-MAR-90
222 415 13-JAN-92
978 815 14-MAR-89
700 315 14-FEB-91
835 515 12-MAR-92
515 915 22-APR-91
263 215 14-JUN-92
263 315 14-FEB-92
453 715 14-AUG-93
790 315 14-AUG-91
560 915 14-AUG-91
453 615 14-JUL-93
628 315 13-JUL-91

My Question requirement is:
1) From the INSTRUCTOR table, if the salary of that instructor >= 3750, then he/she can insert new record on the AUTH table, BUT if salary <>

SO, I SOLVE this question using the method below, and can some one help me to check any logic error on it.
cause even i insert a new record where the instructor salary already <>
******************************************************
INSERT INTO INSTRUCTOR(INSTRUCTOR_ID,
INSTRUCTOR_NAME,
SALARY,
COMMISSION,
MENTOR_ID,
DATE_HIRED)
VALUES (100, 'JOSH', 2000, 500, 700, '11-AUG-05');

INSERT INTO AUTH(INSTRUCTOR_ID,
COURSE_ID,
AUTH_DATE)
VALUES(100, 515, '11-AUG-05');
******************************************************
=============================================================================
CREATE OR REPLACE TRIGGER CHECK_SALARY_TR
BEFORE INSERT
ON AUTH
DECLARE
SALARY INSTRUCTOR.SALARY%TYPE;
BEGIN
IF (SALARY >= 3750)THEN
RAISE_APPLICATION_ERROR(-20101,'THANKS, YOU HAVE AN AUTHORIZATION TO OFFER COURSES');
ELSIF (SALARY <>
RAISE_APPLICATION_ERROR(-20102,'SORRY, YOU DO NOT HAVE AUTHORIZATION TO OFFER COURSES');
END IF;
END;
=============================================================================
CREATE OR REPLACE PROCEDURE INSERT_AUTH_PROC(P_INSTRUCTOR_ID AUTH.INSTRUCTOR_ID%TYPE,
P_COURSE_ID AUTH.COURSE_ID%TYPE,
P_AUTH_DATE AUTH.AUTH_DATE%TYPE ) IS
BEGIN
INSERT INTO AUTH(INSTRUCTOR_ID, COURSE_ID, AUTH_DATE)
VALUES (P_INSTRUCTOR_ID, P_COURSE_ID, P_AUTH_DATE);
END INSERT_AUTH_PROC;
=============================================================================

--------------------------------------->

In your trigger you have defined a variable SALARY and used it in the IF..ELSIF. Since the value of SALARY is NULL (you haven't initialized it) both the IF and ELSIF will evaluate to FALSE. You need to populate the variable, probably by querying the INSTRUCTOR table with the ID of the instructor from the insert. Use the NEW record supplied by the trigger (:new.instructor_id).

Also, I don't think you want to use the RAISE_APPLICATION_ERROR if the insert is allowed. Doing so will cause the insert to fail. Perhaps you are just doing that for testing.

--------------------------------------->

=============================================================================
CREATE OR REPLACE TRIGGER CHECK_SALARY_TR
BEFORE INSERT
ON AUTH
DECLARE
SALARY INSTRUCTOR.SALARY%TYPE;
BEGIN
IF (SALARY < 3750) THEN
RAISE_APPLICATION_ERROR(-20101,'SORRY, YOU DO NOT HAVE AUTHORIZATION TO OFFER COURSES');
END IF;
END;
=============================================================================
CREATE OR REPLACE PROCEDURE INSERT_AUTH_PROC(P_INSTRUCTOR_ID AUTH.INSTRUCTOR_ID%TYPE,
P_COURSE_ID AUTH.COURSE_ID%TYPE,
P_AUTH_DATE AUTH.AUTH_DATE%TYPE ) IS
BEGIN
INSERT INTO AUTH(INSTRUCTOR_ID, COURSE_ID, AUTH_DATE)
VALUES (P_INSTRUCTOR_ID, P_COURSE_ID, P_AUTH_DATE);
END INSERT_AUTH_PROC;
=============================================================================

How to modify the trigger coding so that the SALARY can refer to the most currently inserted new row?

example: I insert new record into the INSTRUCTOR table where the new instructor have the SALARY <>

It can run smoothly if i change the ......

SALARY INSTRUCTOR.SALARY%TYPE;

TO BECOME

SALARY INSTRUCTOR.SALARY%TYPE:=2000; (this will not allow me to insert into AUTH table)
SALARY INSTRUCTOR.SALARY%TYPE:=5000; (this will allow me to insert into AUTH table)

BUT I don't want it to be fix value! I want the trigger to check the SALARY on the new instructor that i just inserted.

PROBLEM: I don't really know how to use the :new and :old like what you told me, if not mistaken, the :new should be only available on "BEFORE INSERT or update" right.

--------------------------------------->

You're correct, the NEW and OLD are only available to row triggers. Sorry about that, didn't catch that your trigger was not a row trigger. Could you make this a row trigger instead? Or, add the validation code to the procedure, prior to the insert.

--------------------------------------->

Thanks again for your help one more time. I try to implement the technique that you suggest and now I done perfectly. Thanks.

Below is the code that run successfully. with make sure of :NEW command
=============================================================================
CREATE OR REPLACE TRIGGER CHECK_SALARY_TR
BEFORE INSERT
ON AUTH
FOR EACH ROW
DECLARE
V_SALARY INSTRUCTOR.SALARY%TYPE;
BEGIN
SELECT SALARY
INTO V_SALARY
FROM INSTRUCTOR
WHERE INSTRUCTOR_ID = :NEW.INSTRUCTOR_ID;
IF (V_SALARY < 3750) THEN
RAISE_APPLICATION_ERROR(-20101,'SORRY, YOU DO NOT HAVE AUTHORIZATION TO OFFER COURSES');
END IF;
END;

Questions and Answers Error in PL/SQL block of trigger

I have written a trigger whose PL/SQL block contains a simple select statment among many other statements.
Now I find that, if the select statement returns no rows the trigger does not continue its operation further and aborts there itself. And if the select statement returns some rows, then it works fine.

I tried to execute a simplified PL/SQL block of the trigger in SQL*Plus and following were the results:

************************
declare
tempdate date;
begin
select trdt into tempdate from inv_trans;
if sql%notfound then
null;
end if;
end;
/
************************

When no data is present in inv_trans table, the result was:
************************
declare
*
ERROR at line 1:
ORA-01403: no data found
ORA-06512: at line 4
************************

And when the table inv_trans had data, the result was:
************************
PL/SQL procedure successfully completed.
************************

Why is the piece of code flashing an error when I have already given a treatment if no data is found.
Why is it taking "No Data in table" as an abnormal condition and not normal?

-------------------------

Your problem is in the fact that you haven't given a treatment if no data was found, as you said you've been doing'.

sql%notfound was never reached in case where no record was returned.
The exception was raised in the select into statement.
That's the default Oracle behaviour.

select into statement always raise ORA-01403 error
if no record was returned and no value set into variable.

You'll have to handle the exception.

Here is the code that will work the same logic, without any problem:

[color=red]declare
tempdate date;
begin
select trdt into tempdate from inv_trans;
exception
when no_data_found then
null;
end;
/ [/color]

Questions and Answers Is IMPORT & EXPORT is platform dependent

Please help me to find the soultion for this,,,,

I'll explain u my problem....

1. I have a Unix server Running Oracle 7.2
2. I have a user called 'Namankan' on Oracle DB
3. I have to shift the entire tables of user 'Namankan' from this System to a new server running Windows XP (or NT) with Oracle 8 (Not 8i)

If you are going to suggest me that I spool the entire data into text files and import them by running SQL*Loader in the new system, Pls dont suggest.......coz
i) Data is too large, ii) Table level validations in database will not allow the data to go in.
I have tried making a .dmp file using exp command on Unix Machine with default parameters, and have exported the entire data into a file called Intecons.dmp which is 175 MB, zipped into 28MB

Then I have taken this file onto Windows system with Oracle 8 and tried to import it through Imp80 command

It says
* Invalid Header Information, OS different (some such 2-3 lines)

As suggested by someone in a yahoo chat room, I Have tried to change the header information in .dmp file using a hex editor, I matched it to same as it was in a sample .dmp I made using exp80 command on my windows machine.......... Sometimes, it asks 2-3 questions and after replies starts dumping junk......... sometimes it hangs the system

I also came across to a data extraction program NXTract, however, its similar to spooling of files, even if it extracts data from .dmp file, so it is useless for me

Puneet Sachar

IMP/EXP IS NOT PLATFORM DEPENDANT!!!!!!!!

Gawd Hex editor hacking on dmp binary files.... thatz weird!!!
The guy who gave you that advice is either brilliant
or
....let me leave this here

Firstly:
With the Oracle EXPORT and IMPORT utilities you can transfer data objects between Oracle databases, even if they reside on platforms with different hardware and software configurations.
ie: Dump files also aren't OS-specific; as a result, you can use Export/Import to transfer data between databases on different platforms.

Secondly:
Exporting data from a lower version of oracle into a higher version===no problem
The vice versa ==== got to do it tactically!!

IN your case Puneeth:
From 7.3.3 to 8 => Use the EXPORT 7.3.3 to export the data from the 7.3.3 database and IMPORT 8 to import the data into the 8 database. This should work just fine without any dependancy on the OS.

The PROBLEM of yours could be simple as this:
Did you use ftp to transfer the dmp file from the unix system in to ur target machine?
IF SO: did you type
ftp>bin
before you did the transfer?
When transferring the export dump file over a network, the file has to be transmitted in binary mode.
Transmitting export files in character mode (ASCII) causes errors when the file is imported.

If the problem is still not solved post the errors that are being logged so that we could actually understand the problem come up with some clear cut answer!!!

I see that you have actually posted a similar posting somewhere where you have suggested to pay the person who helps you get through this.... so is that offer still valid here :+)

Channesh

As per oracle corp:
When creating an export dump file for an import into a higher release database (e.g.: from Oracle8i to Oracle9i), use a version of the EXPORT utility that is equal to the version of the source database (= lowest version = Oracle8i in this case).
The export FAILS if you use a HIGHER release export version.
For example, if you use the export 9.0.1 utility the export data from an 8.1.7 database, you will get the errors:
EXP-56 Oracle error 942 encountered
ORA-942 table or view does not exist
EXP-0 Export terminated unsuccessfully
Solution: use the lowest release export utility (8.1.7 in this case).

Hence I dnt think you can use oracle8 exp on the oracle7.3 database and get things right....!!

And i totally agree HEX editor on dmp files==bad idea.

Questions and Answers How Can I Copy Data in Another System

I am using oracle 9i.
Now I want to copy its whole data like tables, cursors, function, procedure and trigger to an another system which has no link with my first system.

Oracle export (EXP) and import (IMP) utilities are used to perform logical database backup and recovery. export / import are logical backup system in oracle.

Just type exp(in case of export) or imp (in case of import) at prompt, you will get online help from oracle and supply parameters, it will serve your purpose.

Otherwise, the command is

login as sys user and give command...

exp file= full=y statistics = none (will export all schema backups)

for example,

exp scott/tiger file=emp.dmp log=emp.log tables=emp rows=yes indexes=no
(table level export)
exp scott/tiger file=emp.dmp tables=(emp,dept) (exporting 2 tables)

Similarly import command will be like....

imp scott/tiger file=emp.dmp full=yes
imp scott/tiger file=emp.dmp fromuser=scott touser=scott
tables=dept

Questions and Answers Advantage Between Range Scan & Skip Scan In Oracle

Can someone explain me how the range scan is better than Skip Scan in Oracle 9i.
Is it advantage of tuning queries to take RANGE SCAN access path than SKIP SCAN path?

In index range scans,
<>

Multiple rows with identical values are sorted in ascending order by rowid.
< /quotedoc>

in Skip scan
<>

Skip scanning lets a composite index be split logically into smaller subindexes. In skip scanning, the initial column of the composite index is not specified in the query. In other words, it is skipped.

The number of logical subindexes is determined by the number of distinct values in the initial column. Skip scanning is advantageous if there are few distinct values in the leading column of the composite index and many distinct values in the nonleading key of the index.
< /quotedoc>

My understanding is,
Skip scanning is good only if the cardinality of the leading columns are low ( very few distinct records).
if the cardinality of the rest columns are too low, eventually the CBO will ignore the indexes.

Questions and Answers Droping Logfile Group Failed

How to drop a log file group that is being the current logfile group?
I have 4 groups. In that I want to drop one group and that group is the active one.
If I drop that group it is telling that it is the current group.
If I try to switch logfile it is telling that database is not open.

----->
Have you use the SYS user to start the database ?

SQL> conn sys/ as sysdba
connected to an idle instance
SQL> startup

----->
In mount stage I want to drop it.

----->
In mount stage you can drop non-current log group but cannot drop or switch current log group.

----->
1. You must have at- least two online groups.
2. You can not drop a active online active redo log group.
3. If it active switch it by alter system switch logfile before dropping.
3. make sure that online redo log group is archived ( if archiving is enabled).
Syntax :- Alter database drop logfile group .

----->
Open the database
switch logfile.
drop the logfile

Why do you want to drop the logfile only on mount stage??

----->
There was some problem with the logfile while opening the database. So to rectify that I need to drop that group.
Database is not starting.. If it get started then I would have used switch log file command then I would have droped it.
Since it is not starting I am forced to drop it in mount stage.

Since the log file is the current log then in mount stage switch log file is not working.
So what I did I recreated control file. Now it is working

----->
Well if the problem has been solved, No issues.
But the appropriate solution would have been:

Alter database clear unarchived logfile group <>;

----->
My database is in no archivelog mode.. will it work....

Moreover suppose if it is in archivelog mode then

If we clare the logfile group will it clear the data or will it move the data to the logfiles... and what effect will be there if the database is in archivelog mode? Like dataloss?

----->
This statement is to be used only when the current logfile has became corrupt and cannot be dropped.It will simply clear the contents and will not copy them any other log group

ALTER DATABASE CLEAR LOGFILE GROUP ;
Use this for noarchivelog mode

ALTER DATABASE CLEAR UNARCHIVED LOGFILE GROUP ;

Use this verison of clearing a log file if the corrupt log file has not been archived

----->
I have a question how does creating a new control file , solves the problem as the new control file will be pointing to the current logfile which has the problem

----->
In the new control which I created in the trace file I edited and droped the logfile which is giving problem and then assigend the new control file to the database.

Oracle Application Oracle Application Hints and Tips

Press Ctrl+D to bookmark this page.

Oracle Financials Forums
This is an email discussion group for ALL ORACLE FINANCIALS MODULES (General Ledger, Account Payable, Receivable...) to share information and request assistance from ORACLE PEERS around the world. The discussion topics should be focused on All Oracle Financials related issues.

Control Files Backup and Recovery Tips

Helpful statement to end the backup for the tablespaces which are in the online backup mode:

1- Create a script through the following commands:
svrmgrl> spool endhotbackup.sql
svrmgrl> select 'ALTER DATABASE DATAFILE '''||name||''' END BACKUP ' FROM V$DATAFILE;

2- Cleanup endhotbackup.sql through vi

3- svrmgrl> @endhotbackup.sql

4- startup the database

Oracle Forms TEXT_IO code to write data to a flat file

PROCEDURE CREATE_FLAT_FILE IS
-- DESCRIPTION
-- Simple procedure to write to a text fille from a form
-- NOTES
-- Call this procedure from the WHEN-BBUTTON-PRESSED trigger
-- REQUIREMENTS
-- Must have access to local drives
--
--=============================================================================

in_file TEXT_IO.FILE_TYPE;
linebuf VARCHAR2(80);
your_file VARCHAR2(50) := 'C:\TEMP\your_file.dat';
text_line VARCHAR2(400);
BEGIN
in_file := TEXT_IO.FOPEN(your_file, 'W');
GO_BLOCK('YOUR_DATA_BLOCK');
FIRST_RECORD;
LOOP
IF :your_checkbox = 'Y' THEN
text_line := LPAD(:your_item1, 10, ' ')||
LPAD(:your_item2, 20, ' ')||
LPAD(:your_item3, 30, ' ')||
LPAD(:your_item4, 50, ' ');
--

TEXT_IO.PUT_LINE(in_file, text_line);
END IF;
--
exit when :SYSTEM.LAST_RECORD = 'TRUE';
NEXT_RECORD;
END LOOP;
--
TEXT_IO.FCLOSE(in_file);
EXCEPTION
WHEN NO_DATA_FOUND THEN
TEXT_IO.FCLOSE(in_file);
END;

Oracle Forms 4.5 FAQ

Can on bypass the Oracle login screen?

The first thing that the user sees when using runform is the Oracle logon prompt asking them for their username, password, and database to connect to. You can bypass this screen or customise it by displaying your own logon screen. Eg:

ON-LOGIN


declare
uname varchar2(10);
pass varchar2(10);
begin
uname := 'username';
pass :='password';
logon(uname, pass||'@connect_database');
end;






Can one issue DDL statements from Forms?

DDL (Data Definition Language) commands like CREATE, DROP and ALTER are not directly supported from Forms because your Form is not suppose to manipulate the database structure.

A statement like CREATE TABLE X (A DATE); will result in error:

    Encountered the symbol "CREATE" which is an reserved word.
However, you can use the FORMS_DDL built-in to execute DLL statements. Eg:
    FORMS_DDL('CREATE TABLE X (A DATE)');

Can one execute dynamic SQL from Forms?

Yes, use the FORMS_DDL built-in or call the DBMS_SQL database package from Forms. Eg:
    FORMS_DDL('INSERT INTO X VALUES (' || col_list || ')');
Just note that FORMS_DDL will force an implicit COMMIT and de-synchronize Oracle Forms.


Forms won't allow me to use restricted built-in's. What should I do?

How to get around the "can't use a restricted built-in in built-in XXX" message:

1. Create a TIMER at the point where you want the navigation to occur. Eg. create_timer('TIMER_X', 5, NO_REPEAT);

2. Code a WHEN-TIMER-EXPIRED trigger to handle the navigation

DECLARE
tm_name VARCHAR2(20);
BEGIN
tm_name := Get_Application_Property(TIMER_NAME);
IF tm_name = 'TIMER_X' THEN
Go_Item('ITEM_X');
END IF;
END;
Dirty but effective (didn't Oracle promise to fix this feature?).


Can one change the mouse pointer in Forms?

The SET_APPLICATION_PROPERTY build-in in Oracle Forms allow one to change the mouse pointer. Eg:

SET_APPLICATION_PROPERTY(CURSOR_STYLE, BUSY);


Why doesn't my messages show on the screen?

Regardless of whether you call the MESSAGE() built-in with ACKNOWLEDGE, NO_ACKNOWLEDGE, or with no mode specification at all, your message may or may not be displayed. This is because messages are displayed asynchronously. To display messages immediately, use the SYNCHRONIZE build-in:

message('...'); synchronize;

This can also be used to execute a query while the user is looking at the results of a previous query.


What happened to SQL*Menu?

SQL*Menu is now fully integrated into Oracle Forms 4.5. Application menus can be added to your application by creating Menu Modules (*.MMB) and generate it to Menu Module Executables (*.MMX).

Developer Programming Tips PL/SQL coding

1. Don't code Exception handlers unless you have a clear and compelling reason to do so. Unless there is a specific problem you are trapping, how can you ever guess what problem might occur? By leaving out the exception code and by following my no blank lines rule, the line number returned with the exception error points to the exact place the error occurred.

2. Don't raise your own exceptions in your procedures. My reasons-- they break the rules of structured programming. When you RAISE , it is just a disguised GOTO statement, which forces processing immediately to jump to the end of the procedure.

To handle a user-created exception, you have to write special code in three places in your procedure: you have to declare it (Pragma exception init...), you have to raise it (GOTO the end), and you have to handle it (Exception when...). It is so much easier and clearer to take care of a special condition in-line in your code, especially for someone else trying to read your code.

To pass back an error condition to a calling procedure, use a parameter -- something like Return_Code. Then the calling procedure can test the Return_Code value immediately after the call, making all the code easier to follow. If you use an exception in the caller, it isn't immediately clear to the next person reading your code that the sub procedure can raise such an error. It just confuses the process.

Archives