如何从Lisp运行Oracle plsql过程?

时间:2008-09-15 20:20:19

标签: oracle stored-procedures plsql lisp clojure

我如何开始?

3 个答案:

答案 0 :(得分:4)

我找到了使用Clojure实现这一目标的最简单方法。 这是示例代码:


(ns example
  (:require [clojure.contrib.sql :as sql])
  (:import  [java.sql Types]))

(def devdb {:classname "oracle.jdbc.driver.OracleDriver" :subprotocol "oracle" :subname "thin:username/password@localhost:1509:devdb" :create true})

(defn exec-ora-stored-proc [input-param db callback] (sql/with-connection db (with-open [stmt (.prepareCall (sql/connection) "{call some_schema.some_package.test_proc(?, ?, ?)}")] (doto stmt (.setInt 1 input-param) (.registerOutParameter 2 Types/INTEGER) (.registerOutParameter 3 oracle.jdbc.driver.OracleTypes/CURSOR) (.execute)) (callback (. stmt getInt 2) (. stmt getObject 3)))))

(exec-ora-stored-proc 123 ;;input param value devdb (fn [err-code res-cursor] (println (str "ret_code: " err-code)) ;; prints returned refcursor rows (let [resultset (resultset-seq res-cursor)] (doseq [rec resultset] (println rec)))))

答案 1 :(得分:1)

您需要一个Oracle SQL数据库的接口。正如鲍勃指出的那样,Allegro CL有这样的界面。

GNU CLISP apparently comes with an interface to the database as well.

答案 2 :(得分:1)

从Common Lisp程序中执行Oracle操作的最直接方法是使用CLSQL。还有很多其他软件包用于处理来自Common Lisp的数据库。看看Cliki's database page