oracle
latest
Since the docker version gave problems, a new attempt is made with an oracle linux VM. Here is a work instruction.
Install OL8 via vagrant, this is what my Vagrantfile looks like
| vagrantfile | |
|---|---|
Do vagrant up, and login and changes the passwords for vagrant and oracle, since they are not given.
Enable ssh to allow Password Login. restart sshd, you can now login remotely.
Install oracle-xe. visit
You have to come up with a password for SYS users here ! Also this will mention some interesting things.
The SID name will be needed later. Now you have to set some environment variables to continue. Since I wanted these systemwide, i ended up adding this file
export ORACLE_SID="XE" export ORACLE_HOME="/opt/oracle/product/21c/dbhomeXE/" export PATH="$PATH:$ORACLE_HOME/bin"
Now we still need to start the database with
Now you can use sqlplus directly. Execute this to make the interface available from outside the vm.
| expose web | |
|---|---|
If all is ok, you should be able to connect.
hostname : 192.168.1.251
port : 1521
sid : xe
username : system
password :
quick-start
If you really want an oracle install as fast as possible try this site.
tldr
| docker version | |
|---|---|
now you can connect with these settings :
Installation
This is all about oracle XE/express, because that's free ;) I tried versions 10,11 and 12. Some systems are easier than others, here is a little overview of what i tried:
- oracle XE 10 (32 bits), debian 64 bits : working but without apex:8080
- oracle XE 11G (32 bits), windows 32. Working out of the box.
- oracle XE 11G (64 bits), debian 64 bits, not working yet... lot's of problems
- oracle XE 11G (64 bits), fedora 64 bits : working but without apex:8080
- oracle XE 12G (64 bits). debian 64 bits : in progress
Overall most problems occur when trying to install on debian, but i am not going to switch distro's for oracle yet.. Since it seems to be developed on RedHat, fedora and CentOS work best. I guess solaris being from oracle also works ok ? The next sections will contain a LOT of problems and mostly solutions for debian.
Debian 64 bits, oracle express 11G
Keep with this guid for debian, since 10g is 32 bits. This is a combination of 2 sources : https://forums.oracle.com/thread/2229554 http://stackoverflow.com/questions/16545412/problems-installing-oracle-database-express-edition-11g Please follow it exactly, all steps seem to be needed.
delete old installation
If needed of course, but this guide gives you a clean slate to start with.
| clean old install | |
|---|---|
preparation
Granted: i don't know if theses steps are really necessary, but they won't hurt. See if you have enough swap space :
You will need at least 2GB, so this will probably not be needed unless you have very low memory to start with. But to enlarge the swap : To install a 1 GB swapfile (so in addition it will be 2GB) named swapfile in /, for example:
| stretch swap space | |
|---|---|
Now set some kernel parameters for oracle, create a file called /etc/sysctl.d/60-oracle.conf, and fill it with this :
| /etc/sysctl.d/60-oracle.conf | |
|---|---|
The kernel.shmmax should contain the max memory you have , so take it from
| recheck swap | |
|---|---|
And paste the MemTotal value there, it is both Kb. Then activate with :
Verify with :
| verify | |
|---|---|
It should contain the value specified : 6815744 Now we need to create the chkconfig tool since that is a redhat tool and debian does not have it. So create a file called /sbin/chkconfig with these contents.
And make it executable :
That last line is to anticipate the error you will get next, and that's a hard path to /bin/awk, probably also the redhat location. With settings like this, you will get the infamous errors mentioned in the troubleshooting section if you continue.
or ...
| error | |
|---|---|
This is handled by creating this file /etc/init.d/oracle-shm, containing
But note.. this did not work on another machine, that probably had too small /run/shm so i could enlarge that in the file : /etc/default/tmpfs Uncomment the SHM_SIZE parameter and make it 2GB :
| shared memory | |
|---|---|
And reboot, or find a way to restart tmpfs and log it here how ;) Make oracle-shm executable :
| executable | |
|---|---|
Now to make sure this starts at reboot... reboot. After that try :
| verify | |
|---|---|
To check if it worked. Make sure you also restart oracle after running the script :
| restart oracle | |
|---|---|
The file that seems to work best was oracle-xe-11.2.0-1.0.x86_64.rpm.zip It is an rpm files, so of course you need to install extra software to install rpm's on debian:
| preliminaries | |
|---|---|
Create a debian package of it :
| convert to .deb | |
|---|---|
Now run dpkg
| install | |
|---|---|
If any of the steps fail you might end up with a running listener, and that hogs the ports 8080 or 1521 in a new install. You can stop the listener with :
If that gives an error, the executable occupying the port is tnslsnr so this will certainly help :
| stop listener | |
|---|---|
Apex (application express) install
Download from : visit First set the SID :
| SID | |
|---|---|
Then login with sqlplus :
| connect with sqlplus | |
|---|---|
When logged in run :
| apex install | |
|---|---|
This.....will... take.....a.........long.......time......... Pending... have not got this working yet !
troubleshooting
Installation of 11G goes ok up to the configuration step. The script is /etc/init.d/oracle-xe which fails on line : 274, which is a call to another script : $ORACLE_HOME/config/scripts/XE.sh. And that call boils down to :
| error script | |
|---|---|
The .sql files are all scripts run in sqlplus, so if we run these commands line by line : The first error given is :
| detailed error | |
|---|---|
This is usually cause by te fact that the TNS/SID name is unknown, the default is XE, so this will probably help :
| set sid | |
|---|---|
Run sqlplus again for the next error :
The seconds is very probably caused by the first, so let's focus on that. It just seems oracle is not running. I can't find where it would have been started, but running it by hand just silently fails.
| more errors | |
|---|---|
lsnrctl
| more errors | |
|---|---|
You need to set ORACLE_HOME to your installation, it is the directory where bin,scripts, etc are. As an actual example, i have this in my .bashrc file :
| set oracle home | |
|---|---|
But that's over to the next error on startdb.sh, this is in $ORACLE_HOME/scripts/startdb.sh. It is the script that is run when you do "Start Database" in the oracle menu's.
| error | |
|---|---|
Or start lsnrctl and run status for the same message. Try lsnrctl and run the start command.
In $ORACLE_HOME/network/admin/listener.ora the contents were :
I have no idea what hostname, and port will contain,or where they are set, so I changed that line to the hard values :
| fill in host:port | |
|---|---|
This takes care of the error.
debian 64 bits, oracle 10G universal
The best success so far on debian (and only really working install) was the universal XE install. It is version 10 of the database, and the express (free) edition. This is a debian package so that gives some hope. But... it is 32 bits and it The newer ones are not available for download (12) or only for windows 32-bit (11g) or linux redhat 64 bit(also 11g). So download the universal version : oracle-xe-universal_10.2.0.1-1.1_i386.deb Words are you also need bc:i386 installed and libaio. After installation you need to configure the installation. Also make the /var/local/subsys directory to prevent an error along the way.
| install | |
|---|---|
Then startup the database with:
| start | |
|---|---|
If you get an error about not being able to write to the log stream. You did not start as user oracle:
If ... thank's so far oracle, you get ANOTHER error like this :
| error | |
|---|---|
It turns out that the .oracle directory in /var/tmp is owned by root so :
| change owner | |
|---|---|
Next... Problem. The apex installation on port 8888 did not start. I installed it on port 8888, but nmap does not list that port, however it does list 1521 so oracle seems to be running. Unresolved so far, continuing with oracle developer and remote clients. additional : this is a common problem for 11g, it tried both fedora and centos because after all 11g comes as an .rpm file. But the same problems arise !!
cannot find oracle in nmap dump
I had this after setting the ip address to 192.168.2.5 instead of localhost. Make sure you also nmap on that address not localhost !!
cannot connect to local install
The message is :
| error | |
|---|---|
When trying to connect with clients, java or c interface functions.
Sqldeveloper
In absence of the web interface, this tool is quit usable. Download,unpack and go into the bin directory and run
| sqldeveloper | |
|---|---|
You will probably have to enter the path to a working java sdk, after that it will be stored in ~/.sqldeveloper/jdk. It has to be a JDK directory, JRE alone is not enough. be sure when you make a new connection you connect to the listener address, so localhost or 192.168.2.5 according to what you specified in listener.ora
ORA-00917: missing comma
Mainly caused by the use of single quotes in an INSERT query. I had escaped these quotes with :
| non-working escape | |
|---|---|
But the 'standard' escape is not used in oracle. While the above will work for both mysql as mongodb, oracle needs to escape it with another single quote. So :
| working escape | |
|---|---|
ORA-01704: string literal too long
Use setinputsizes() :
| alter input size | |
|---|---|
Both the uncommented as the commented versions work, but beware that sqlplus truncates the result for a select. See next chapter.
truncated output sqlplus
When inserting larger objects (CLOB) into the database, your select in sqlplus will be cut short. You can enlarge the output with :
| change output sizes | |
|---|---|
apache problems
This occurs when running oci_ functions in php under apache :
| error php/apache | |
|---|---|
The same script will run under the command line because variables like ORACLE_HOME etc are set. Not so in apache. You need to add this to the configuration.
| apache config | |
|---|---|
Though this does not solve my complete problem.. it did lead to a different error ;-) Oracle development ==================
Oracle uses instance identifiers or System identifiers to connect to a database. So this is the SID we talk about. The instance is associated with a database In express edition i think you are stuck with one database: xe.
SQL
The SQL is rather standard, all commands i type MySQL style work. Some exceptions of course. First watch that you need to commit your changes to see them though other channels. For instance :
Note that both are deleted, and that you cannot use the LIMIT command like in MySQL. So far so good, but if you now run a select from for instance the java program :
| from another connection | |
|---|---|
Not so expected, only after you do
| commit to make it stick | |
|---|---|
Will you get the expected :
PL/SQL
The procedural language extension for SQL, however i never used it because i always connect from another language like java, C or php that have their own procedural constructs. Mostly you will want to run (pl/)sql scripts and not type everything on the sqlplus command line, you use the @ sign for that :
The last one to show you that the .sql is filled in so it will save you same typing. This runs as script located in the directory where you started sqlplus, full path names are required otherwise, or relative paths as the example shows. Here are some major operations to be performed in PL/SQL, they will be reflected in the other connector chapters : java, C++ and php in the same order.
preliminaries
A lot of these examples are to be run in sqlplus, and it becomes tedious to connect every time. So use this format to login directly :
| login | |
|---|---|
If you have trouble running PL/SQL scripts and get a prompt, like :
Try typing a slash "/" and return, this acts as an 'execute'. You can also directly to the scripts. I will try to include it in the examples here. Also, you can directly in the script from the command line with :
| run scripts directly | |
|---|---|
After this you will remain in the sqlplus cli unless you also run 'exit' as the last command Let's say hello.sql contains this :
| script | |
|---|---|
The first line is needed This is because the default for pl/sql is not to display 'dbms_output'. And it is per session, so at the next connect it will be 'off' again. Also i intentionally put two slashes to make it run twice. The output of this will be :
A little bit too much for my taste, so use the -S silent option :
| silence option | |
|---|---|
Still too much !!, it seems you also need to set feedback of, so the start of the file will be :
And finally :
Now one more warning, do not use set feedback off or use -S without an exit at the end. You will have to type exit blind to get out of sqlplus in that case. Neat... let's start.
create table
A working pl/sql program for creating a table, in my case a table for storing html pages by name, and since i want to limit each html chapter i think the maximum for VARCHAR2 (32k) should suffice :
| create tables | |
|---|---|
Note i commented the feedback (comments are "--") because i want it this time. However the documented maximum value 32767 for VARCHAR2 gives an error. I had to get it down to 4000 and that in fact is becoming too small for a decent html chapter. So .. let's drop the table again :
| drop tables | |
|---|---|
There is no "IF EXISTS" clause in pl/sql, so you should do it using the PL logic of PL/SQL :
To run this code, you need to start sqlplus and issue @
| warning | |
|---|---|
Which is not very helpful, so to reveal the errors, you will have to type show errors, or if you are lazy ...
| show errors | |
|---|---|
Of course you could put it in the script itself... but that would mean you expect an error ;-), just take it out when it works. Oracle and C++ ==============
Since occi download only states windows i use libocci, though on linux they call it libclntsh for god knows what reason (windows is ociw32.dll) for both C and C++. When trying to download libocci i also noted that it wanted me to install odbc (?!?). If it uses ODBC what am i using libocci for then ?!?. But on this site i was assured that this is not the case. Here are the advantages of OCI. Maybe it's only occi hat used odbc ?
- OCI is optimized for queries. Transparent prefetch buffers reduce round-trips and improve performance and scalability. As a result, there is reduced memory usage on the server.
- OCI is optimized for round-trips. No-reply requests are batched until the next call is generated for the server. This allows certain calls to be lazily propagated.
- OCI is thread safe. You do not need to mutex (use mutual exclusivity locks) any of the OCI handles. ODBC is not thread safe, so you have to mutex most data structures.
- OCI provides an asynchronous event notification API for active databases.
- OCI provides enhanced array data manipulation language (DML) operations that reduce round-trips.
- OCI returns ROWIDs for all rows selected for update in a single round-trip. Using ROWID allows for more efficient SQL access.
- ODBC has no concept of sessions. OCI decouples connections, sessions and transactions. Multiple users can use a single connection; they get serialized on the connection for SQL operations. Multiple transactions can exist per user. This allows users to scale and service more users than there are connections available. Sessions and transactions can be migrated between connections to the same server.
- ODBC does not support object types, large objects (LOBs), and other new Oracle data types.
- ODBC affects server scalability. Using ODBC and having n number of concurrent users forces the server to have n number of processes service the clients if Oracle8i is operating in dedicated server mode. Your operating system may or may not support so many connections and processes.
- ODBC is a wrapper around OCI so it is slower.
So it's the other way round it seems: odbc is built upon oci. You can either do this via odbc, or as i have done here with libocci. The library is included in the oracle express installation, and is called lclntsh. Compiling the source used could be something like :
| compile demo | |
|---|---|
A collection of demo programs was once available in the demo directory $ORACLE_HOME/rdbms/demo, but that is cut down to a handful of examples. You can still download it from here :
| get demo programs | |
|---|---|
Although let it be noted, these are older version still they can be used to shed some light on this dark matter. Some functions like oparse(), are pre-version 8.0 and should not be used. see this page. As an example, i want to set up the web database in oracle just so that will be the example here. Again, here is a full example of connecting, create database, fill some row, print the rows, delete one row, and drop the table again. One note beforehand.. some examples used OCIConnectionPoolCreate, and subsequently the poolName that was returned from that call for the call to OCILogon(). The poolname is a string that looks like :
| poolname | |
|---|---|
That works but it takes an awful long time to connect, and just using the database name works instantly. So that is of course the way i use it in this example :
| example c++ | |
|---|---|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 | |
Oracle and java
java connection
This is a page about connecting to an oracle database server with java (JDBC).
Java Installation
This is a java example, but the problems described here are probably the same for any client. First the jdbc jar is needed to run this program. sauce The jar file is called ojdbc14.jar, get it from here The installation from scratch was troublesome, so if you have any problem, search in the troubleshooting section below to see if your problem is described there. For now i assume you have a working setup. Here is the sample java file OracleJDBC.java:
| example java | |
|---|---|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 | |
And here is how to run it :
| run example | |
|---|---|
Again, this program demonstrates the main operations of connecting, list tables, create a new table, print the contents, delete one row, and drop the table.
ojdbc troubleshooting
Now here is a list of problems I encountered while trying to get this to work.
No connection
| connection problem | |
|---|---|
Ok, this means it cannot understand XE in the connection string :
| failing connect string | |
|---|---|
So i changed it to a SID_NAME that was present, see the listener.ora file earlier in this page.
| change SID name | |
|---|---|
not a usable SID_NAME
Using PLSExtProc lead to the next error :
| error 2 | |
|---|---|
The PLSExtProc seems to be some other service ? TODO (find out what it does) but it does not handle any API functions, so the interwebz gave me a hint on this: add another name to the listener.ora file like this :
| add another listener name | |
|---|---|
And behold, this gave another error.
invalid username
| error 3 | |
|---|---|
This figures, on windows you have the apex interface and you are given the change to add a user. We could probably use the SYSTEM account with the password given at installation, but adding a user is a better solution. I did it with the sqldeveloper program, of course here you will have to login as SYSTEM when connecting, right click on the user table and create user. Be sure you put quotes around your password or it will fail to create. Or only use letters and numbers, quotes do not seems to be needed then.
connect string
| connect | |
|---|---|
Or :
On to the next error :
Insufficient rights
| rights | |
|---|---|
Were getting there, it could have been done in the dialog for create user. But if you do edit user, you can choose the privileges tab and grant all. Here is how that looks like in sql
Next,... no tables shown :
no output
Well the most obvious would be that there are no tables, so let's create one in the interface, one through java and one through C++. Note that if you login as 'kees' you are not listed in the "other users" list, which is logical, but nevertheless confusing to say the least. Why not just call it "users" oracle ? From sqldeveloper, choose 'tables' and that explains the empty list. So create one and remember the sql it spawns, and let's make a useful database as well.
That's a little cryptic but the main idea is readable. Also now our java program finally works :
| java output | |
|---|---|
Oracle JDBC
So on to programming java for Oracle, list table we have seen before. sauce
ojdbc create table
On to creating a table in java, but a lot simpler :
| ojdbc | |
|---|---|
Fit into the former OracleJDBC.java program, this also works. If you look into the SQL tab on sqldeveloper you will see what oracle adds for itself :
| sqldeveloper | |
|---|---|
That's more or less the same as the client table, so don't bother putting all that in.
inserting
Well if it's all just SQL sent over a JDBC link, we don't need to go into deleting tables etc, but what is interesting is how results are handled. I need some more data so let's fill that in first. I typed this one MySQL style and it worked in one go :
| insert | |
|---|---|
querying results
I filled in the rest in sqldeveloper as it faster. Now let's list the contents.
... pending..
Oracle and python
python Installation
| install | |
|---|---|
Easy enough ?. now see if you can run this script.
| usage | |
|---|---|
When run it should say something like
| output | |
|---|---|