如何将varchar2转换为PL / SQL

时间:2017-08-19 12:40:03

标签: sql oracle plsql

我有一个bash脚本,我想在SqlPlus中进行这样的查询

CREATE TABLE tab1(digits VARCHAR2(100));

INSERT INTO tab1(digits) VALUES (5,6);
COMMIT;


#!/bin/bash
.
.
DECLARE
lv_digits VARCHAR2(100):='';
BEGIN
SELECT digits INTO digits FROM tab1;
FOR i IN (SELECT column1 FROM tab2 WHERE column_id IN (lv_digits) AS text);
LOOP
DBMS_OUTPUT.PUT_LINE(i.text);
END LOOP;
END;
/ 

我不知道如何在WHERE中正确输入条件以返回值

如何手动介绍WHERE column_id IN (5,6) AS text它是否正常工作,并且必须从另一个表中加载值为VARCHAR2的表加载值。

DECLARE
lv_digits VARCHAR2(100):='';
BEGIN
SELECT digits INTO digits FROM tab1;
FOR i IN (SELECT column1 FROM tab2 WHERE column_id IN (5,6) AS text);
LOOP
DBMS_OUTPUT.PUT_LINE(i.text);
END LOOP;
END;
/ 

有没有人知道如何转换它?

1 个答案:

答案 0 :(得分:0)

这对某人有用

DECLARE
lv_digits VARCHAR2(100):='';
BEGIN
SELECT digits INTO digits FROM tab1;
FOR i IN (SELECT column1 FROM tab2 WHERE column_id IN (select regexp_substr(digits,'[^,]+', 1, level) from karuzela_loop 
connect by regexp_substr(digits, '[^,]+', 1, level) is not NULL) AS text);
LOOP
DBMS_OUTPUT.PUT_LINE(i.text);
END LOOP;
END;
/ 

@mathguy感谢您的提示