If writing a C program seems too long-winded. The above could also be achieved with a shell script. To run it from any of the web servers, the some environment variables need to be set first before using sqlplus in silent mode.
echo Content-type: text/html
# Set up the TWO_TASK environment variables so that the web server can "find" Oracle
# Speak to your local database administrator to find out the current settings
# Now output the standard HTML tags
# reformat the table output using CSS stylesheet, otherwise Oracle output very plain
echo "<link rel=StyleSheet href=\"Oracle.css\" type=\"text/css\">"
echo "<h1>Accessing Oracle from a Shell Script</h1>"
echo "<h2>List of Departments and Employees</h2>"
# sqlplus is invoked in silent mode to list the current departments
sqlplus -s yourOracleUsername/yourOraclePassword <<!
SET MARKUP HTML ON!
SET FEEDBACK OFF
SELECT deptno, dname
ORDER BY deptno;
SELECT * FROM Emp;
# Finally provide the closing tags
The above can be run:
Note, currently students can not run cgi scripts
against the mi-linux webserver.
If you want to try these out, you would need to try these against a different webserver (e.g., a home webserver).