Oracle
 sql >> डेटाबेस >  >> RDS >> Oracle

संग्रहीत कार्यविधि निष्पादित करते समय नोड-ओरेक्लेडब त्रुटि NJS-012

अपडेट 2019/08/28:

Node-oracledb ने v4 में SQL ऑब्जेक्ट प्रकारों और PL/SQL रिकॉर्ड प्रकारों के लिए समर्थन जोड़ा (रिलीज़ 2019/07/25)। विवरण के लिए दस्तावेज़ का यह भाग देखें:https://oracle. github.io/node-oracledb/doc/api.html#objects

पहले सूचीबद्ध समान वस्तुओं को देखते हुए, निम्नलिखित जावास्क्रिप्ट का उपयोग अब पहले की तुलना में कोड की बहुत कम पंक्तियों के साथ काम करने के लिए किया जा सकता है:

const oracledb = require('oracledb');
const config = require('./db-config.js');

async function runTest() {
  let conn;

  try {  
    const sql = 
     `call xxeta_grid_user_context_pkg.extract_grid_details(
        p_user_name      => :P_USER_NAME,
        p_content_type   => :P_CONTENT_TYPE,
        p_project_number => :P_PROJECT_NUMBER,
        op_grid_tab_typ  => :OP_GRID_TAB_TYP
      )`;

    const binds = {
      P_USER_NAME: 'Jane Doe',
      P_CONTENT_TYPE: 'Some Content Type',
      P_PROJECT_NUMBER: '123',
      OP_GRID_TAB_TYP: {
        dir: oracledb.BIND_OUT,
        type: 'HR.XXETA_GRID_CONTEXT_TAB_TYP'
      } 
    }

    conn = await oracledb.getConnection(config);

    const result = await conn.execute(
      sql,
      binds
    );

    const gridContexts = [];

    for (let x = 0; x < result.outBinds.OP_GRID_TAB_TYP.length; x += 1) {
      gridContexts.push({
        gridViewId: result.outBinds.OP_GRID_TAB_TYP[x].GRID_VIEW_ID,
        gridViewName: result.outBinds.OP_GRID_TAB_TYP[x].GRID_VIEW_NAME,
        userName: result.outBinds.OP_GRID_TAB_TYP[x].USER_NAME,
        projectNumber: result.outBinds.OP_GRID_TAB_TYP[x].PROJECT_NUMBER
      });
    }

    console.log(gridContexts);
  } catch (err) {
    console.error(err);
  } finally {
    if (conn) {
      try {
        await conn.close();
      } catch (err) {
        console.error(err);
      }
    }
  }
}

runTest();

पिछला उत्तर:

जटिल प्रकार वर्तमान में समर्थित नहीं हैं। आपके द्वारा निर्दिष्ट आउट बाइंड इस श्रेणी में आता है। जब तक ऐसे प्रकार सीधे समर्थित नहीं होते हैं, तब तक आपको जटिल प्रकार को एक या अधिक सरल प्रकारों में विभाजित करने के लिए थोड़ा सा रैपर कोड जोड़ना होगा। मैं इसका एक उदाहरण यहां दिखाता हूं: https://jsao.io/2017/01/plsql-record-types-and-the-node-js-driver/

उस पोस्ट में लक्ष्य एक संग्रहीत कार्यविधि को लागू करना है जो एक कस्टम रिकॉर्ड प्रकार की एक सरणी को स्वीकार करता है। इसे लागू करने के लिए, मुझे पहले कुछ सरल सरणी प्रकारों को बाइंड करने की घोषणा करनी होगी। फिर मैं उन सरणियों का उपयोग अधिक जटिल सरणी बनाने और प्रक्रिया को लागू करने के लिए कर सकता हूं।

आपके मामले में, आपको उल्टा करना होगा। PL/SQL ब्लॉक में, APPS.XXETA_GRID_CONTEXT_TAB_TYP प्रकार का स्थानीय चर घोषित करें। फिर, प्रक्रिया लागू होने के बाद, सरणी पर पुनरावृति करें और कुछ सरल सरणियों (VARCHAR2, NUMBER, या DATE) को पॉप्युलेट करने के लिए इसका उपयोग करें और उन्हें अपने आउट बाइंड के रूप में उपयोग करें।

अपडेट करें:

बशर्ते आपके पास निम्नलिखित वस्तुएं हों:

create or replace type xxeta_grid_context_rec_typ as object (
  grid_view_id   number(15),
  grid_view_name varchar2(240),
  user_name      varchar2(30),
  project_number varchar2(5)
)
/

create or replace type xxeta_grid_context_tab_typ as table of xxeta_grid_context_rec_typ
/

create or replace package xxeta_grid_user_context_pkg
as

procedure extract_grid_details(
  p_user_name      in varchar2,
  p_content_type   in varchar2,
  p_project_number in varchar2,
  op_grid_tab_typ  out xxeta_grid_context_tab_typ
);

end;
/

create or replace package body xxeta_grid_user_context_pkg
as

