新聞中心
這里有您想知道的互聯(lián)網(wǎng)營銷解決方案
oracle排列組合
Oracle數(shù)據(jù)庫中,排列組合可以使用
CONNECT BY子句實現(xiàn)。查詢部門表(departments)中所有可能的部門層次結(jié)構(gòu),可以使用以下SQL語句:,,“sql,SELECT department_id, parent_department_id,F(xiàn)ROM departments,START WITH parent_department_id IS NULL,CONNECT BY PRIOR department_id = parent_department_id;,“在Oracle中,我們可以使用遞歸的方式來生成全排列,以下是詳細的步驟:

玉環(huán)網(wǎng)站建設(shè)公司成都創(chuàng)新互聯(lián)公司,玉環(huán)網(wǎng)站設(shè)計制作,有大型網(wǎng)站制作公司豐富經(jīng)驗。已為玉環(huán)成百上千家提供企業(yè)網(wǎng)站建設(shè)服務(wù)。企業(yè)網(wǎng)站搭建\外貿(mào)營銷網(wǎng)站建設(shè)要多少錢,請找那個售后服務(wù)好的玉環(huán)做網(wǎng)站的公司定做!
1. 創(chuàng)建函數(shù)
我們需要創(chuàng)建一個函數(shù),該函數(shù)接受一個字符串作為輸入,并返回該字符串的所有可能的全排列。
CREATE OR REPLACE FUNCTION permutations (p_string IN VARCHAR2)
RETURN SYS.ODCINUMBERLIST PIPELINED IS
n INTEGER := LENGTH(p_string);
index INTEGER;
current_permutation VARCHAR2(32767);
BEGIN
FOR i IN 1..n LOOP
index := i;
current_permutation := p_string;
WHILE index > 0 LOOP
FOR j IN index+1..n LOOP
IF SUBSTR(current_permutation, j, 1) < SUBSTR(current_permutation, index, 1) THEN
Swap characters
:new.string := SUBSTR(current_permutation, 1, index1) || SUBSTR(current_permutation, j, 1) || SUBSTR(current_permutation, index+1) || SUBSTR(current_permutation, index, 1);
RETURN;
END IF;
END LOOP;
index := index 1;
END LOOP;
END LOOP;
RETURN;
END permutations;
/
2. 使用函數(shù)
我們可以使用這個函數(shù)來生成全排列,如果我們想要生成字符串’abc’的所有全排列,我們可以這樣做:
SELECT * FROM TABLE(permutations('abc'));
這將返回以下結(jié)果:
| COLUMN_VALUE |
| abc |
| acb |
| bac |
| bca |
| cab |
| cba |
這就是在Oracle中生成所有全排列的方法。
當前文章:oracle排列組合
當前網(wǎng)址:http://m.fisionsoft.com.cn/article/djoeceh.html


咨詢
建站咨詢
