vue的路由對映問題及解決方案
阿新 • • 發佈:2020-11-19
--1.建立模擬資料
DROP TABLE test; CREATE TABLE test(id int, info text); INSERT INTO test SELECT generate_series(1, 10), 'test';
--2.建立儲存過程
CREATE OR REPLACE FUNCTION test_1() RETURNS refcursor AS $BODY$ DECLARE CURSOR c1 FOR SELECT * FROM test; BEGIN OPEN c1; RETURN c1; END $BODY$ LANGUAGE plsql;
--3.在命令列中可以查詢:
TEST=# BEGIN; BEGIN TEST=# SELECT test_1(); TEST_1 -------- C1 (1 row) TEST=# FETCH 5 IN "C1"; ID | INFO ----+------ 1 | test 2 | test 3 | test 4 | test 5 | test (5 rows) TEST=# END; COMMIT
--4.管理工具需要在匿名塊中執行:
DO $$ DECLARE ret_ref refcursor; one_row record; BEGIN OPEN ret_ref FOR SELECT 1 ; ret_ref := test_1(); FETCH ret_ref INTO one_row; WHILE ret_ref%FOUND LOOP raise notice 'id is: %, text is: %', one_row.id, one_row.info; FETCH NEXT IN ret_ref INTO one_row; END LOOP; CLOSE ret_ref; END $$
結果:
00000: id is: 1, text is: test 00000: id is: 2, text is: test 00000: id is: 3, text is: test 00000: id is: 4, text is: test 00000: id is: 5, text is: test 00000: id is: 6, text is: test 00000: id is: 7, text is: test 00000: id is: 8, text is: test 00000: id is: 9, text is: test 00000: id is: 10, text is: test
--注意:如果在儲存過程中,已經消費了,則返回的遊標需要重新定位到開始
--5.處理out引數的遊標,一樣的:
CREATE OR REPLACE FUNCTION test_2(v_id int, c1 OUT refcursor) RETURNS refcursor AS $BODY$ DECLARE BEGIN OPEN c1 FOR SELECT * FROM test WHERE id < v_id; END $BODY$ LANGUAGE plsql; DO $$ DECLARE ret_ref refcursor; one_row record; BEGIN OPEN ret_ref FOR SELECT 1 ; ret_ref := test_2(6); FETCH ret_ref INTO one_row; WHILE ret_ref%FOUND LOOP raise notice 'id is: %, text is: %', one_row.id, one_row.info; FETCH NEXT IN ret_ref INTO one_row; END LOOP; CLOSE ret_ref; END $$
結果:
00000: id is: 1, text is: test 00000: id is: 2, text is: test 00000: id is: 3, text is: test 00000: id is: 4, text is: test 00000: id is: 5, text is: test