procedure extract_grid_details(
  p_user_name      in varchar2,
  p_content_type   in varchar2,
  p_project_number in varchar2,
  op_grid_tab_typ  out xxeta_grid_context_tab_typ
)

is

  l_xxeta_grid_context_rec xxeta_grid_context_rec_typ;

begin

  op_grid_tab_typ := xxeta_grid_context_tab_typ();

  for x in 1 .. 3
  loop
    l_xxeta_grid_context_rec := xxeta_grid_context_rec_typ(
      grid_view_id   => x,
      grid_view_name => 'Some Grid View',
      user_name      => p_user_name,
      project_number => p_project_number
    );

    op_grid_tab_typ.extend();

    op_grid_tab_typ(x) := l_xxeta_grid_context_rec;
  end loop;

end;

end;
/

निम्नलिखित Node.js कोड संग्रहीत कार्यविधि को लागू कर सकता है और जटिल आउट पैरामीटर से मान प्राप्त कर सकता है।

const oracledb = require('oracledb');
const config = require('./dbConfig.js');

async function runTest() {
  let conn;

  try {
    const userName = 'Jane Doe';
    const contentType = 'Some Content Type';
    const projectNumber = '123';

    // This is what we want to populate with records/objects that come out
    // of the procedure.
    const gridContexts = [];

    // We start by declaring some other arrays, one for each field in the
    // xxeta_grid_context_rec_typ type.
    const gridViewIds = [];
    const gridViewNames = [];
    const userNames = [];
    const projectNumbers = []; 

    conn = await oracledb.getConnection(config);

    // Then we execute the procedure with a little wrapper code to populate
    // the individual arrays.
    let result = await conn.execute(
     `declare

        -- This is a local variable that you'll use to get the out data from
        -- the procedure.
        l_xxeta_grid_context_tab xxeta_grid_context_tab_typ;

      begin

        xxeta_grid_user_context_pkg.extract_grid_details(
          p_user_name      => :user_name,
          p_content_type   => :content_type,
          p_project_number => :project_number,
          op_grid_tab_typ  => l_xxeta_grid_context_tab
        );

        -- Now that the local variable is populated, iterate over it to
        -- populate the individual out binds.
        for x in 1 .. l_xxeta_grid_context_tab.count
        loop
          :grid_view_ids(x) := l_xxeta_grid_context_tab(x).grid_view_id;
          :grid_view_names(x) := l_xxeta_grid_context_tab(x).grid_view_name;
          :user_names(x) := l_xxeta_grid_context_tab(x).user_name;
          :project_numbers(x) := l_xxeta_grid_context_tab(x).project_number;
        end loop;

      end;`,
      {
        user_name: userName,
        content_type: contentType,
        project_number: projectNumber,
        grid_view_ids: {
          dir: oracledb.BIND_OUT,
          type: oracledb.NUMBER,
          maxArraySize: 200
        },
        grid_view_names: {
          dir: oracledb.BIND_OUT,
          type: oracledb.STRING,
          maxArraySize: 200
        },
        user_names: {
          dir: oracledb.BIND_OUT,
          type: oracledb.STRING,
          maxArraySize: 200
        },
        project_numbers: {
          dir: oracledb.BIND_OUT,
          type: oracledb.STRING,
          maxArraySize: 200
        }
      }
    );

    // At this point you can access the individual arrays to populate the 
    // original target array with objects. This is optional, you can work
    // with the individual arrays directly as well.
    for (let x = 0; x < result.outBinds.grid_view_ids.length; x += 1) {
      gridContexts.push({
        gridViewId: result.outBinds.grid_view_ids[x],
        gridViewName: result.outBinds.grid_view_names[x],
        userName: result.outBinds.user_names[x],
        projectNumber: result.outBinds.project_numbers[x]
      });
    }

    console.log(gridContexts);
  } catch (err) {
    console.error(err);
  } finally {
    if (conn) {
      try {
        await conn.close();
      } catch (err) {
        console.error(err);
      }
    }
  }
}

runTest();

मुझे आशा है कि वह मदद करेंगे! जटिल प्रकारों के लिए प्रत्यक्ष समर्थन संवर्द्धन की सूची में है, बस यह नहीं कह सकता कि यह कब उतरेगा।




  1. Database
  2.   
  3. Mysql
  4.   
  5. Oracle
  6.   
  7. Sqlserver
  8.   
  9. PostgreSQL
  10.   
  11. Access
  12.   
  13. SQLite
  14.   
  15. MariaDB
  1. मानों के एक ही ब्लॉक से संबंधित मानों को अलग किए बिना कई अद्वितीय मान प्राप्त करें

  2. ओरेकल फॉर्म से माइक्रोसॉफ्ट वर्ड स्पेल चेक को लागू करते समय विस्टा फोकस मुद्दा

  3. पर्ल का उपयोग करके Oracle में कई बार क्वेरी करना केवल पहली क्वेरी देता है

  4. Oracle sql MERGE INTO एक सिंगल जहाँ क्लॉज के साथ

  5. Oracle SQL डेवलपर में संग्रहीत कार्यविधि को कैसे संपादित करें?