Example of a PrologSQL use.


  1. Import two tables from a database.
  2. Create a nondeterministic query predicate as an join between two tables.
  3. Call the query predicate.

:- use_module(oracle).

go :-
	db_open('Your Database Name', 'scott', 'tiger'),
	db_import('DEPT'('DEPTNO', 'DNAME', 'LOC'), dept),
	db_import('EMP'('EMPNO', 'ENAME', 'JOB', 'MGR', 'HIREDATE', 'SAL', 'COMM', 'DEPTNO'), emp),
	%% Uncomment it, if you do not want to see SQL statements.
	%% db_flag(show_query, _, off),
	db_query(empinfo(EMPNO, ENAME, JOB, MGR, HIREDATE, SAL, COMM, DEPTNO, DNAME, LOC),
		(	emp(EMPNO, ENAME, JOB, MGR, HIREDATE, SAL, COMM, DEPTNO),
			dept(DEPTNO, DNAME, LOC)
		)
	),
	get_result,
	db_close.

get_result:-
	empinfo(EMPNO, ENAME, JOB, MGR, HIREDATE, SAL, COMM, DEPTNO, DNAME, LOC),
	write_ln([EMPNO, ENAME, JOB, MGR, HIREDATE, SAL, COMM, DEPTNO, DNAME, LOC]),
	fail.
get_result.

My Home Page