
SQL
engchina
Get your hands dirty
展开
-
PLSQL Recursion Call
CREATE OR REPLACE FUNCTION FUNC1 ( N IN NUMBER) RETURN NUMBER/**************************************************************/-- 普通のループ処理で、1からNまでの足し込みを行うファンクション/*************************************翻译 2017-02-27 16:05:52 · 420 阅读 · 0 评论 -
PLSQL Table Collection Cursor Variable
SELECT * FROM TEST02; A B C---------- ---------- ----------1 EMP 79342 DEPT 10CREATE OR REPLACE PACKAGE PAC2IS/*******************************翻译 2017-02-23 15:42:26 · 586 阅读 · 0 评论 -
PLSQL Table Function NO_DATA_NEEDED
SELECT * FROM TABLE(pac1.f1(5)) WHERE ROWNUM <= 2; COL1 COL2---------- ---------- 1 ABC1 2 ABC2CREATE OR REPLACE PACKAGE BODY pac1IS/***********************************翻译 2017-02-23 14:48:07 · 427 阅读 · 0 评论 -
PLSQL Table Function
CREATE OR REPLACE PACKAGE pac1IS/**********************************************************//** レコード型の宣言 (テーブル・ファンクションの行の型) *//**********************************************************/ T翻译 2017-02-23 14:28:37 · 489 阅读 · 0 评论 -
PLSQL Update data via view (INSTEAD OF)
CREATE OR REPLACE VIEW V_GSALASSELECT D.DEPTNO, D.DNAME, SUM(E.SAL) AS GSALFROM EMP E, DEPT DWHERE E.DEPTNO = D.DEPTNOGROUP BY D.DEPTNO, D.DNAME/SELECT * FROM V_GSAL; DEPTNO DNAME翻译 2017-02-23 14:13:44 · 435 阅读 · 0 评论 -
PLSQL Update data via view
CREATE OR REPLACE VIEW V_TEST1ASSELECT EMPNO, ENAME, LOWER(ENAME) AS LOW_NAME FROM EMP;SELECT * FROM V_TEST1; EMPNO ENAME LOW_NAME---------- ---------- ---------- 7369 SMITH翻译 2017-02-23 13:42:09 · 695 阅读 · 0 评论 -
PLSQL Package 2
CREATE OR REPLACE PACKAGE PAC1IS -- PROCAプロシージャの仕様の宣言 PROCEDURE PROCA ( PA IN NUMBER);END;/CREATE OR REPLACE PACKAGE BODY PAC1IS -- 変数 V1の宣言 V1 NUMBER; -- PROCBプロシージャの完全な定義 PROCEDURE PROCB ( PB IN NUM翻译 2017-01-27 10:59:59 · 334 阅读 · 0 评论 -
PLSQL Package
CREATE PACKAGE PAC1IS PROCEDURE PROC1 ( P1 IN VARCHAR2);END;/CREATE PACKAGE BODY PAC1IS PROCEDURE PROC1 ( P1 IN VARCHAR2) ISBEGIN DBMS_OUTPUT.PUT_LINE(P1);END;END;SET SERVERO翻译 2017-01-27 10:55:42 · 659 阅读 · 0 评论 -
PLSQL Collection Sort
SET serveroutput ONSET verify OFFDECLAREtype a_typeIS TABLE OF VARCHAR2(10) INDEX BY binary_integer; a a_type; I binary_integer :=1;BEGIN a(5) := 'five'; a(-3) := 'minus 3'; a(0) :=翻译 2017-01-26 15:01:11 · 594 阅读 · 0 评论 -
PLSQL Collection
SET serveroutput ONSET verify OFFDECLAREtype a_typeIS TABLE OF VARCHAR2(10) INDEX BY binary_integer; a a_type;BEGIN a(10) := 'ABC'; a(20) := 'DEF'; a(30) := 'GHI'; dbms_output.put_lin翻译 2017-01-26 14:49:50 · 706 阅读 · 0 评论 -
PLSQL Cursor ROWTYPE TYPE
SET serveroutput ONSET verify OFFDECLARE rec2 emp%rowtype;BEGIN SELECT * INTO rec2 FROM EMP WHERE employee_id = 100; dbms_output.put_line(REC2.employee_id || ' ' || REC2.first_name );END;/翻译 2017-01-26 14:23:09 · 898 阅读 · 0 评论 -
PLSQL Cursor For Loop handle header and detail
SET serveroutput ONSET verify OFFBEGIN FOR rec1 IN (SELECT * FROM DEPT ) LOOP DBMS_OUTPUT.PUT_LINE(CHR(10) || '### 部門名 : ' || REC1.department_name || ' ####'); -- CHR(10)换行 FOR rec2翻译 2017-01-26 14:14:33 · 333 阅读 · 0 评论 -
PLSQL Cursor For Loop
定义CursorSET serveroutput ONSET verify OFFDECLARE CURSOR cur_emp IS SELECT employee_id, upper(first_name) upname, salary*12 annsal FROM emp WHERE department_id = &翻译 2017-01-26 14:07:59 · 958 阅读 · 0 评论 -
PLSQL 明示Cursor 2
SET serveroutput ONSET verify OFFDECLARE CURSOR cur_emp IS SELECT employee_id, upper(first_name) upname, salary*12 annsal FROM emp WHERE department_id = &deptno;翻译 2017-01-26 13:59:16 · 378 阅读 · 0 评论 -
PLSQL 明示Cursor
SET serveroutput ONSET verify OFFDECLARE CURSOR cur_emp IS SELECT employee_id, first_name FROM emp WHERE department_id = &deptno; rec cur_emp%rowtype;BEGIN OPEN cur_翻译 2017-01-26 13:54:08 · 359 阅读 · 0 评论 -
PLSQL 异常处理
SET serveroutput ONSET verify ONDECLARE v_empno emp.employee_id%type := &emp_no; v_ename emp.first_name%type; v_deptno dept.department_id%type; v_dname dept.department_name%type;BEGIN SEL翻译 2017-01-26 13:46:51 · 496 阅读 · 0 评论 -
PLSQL Temporary Table
CREATE GLOBAL TEMPORARY TABLE TEMP01( A NUMBER PRIMARY KEY, B VARCHAR2(10))/翻译 2017-02-23 16:05:25 · 680 阅读 · 0 评论 -
PLSQL Package 3
CREATE OR REPLACE PACKAGE PAC1IS /* 同じ名前のプロシージャ3つ ただしパラメータの型や数が違う*/ PROCEDURE PROC1( P1 IN NUMBER); PROCEDURE PROC1( P1 IN VARCHAR2); PROCEDURE PROC1( P1 IN VARCHAR2,翻译 2017-02-01 13:00:26 · 472 阅读 · 0 评论 -
PLSQL 变数的永续性
CREATE OR REPLACE PACKAGE PAC1IS A NUMBER;END;/show err;/BEGIN PAC1.A := 10;END;/show err;/BEGIN DBMS_OUTPUT.PUT_LINE(PAC1.A);END;/show err;/outputPackage PAC1がコンパイルされましたエラー翻译 2017-02-01 13:10:20 · 358 阅读 · 0 评论 -
PLSQL Tools for query primary key and foreign key of a table
SET VERIFY OFFSET SERVEROUTPUT ONDECLARE V_TABLE_NAME VARCHAR2(100); -- 表名 V_PK_NAME VARCHAR2(100); -- 主キー制約の名前 V_COLUMNS VARCHAR2(3000); -- 列名の取得(列1,列2,・・)BEGIN -- 表名の取得(キーボードから入力)翻译 2017-02-03 16:33:16 · 425 阅读 · 0 评论 -
PLSQL UTL_FILE input from file
SET serveroutput ONDECLARE fh utl_file.file_type; v_line VARCHAR2(32767);BEGIN fh := utl_file.fopen('DATA_PUMP_DIR','test.txt','R'); LOOP utl_file.get_line(fh,v_line); dbms_output.pu翻译 2017-02-03 16:27:31 · 457 阅读 · 0 评论 -
PLSQL UTL_FILE output file
DECLARE fh utl_file.file_type;BEGIN fh := utl_file.fopen('DATA_PUMP_DIR','test.txt','W'); utl_file.put_line(fh,'hello'); utl_file.put_line(fh,'how are you'); utl_file.fclose(fh);END;/翻译 2017-02-03 13:35:12 · 619 阅读 · 0 评论 -
PLSQL Dynamic SQL Using Bind Variat
CREATE OR REPLACE PROCEDURE get_name( p_id IN NUMBER, p_name OUT VARCHAR2)IS v_name emp.first_name%type;BEGIN EXECUTE immediate 'select first_name from emp where employee_id = :EMPID'翻译 2017-02-03 13:14:16 · 470 阅读 · 0 评论 -
PLSQL Dynamic SQL Multiple Results
DECLAREtype cur_emp_typeIS ref CURSOR; cur_emp cur_emp_type; rec emp%rowtype; BEGIN OPEN cur_emp FOR 'select * from emp where department_id = 20'; LOOP FETCH cur_翻译 2017-02-03 13:01:44 · 449 阅读 · 0 评论 -
PLSQL Dynamic SQL one row result
DECLARE V_ENAME EMP.FIRST_NAME%TYPE;BEGIN EXECUTE IMMEDIATE 'SELECT FIRST_NAME FROM EMP WHERE EMPLOYEE_ID = 200' INTO V_ENAME; DBMS_OUTPUT.PUT_LINE('取得した社員名 = ' || V_ENAME);END;/PL/SQLプロ翻译 2017-02-03 12:32:51 · 345 阅读 · 0 评论 -
PLSQL Trigger Dynamic SQL
select * from dept;SET serveroutput ONDECLARE v1 VARCHAR2(10) := 'DEPT'; v2 VARCHAR2(10) := '99'; v3 VARCHAR2(10) :='TEST'; v_stmt VARCHAR2(100);BEGIN v_stmt :='INSERT INTO '翻译 2017-02-03 12:26:09 · 334 阅读 · 0 评论 -
PLSQL Trigger Update Another Table
ALTER TABLE DEPARTMENTS ADD ( GSAL NUMBER);DESC DEPT;UPDATE DEPTSET GSAL = ( SELECT SUM(SALARY) FROM EMP WHERE DEPARTMENT_ID = DEPT.DEPARTMENT_ID );SELECT翻译 2017-02-03 12:09:59 · 414 阅读 · 0 评论 -
PLSQL Trigger BEFORE :NEW.列名 设置值
CREATE TABLE TEST02 ( A NUMBER, 登録日 DATE, 最終更新日 DATE ) ; /CREATE OR REPLACE TRIGGER TEST02_TRIG before INSERT OR UPDATE ON test02 FOR EACH row BEGIN IF inserting THEN :NEW.登録日 := SYSDATE;翻译 2017-02-02 14:59:28 · 1209 阅读 · 0 评论 -
PLSQL Trigger :OLD :NEW
CREATE TABLE TEST01 (ID NUMBER, NAME VARCHAR2(10) );CREATE TABLE AUDIT_TEST01 ( USERNAME VARCHAR2(10), OP_TIME VARCHAR2(30), OLD_ID NUMBER, NEW_ID NUMBER, OLD_NAME VARC翻译 2017-02-02 12:53:32 · 1323 阅读 · 0 评论 -
PLSQL Trigger FOR EACH ROW
CREATE OR REPLACE TRIGGER 注文_在庫_TRIG AFTER INSERT ON 注文 FOR EACH ROW BEGIN UPDATE 在庫 SET 在庫数 = 在庫数 - :NEW.注文数 WHERE 製品名 = :NEW.製品名;END;DECLARE V_注文ID 注文.注文ID%TYPE;BEGIN PROC_順序番号('注文ID',V_翻译 2017-02-02 12:25:24 · 681 阅读 · 0 评论 -
PLSQL Trigger
CREATE OR REPLACE TRIGGER TRIG_EMP_CHECK1 BEFORE INSERT OR DELETE OR UPDATE ON EMP DECLARE V_DATE VARCHAR2(5); BEGIN V_DATE := TO_CHAR(SYSDATE,'HH24:MI'); IF V_DATE BETWEEN '08:00' AND '15:00' THEN NU翻译 2017-02-01 14:10:52 · 412 阅读 · 0 评论 -
PLSQL Package Initialize Block
CREATE OR REPLACE PACKAGE PAC1IS -- 最初にこのパッケージをコールした日時 --を格納する変数 FirstCall DATE;END;/show err;/CREATE OR REPLACE PACKAGE BODY PAC1IS -- IS の下は宣言部だがここでは宣言するものなし -- 以下のBEGINから実行部(初期化ブロッ翻译 2017-02-01 13:59:35 · 431 阅读 · 0 评论 -
PLSQL Procedure Customized Exception
set serveroutput onset verify onCREATE OR REPLACE PACKAGE PAC1IS FK_ERROR EXCEPTION; PRAGMA EXCEPTION_INIT(FK_ERROR,-2292); -- ORA-2292 外部Key制约END;/show err;/DECLARE V_DEPTNO NUMBER :=翻译 2017-02-01 13:24:24 · 381 阅读 · 0 评论 -
PLSQL 定数宣言
set serveroutput onCREATE OR REPLACE PACKAGE PAC1IS RITU CONSTANT NUMBER := 5; --PAC1パッケージに定数RITUを宣言END;/show err;/CREATE OR REPLACE FUNCTION FUNC_税額( P_KINGAKU IN NUMBER )RETURN NUMBERIS翻译 2017-02-01 13:15:20 · 446 阅读 · 0 评论 -
PLSQL Function
CREATE OR REPLACE FUNCTION FUNC_順序番号 --←キーワードはFUNCTION ( P_発番単位 IN VARCHAR2) --←仮パラメータのモードは INだけ RETURN NUMBER --←RETURNするデータ型を宣言するIS V_発番済番号 順序.番号%TYPE; V_番号 NUMBER;BEGIN -- 指翻译 2017-01-26 16:57:37 · 1325 阅读 · 0 评论 -
PLSQL Collection Check Existence
SET serveroutput ONSET verify OFFDECLAREtype a_typeIS TABLE OF VARCHAR2(10) INDEX BY binary_integer; a a_type;BEGIN a(5) := 'five'; a(-3) := 'minus 3'; a(0) := 'zero'; a(7) := 'sev翻译 2017-01-26 15:06:06 · 436 阅读 · 0 评论 -
PLSQL Procedure
CREATE OR REPLACE PROCEDURE proc_tax( p1 IN NUMBER, p2 OUT NUMBER)ISBEGIN p2 := p1*1.17;END;/SET serveroutput ONDECLARE v_input NUMBER(5); v_output NUMBER(5);BEGIN v_input :=1翻译 2017-01-26 15:10:16 · 561 阅读 · 0 评论 -
PLSQL Trigger will execute even when there is a Foreign Key Constraint Error
CREATE TABLE OYA ( ID NUMBER CONSTRAINT OYA_PK PRIMARY KEY, C1 VARCHAR2(10)) /CREATE TABLE KO ( ID NUMBER CONSTRAINT KO_PK PRIMARY KEY, C1 VARCHAR2(10), OYA_ID NUMBER CONSTRAI翻译 2017-02-21 14:41:29 · 481 阅读 · 0 评论 -
PLSQL Find Non-Number Data
SELECT * FROM TEST86; COL1----------123a123123b1c23方法1SELECT * FROM TEST86 WHERE REGEXP_LIKE(COL1,'[^0-9]'); COL1----------a123123b1c23方法2SET SERVEROUTPUT ONDECLARE V_DUMMY翻译 2017-02-28 14:26:33 · 777 阅读 · 0 评论 -
PLSQL Source Code Obfuscation
CREATE OR REPLACE PROCEDURE PROC85ISBEGIN DBMS_OUTPUT.PUT_LINE('こんにちは。今日は寒いですね');END;/SQL> show userユーザーは"SCOTT"です。SQL> @input.sqlwrap iname=input.sql oname=output.plbCREATE OR REP翻译 2017-02-28 14:20:08 · 767 阅读 · 0 评论