<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Earl C. Ruby III &#187; Oracle</title>
	<atom:link href="http://earlruby.org/category/oracle/feed/" rel="self" type="application/rss+xml" />
	<link>http://earlruby.org</link>
	<description>this must be the place</description>
	<lastBuildDate>Sat, 17 Dec 2011 22:20:04 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<item>
		<title>Running Oracle&#8217;s CSSCAN utility as sysdba</title>
		<link>http://earlruby.org/2010/04/running-oracles-csscan-utility-as-sysdba/</link>
		<comments>http://earlruby.org/2010/04/running-oracles-csscan-utility-as-sysdba/#comments</comments>
		<pubDate>Sat, 10 Apr 2010 19:28:02 +0000</pubDate>
		<dc:creator>Earl Ruby</dc:creator>
				<category><![CDATA[Oracle]]></category>

		<guid isPermaLink="false">http://earlruby.org/?p=148</guid>
		<description><![CDATA[If you need to run Oracle&#8217;s CSSCAN utility to check a database prior to converting to a new character set, you may have problems getting it to run &#8220;as sysdba&#8221;. There are a number of articles on the web that explain how to do this, and most of the explanations don&#8217;t work. Oracle.com says that [...]]]></description>
			<content:encoded><![CDATA[<p>If you need to run Oracle&#8217;s CSSCAN utility to check a database prior to converting to a new character set, you may have problems getting it to run &#8220;as sysdba&#8221;. There are a number of articles on the web that explain how to do this, and most of the explanations don&#8217;t work.</p>
<p><a href="http://download.oracle.com/docs/cd/B19306_01/server.102/b14225/ch11charsetmig.htm#CEGCHGIJ">Oracle.com</a> says that you should use:</p>
<pre>
CSSCAN /AS SYSDBA FULL=Y
</pre>
<p>This gives the error:</p>
<pre>
LRM-00108: invalid positional parameter value 'SYSDBA'
failed to process command line parameters                                      

Scanner terminated unsuccessfully.
</pre>
<p>Others recommend:</p>
<pre>
csscan "SYS/[password] as sysdba" full=y tochar=AL32UTF8 array=1024000 process=16
</pre>
<p>Which results in:</p>
<pre>
LRM-00108: invalid positional parameter value 'as'
failed to process command line parameters                                                           

Scanner terminated unsuccessfully.
</pre>
<p>Various other guides on the web also fail to work. Trying to run csscan as &#8220;SYSTEM&#8221;, as suggested by <a href="http://articles.techrepublic.com.com/5100-22_11-5219084.html">Tech Republic</a> and <a href="http://download-uk.oracle.com/docs/cd/B19306_01/server.102/b14225/ch12scanner.htm#i1006008">Oracle UK</a>, you get the error:</p>
<pre>
CSS-00113: user system is not allowed to access data dictionary
</pre>
<p>Trying to run csscan as &#8220;SYS&#8221;, as suggested by <a href="http://forums.oracle.com/forums/thread.jspa?threadID=960082">Oracle Forums</a>, results in the error:</p>
<pre>
ORA-28009: connection as SYS should be as SYSDBA or SYSOPER
</pre>
<p><a href="http://www.oracle-base.com/articles/10g/CharacterSetMigration.php">ORACLE-BASE</a> shows a method for running csscan in a Windows environment:</p>
<pre>
C:\>CSSCAN \"sys/password@db10g AS SYSDBA\" FULL=Y
</pre>
<p>This might work in Windows, on a Linux server you get:</p>
<pre>
CSS-00110: failed to parse userid
Scanner terminated unsuccessfully.
</pre>
<p>Here&#8217;s how you do it. Log in as a user with DBA rights and do the following:</p>
<pre>
> csscan full=y tochar=AL32UTF8 array=1024000 process=16

Character Set Scanner v2.1 : Release 10.2.0.0.0 - Production on Sat Apr 10 18:41:37 2010

Copyright (c) 1982, 2005, Oracle.  All rights reserved.

Username: sys/[password] as sysdba
</pre>
<p>That should run the database character scanner on your database. If you get the error:</p>
<pre>
CSS-00107: Character set migration utility schema not installed       

Scanner terminated unsuccessfully.
</pre>
<p>&#8230; then go back and install the character set migration utility schema, then try running csscan again. You can install the character set migration utility schema with:</p>
<pre>
> cd $ORACLE_HOME/rdbms/admin
> sqlplus /nolog                                         

SQL*Plus: Release 10.2.0.2.0 - Production on Sat Apr 10 18:40:04 2010

Copyright (c) 1982, 2005, Oracle.  All Rights Reserved.

SP2-0640: Not connected
18:40:04 nolog> connect / as sysdba
Connected.                         

Session altered.

Elapsed: 00:00:00.00
18:40:08 sys> @csminst.sql
</pre>
<p>If you get this error you can ignore it:</p>
<pre>
grant READ on directory log_file_dir to system
                        *
ERROR at line 1:
ORA-22930: directory does not exist
</pre>
<p>Hope you find this useful.</p>
]]></content:encoded>
			<wfw:commentRss>http://earlruby.org/2010/04/running-oracles-csscan-utility-as-sysdba/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Creating BETTER auto-increment columns in Oracle</title>
		<link>http://earlruby.org/2009/01/creating-auto-increment-columns-in-oracle/</link>
		<comments>http://earlruby.org/2009/01/creating-auto-increment-columns-in-oracle/#comments</comments>
		<pubDate>Wed, 21 Jan 2009 20:51:11 +0000</pubDate>
		<dc:creator>Earl Ruby</dc:creator>
				<category><![CDATA[Oracle]]></category>
		<category><![CDATA[auto-increment]]></category>
		<category><![CDATA[database]]></category>
		<category><![CDATA[sequence]]></category>
		<category><![CDATA[trigger]]></category>

		<guid isPermaLink="false">http://earlruby.org/?p=36</guid>
		<description><![CDATA[Oracle PL/SQL code that behaves just like a MySQL or PostgreSQL auto-increment column, but which also fixes the sequence number when an application provides its own ID number for a record, which is one place whereMySQL and PostgreSQL autoincrement columns fail.]]></description>
			<content:encoded><![CDATA[<p>I was explaining to a developer today how Oracle doesn&#8217;t support auto-increment columns for IDs and how you have to implement your own. I wanted to point him to a tutorial but I found that most of the tutorials have PL/SQL code with unexplained side effects. So I thought I&#8217;d post some Oracle PL/SQL code that behaves just like a MySQL or PostgreSQL auto-increment column, but which also fixes the sequence number when an application provides its own ID number for a record, which is one place where MySQL and PostgreSQL autoincrement columns fail.</p>
<p><strong>Step 1:</strong> Know the names of your tablespaces. Know which tablespace you want to use for your tables and which tablespace you want to use for your indexes. Don&#8217;t assume that Oracle is going to put the table in the right place. To get a list of available tablespaces:</p>
<pre>select tablespace_name from user_tablespaces;</pre>
<p><strong>Step 2:</strong> Create your table. In this example the table is built in the tablespace TDATA and the primary key index is built in the tablespace INDX.</p>
<pre>create table example (
    id number not null,
    name varchar2(30),
    constraint example_pk primary key(id) using index tablespace INDX
) tablespace TDATA;</pre>
<p>Note that by declaring the id column &#8220;not null&#8221; you can&#8217;t add a record with an empty ID field, ever.</p>
<p>Creating the primary key constraint on a separate line allows us to name the constraint, which can be handy when you&#8217;re looking through the data dictionary later on trying to figure out which constraint does what.</p>
<p><strong>Step 3:</strong> Create a sequence. In this case I create an ID sequence that starts at 1 and goes on from there. If you want to start your ID sequence with a different number, or increment by some other amount, change these values.</p>
<pre>create sequence example_id_seq start with 1 increment by 1;</pre>
<p><strong>Step 4:</strong> Create a trigger. This is what does the actual work setting the ID number. There are many ways to do this, here are two:</p>
<p><strong>Method 1:</strong> Use a sequence-generated ID for all IDs.</p>
<pre>create or replace trigger example_insert
before insert on example
for each row
begin
    select example_id_seq.nextval into :new.id from dual;
end;
/</pre>
<p>Method 1 will always use a sequence-generated ID no matter what. For example:</p>
<pre>SQL&gt; insert into example (id, name) values (100, 'Earl');
1 row created.
SQL&gt; insert into example (name) values ('Cleopatra');
1 row created.
SQL&gt; insert into example (name) values ('Frankenstein');
1 row created.
SQL&gt; select * from example;
        ID NAME
---------- ------------------------------
         1 Earl
         2 Cleopatra
         3 Frankenstein</pre>
<p>In this case the trigger-supplied ID 1 overwrote the user-supplied id 100.</p>
<p><strong>Method 2:</strong> Allow users to supply their own IDs when they want to.</p>
<pre>create or replace trigger example_insert
before insert on example
for each row
declare
    max_id number;
    cur_seq number;
begin
    if :new.id is null then
        -- No ID passed, get one from the sequence
        select example_id_seq.nextval into :new.id from dual;
    else
        -- ID was set via insert, so update the sequence
        select greatest(nvl(max(id),0), :new.id) into max_id from example;
        select example_id_seq.nextval into cur_seq from dual;
        while cur_seq &lt; max_id
        loop
            select example_id_seq.nextval into cur_seq from dual;
        end loop;
    end if;
end;
/</pre>
<p>Method 2 will use the sequence-generated ID if the insert statement doesn&#8217;t supply an ID, which is what MySQL and PostgreSQL do. It also updates the sequence so that the next value of the sequence won&#8217;t collide with IDs supplied by an insert statement.</p>
<p>For example, let&#8217;s say I&#8217;m using Trigger Method 2 and just loaded the table with a bunch of old data, including old ID numbers.</p>
<pre>SQL&gt; delete from example;
3 rows deleted.
SQL&gt; insert into example (id, name) values (200, 'Cleopatra');
1 row created.
SQL&gt; insert into example (id, name) values (300, 'Frankenstein');
1 row created.
SQL&gt; insert into example (name) values ('Earl');
1 row created.
SQL&gt; select * from example;

        ID NAME
---------- ------------------------------
       200 Cleopatra
       300 Frankenstein
       301 Earl</pre>
<p>The last record added gets an ID of 301.</p>
<p>Hope you find this useful.</p>
]]></content:encoded>
			<wfw:commentRss>http://earlruby.org/2009/01/creating-auto-increment-columns-in-oracle/feed/</wfw:commentRss>
		<slash:comments>44</slash:comments>
		</item>
	</channel>
</rss>

