顯示具有 oracle 標籤的文章。 顯示所有文章
顯示具有 oracle 標籤的文章。 顯示所有文章

2023年10月15日 星期日

SimpleJdbcCall with Oralce Data Type Struct、Array

 

SimpleJdbcCall with Oralce Data Type Struct、Array

Java spring Jdbc Template 可以直接傳 StroreProcedure type arral 啦!!!

不要只會傻傻的傳 Number、Varchar啦。

https://docs.spring.io/spring-data/jdbc/old-docs/1.0.0.RELEASE/reference/html/orcl.datatypes.html


https://copyprogramming.com/howto/how-to-create-a-table-in-18c-express-edition#google_vignette


问如何从Java调用具有自定义复杂对象类型作为输入参数的Oracle PL-SQL过程

https://cloud.tencent.com/developer/ask/sof/110651663

SqlStructArrayValue :将对象列表传递给Oracle存储过程中的结构数组

https://cloud.tencent.com/developer/ask/sof/110651663


JAVA DOC
https://docs.spring.io/spring-data/jdbc/old-docs/2.0.0.M1/api/org/springframework/data/jdbc/support/oracle/package-frame.html

2022年10月27日 星期四

Java Stored Procedures Application Example

  Java Stored Procedures Application Example

call Procedures doJAVA

https://docs.oracle.com/database/121/JJDEV/cheight.htm#JJDEV13295

2022年10月26日 星期三

Oracle JAVA ConnectionUrl

 Oracle JAVA ConnectionUrl 



Oracle JAVA ConnectionUrl 
#SID
jdbc:oracle:thin:@127.0.0.1:1521:MyDb
#tnsnames.ora
jdbc:oracle:thin:@(DESCRIPTION=(ADDRESS=(PROTOCOL=TCPS)(HOST=127.0.0.1)(PORT=1521))(CONNECT_DATA=(SERVER=DEDICATED)(SERVICE_NAME=MyDb)))
jdbc:oracle:thin:@(DESCRIPTION=(ADDRESS=(PROTOCOL=TCPS)(HOST=127.0.0.1)(PORT=1522))(CONNECT_DATA=(SERVER=DEDICATED)(SERVICE_NAME=MyDb)))

2022年10月5日 星期三

Tomcat JNDI Oracle 19c with TLS v1.2

 


Tomcat JNDI Oracle 19c with TLS v1.2

SSL Connection to Oracle DB using JDBC, TLSv1.2, JKS or Oracle Wallets (12.2 and lower)

https://blogs.oracle.com/developers/post/ssl-connection-to-oracle-db-using-jdbc-tlsv12-jks-or-oracle-wallets-122-and-lower#Wallets

https://www.796t.com/p/316899.html

https://www.ibm.com/docs/en/tnpm/1.4.2?topic=security-import-certificate-jre-keystore

需要 jdk/jre/lib/secrity/cacerts 

tomcat 啟動參數


-Doracle.net.wallet_location=D:\app\oracle\wallet
-Doracle.net.ssl.clipher_suites="(TLS_RSA_WITH_AES_256_CBC_SHA256)"
-Djavax.net.debug=all

context.xml 連線設定


<Resource auth="Container" name="jdbc/myDS"
type="javax.sql.DataSource"
driverClassName="oracle.jdbc.driver.OracleDriver" 
username="MyUserName"
password="MyPassWord" 
maxIdle="2" 
maxWaitMillis="5000"
url="jdbc:oracle:thin:@192.168.0.100:1521:MYDB" 

maxTotal="4" />

<Resource auth="Container" name="jdbc/myDS"
type="javax.sql.DataSource"
driverClassName="oracle.jdbc.driver.OracleDriver" 
username="MyUserName"
password="MyPassWord" 
maxIdle="1" maxWaitMillis="5000"
url="jdbc:oracle:thin:@(DESCRIPTION=    (ADDRESS=(PROTOCOL=TCPS)(HOST=192.168.0.100)(PORT=1522))    (CONNECT_DATA=      (SERVER = DEDICATED)      (SERVICE_NAME=MYDB)    )  )" 
maxTotal="1" />

2022年4月19日 星期二

Oracle Alternative Quoting Mechanism (''Q'') for String Literals

 

Oracle Alternative Quoting Mechanism (''Q'') for String Literals

https://livesql.oracle.com/apex/livesql/file/content_CIREYU9EA54EOKQ7LAMZKRF6P.html


Oracle Database offers the ability, in both SQL and PL/SQL, to specify our own user-defined delimiters for string literals. Here's how it works: you prefix your literal with the letter "q". Then you type a single quote, followeed by your starting delimiter for the literal. Then you type your literal string without having to double up on your single quote characters. When you have typed in your full literal, terminate it with your ending delimiter, followed by a single quote. In other words, you will follow this general format: q'[your string here]' where "[" represents (and certainly could be used for) the starting delimiter, and "]" represents the ending delimiter. Oracle automatically recognizes "paired" delimiters, such as [], {}, (), and <>. If you want to use some other character as your start delimiter and it doesn't have a "natural" partner for termination, you must use the same character for start and end delimiters. Finally, if you choose a character for a delimiter and it appears in your string immediately before a single quotation mark, Oracle will be unhappy and raise an error.


Oracle 數據庫在 SQL 和 PL/SQL 中都提供了為字符串文字指定我們自己的用戶定義分隔符的能力。它是這樣工作的:你在你的文字前加上字母“q”。然後鍵入一個單引號,然後是文字的起始分隔符。然後你輸入你的文字字符串,而不必在你的單引號字符上加倍。當你輸入完整的文字後,用你的結束分隔符終止它,然後是一個單引號。換句話說,您將遵循以下通用格式: q'[your string here]' 其中“[”表示(當然可以用於)起始分隔符,“]”表示結束分隔符。 Oracle 自動識別“成對的”分隔符,例如 []、{}、() 和 <>。如果您想使用其他字符作為起始分隔符並且它沒有“自然”夥伴來終止,則您必須對起始和結束分隔符使用相同的字符。最後,如果您選擇一個字符作為分隔符並且它出現在您的字符串中的單引號之前,Oracle 將不高興並引發錯誤。


翻譯

使用 q'! !' 不需要用 '' 替代 '

2022年1月21日 星期五

Oracle sql 抓取 result set 後的指定筆數

 Oracle sql 抓取 result set 後的指定筆數


select *
from mytable
--第一筆不要
offset 1 rows
--只要三筆
fetch next 3 rows only


參考

Oracle PL/SQL: 取得排序後的第 n ~ m 筆資料

https://tomkuo139.blogspot.com/2009/06/plsql-n-m.html

2022年1月9日 星期日

Oralce Add Weeks 計算疫苗第二劑 + 12 週 第三劑疫苗施打日期計算

Oralce Add Weeks 計算疫苗第二劑 + 12 週 第三劑疫苗施打日期計算


set SERVEROUTPUT ON
declare
shot2 VARCHAR2(8) := '20211020'; --第二劑日期
shot2date date;
gapeweeks number(2) := 12;
shot3  VARCHAR2(8);  --第三劑日期
begin

    select  to_date(shot2,'YYYYMMDD') into shot2date from dual;
    SELECT  to_char(shot2date + ( gapeweeks * 7 ),'YYYYMMDD') into shot3 from dual;
    DBMS_OUTPUT.PUT_LINE('第二劑日期:' || shot2 || ' + ' || gapeweeks  || ' 週');
    DBMS_OUTPUT.PUT_LINE('第三劑日期:' || shot3);
end;


--======
--OUT_PUT
--第二劑日期:20211020 + 12 週
--第三劑日期:20220112

2021年11月30日 星期二

Oracle 當select 沒有order by 排序出問題時候使用 _gby_hash_aggregation_enabled = false

Oracle  當select 沒有order by 排序出問題時候使用 _gby_hash_aggregation_enabled = false當select 沒有order by 排序出問題時候使用

看到專案裡面的代碼到處充斥著時代的遺跡

select *+ OPT_PARAM('_gby_hash_aggregation_enabled' 'false') */ ......

https://www.modb.pro/db/46311


https://blog.xuite.net/oracle_dba/wretch/119310159


2021年11月16日 星期二

Oracle Output CSV File with UTF8 BOM for MS Excel to open it

Oracle Output CSV File with UTF8 BOM for MS Excel to open it



select unistr('\feff')  as bom,length(unistr('\feff') ) length
from dual;

2021年11月14日 星期日

Oracle ORA-00604

 Oracle ORA-00604

https://blog.csdn.net/wdkymys/article/details/81358095

select
b.file_name 物理文件名,
b.tablespace_name 表空间,
b.bytes/1024/1024 大小M,
(b.bytes-sum(nvl(a.bytes,0)))/1024/1024 已使用M,
substr((b.bytes-sum(nvl(a.bytes,0)))/(b.bytes)*100,1,5) 利用率
from dba_free_space a,dba_data_files b
where a.file_id=b.file_id
group by b.tablespace_name,b.file_name,b.bytes
order by b.tablespace_name
看到99%的利用率,就是天堂近了,該連絡DBA出來掃地了

2021年11月1日 星期一

Oracle Pipelined Table Functions

 Oracle Pipelined Table Functions



drop TABLE test_table;
drop PACKAGE test_pkg;
CREATE TABLE test_table(tt_id INTEGER,tt_text VARCHAR2(40));

CREATE PACKAGE test_pkg IS
    TYPE tp_rec IS RECORD(tt_id INTEGER,tt_text VARCHAR2(40));
    TYPE tp_recs IS TABLE OF tp_rec;

    FUNCTION test_func RETURN tp_recs PIPELINED;
    FUNCTION test_func1 RETURN tp_recs PIPELINED;
    FUNCTION test_func2(ivar INTEGER) RETURN tp_recs PIPELINED;
END;
/

CREATE OR REPLACE PACKAGE BODY test_pkg IS
    FUNCTION test_func RETURN tp_recs PIPELINED
    AS
       currec tp_rec;
    BEGIN
       currec.tt_id := 1;
       currec.tt_text := 'test1';
       PIPE ROW(currec);
    END;

    FUNCTION test_func1 RETURN tp_recs PIPELINED
    AS
       currec tp_rec;
       CURSOR t_cursor IS
           SELECT * FROM test_table;
    BEGIN
        OPEN t_cursor;
        LOOP
            FETCH t_cursor INTO currec;
            EXIT WHEN t_cursor%NOTFOUND;
            PIPE ROW(currec);
        END LOOP;
        CLOSE t_cursor;
    END;

    FUNCTION test_func2(ivar INTEGER) RETURN tp_recs PIPELINED
    AS
       currec tp_rec;
    BEGIN
       SELECT * INTO currec FROM test_table WHERE tt_id = ivar;
       PIPE ROW(currec);
    END;

END;
/

BEGIN
    INSERT INTO test_table VALUES(1,'test1');
    INSERT INTO test_table VALUES(2,'test2');
    INSERT INTO test_table VALUES(3,'test3');
    COMMIT;
END;
/

SELECT * FROM TABLE(test_pkg.test_func());
SELECT * FROM TABLE(test_pkg.test_func1());
SELECT * FROM TABLE(test_pkg.test_func2(2));


drop PACKAGE PIPELINED_FUN_TEST_PKG;

CREATE OR REPLACE PACKAGE PIPELINED_FUN_TEST_PKG AS
    TYPE NUMBER_TBL_TYPE IS TABLE OF NUMBER;
    FUNCTION EXAMPLE1(V_MAX_NUMBER NUMBER) RETURN NUMBER_TBL_TYPE PIPELINED;
END PIPELINED_FUN_TEST_PKG;

CREATE OR REPLACE PACKAGE BODY PIPELINED_FUN_TEST_PKG AS
    FUNCTION EXAMPLE1(V_MAX_NUMBER NUMBER) RETURN NUMBER_TBL_TYPE PIPELINED IS
    BEGIN
        FOR i IN 1..V_MAX_NUMBER LOOP
            PIPE ROW(i);
        END LOOP;
        RETURN;
    END;
END PIPELINED_FUN_TEST_PKG;


SELECT * FROM TABLE(PIPELINED_FUN_TEST_PKG.EXAMPLE1(:X))

2021年10月14日 星期四

Oracle BULK COLLECT

 Oracle BULK COLLECT

Oracle数据库之FORALL与BULK COLLECT语句

https://segmentfault.com/a/1190000019344658


PRAGMA EXCEPTION_INIT的用法

https://db-hub.net/2020/11/18/pragma-exception_init%E7%9A%84%E7%94%A8%E6%B3%95/


PL/SQL Optimization and Tuning

https://docs.oracle.com/database/121/LNPLS/tuning.htm#LNPLS012


Collection Method: DELETE Procedure In Oracle Database

http://www.rebellionrider.com/collection-method-delete-procedure-in-oracle-database/


Oracle PL/SQL 的 Array 陣列

https://tomkuo139.blogspot.com/2015/04/oracle-plsql-array.html


Oracle PL/SQL 的 for loop 迴圈使用

https://tomkuo139.blogspot.com/2010/05/oracle-plsql-for-loop.html


PL/SQL跳出迴圈語句(EXIT,CONTINUE,GOTO,EXIT WEHN)操作例項

https://codertw.com/%E7%A8%8B%E5%BC%8F%E8%AA%9E%E8%A8%80/434151/

Parallelizing INSERT, MERGE, UPDATE, and DELETE

https://docs.oracle.com/database/121/VLDBG/GUID-2627DC19-7EBE-4C45-A758-711BDB5E37EC.htm


oracle 并行之二: parallel dml

https://blog.csdn.net/ctypyb2002/article/details/102748239


PL/SQL Table 集合陣列實作 (Oracle Array-like Programming with PL/SQL Table)

https://www.abu.tw/2010/04/plsql-table-oracle-array-like.html


2021年9月30日 星期四

Oracle Instant Client with Oracle Sql Developer ,PL/Sql Developer Setup SOP

 

Oracle Instant Client with Oracle Sql Developer ,PL/Sql Developer

1. Download Oracle Instant Client 

https://www.oracle.com/tw/database/technologies/instant-client/downloads.html

and unzip the file in the path with D:\temp\oracle\instantclient_19_11-64

2.SET ENVIRONMENT 

2.1 Set the PATH on the Top Level

PATH=D:\temp\oracle\instantclient_19_11-64

2.2 Set the DB Char Set

NLS_LANG=TRADITIONAL CHINESE_TAIWAN.UTF8

[select userenv('language') from dual]

2.3 Set the TNS Path

TNS_ADMIN=D:\temp\oracle\instantclient_19_11-64

copy files sqlnet.ora tnsnames.ora in the path


Setting Up Service Names With a TNSNAMES file

<net_service_name> = (DESCRIPTION =  
    (ADDRESS_LIST =   
        (ADDRESS = (PROTOCOL = TCP)(HOST = <hostname>)(PORT = <1521>))  
    )  
    (CONNECT_DATA =(SERVICE_NAME=<oracle_sid>)        
    )
)

(DESCRIPTION=    (ADDRESS=(PROTOCOL=TCPS)(HOST=192.168.1.111)(PORT=1522))    (CONNECT_DATA=      (SERVER = DEDICATED)      (SERVICE_NAME=DB)    )  )

2021年9月8日 星期三

ORACLE FILE IO 檔案操作工具 UTL_FILE

ORACLE FILE IO 檔案操作工具 UTL_FILE 參考 Oracle - UTL_FILE包之詳解 https://iter01.com/166236.html

2021年7月22日 星期四

Oracle DBMS_OUTPUT.PUT_LINE 的地雷

 Oracle DBMS_OUTPUT.PUT_LINE 的地雷

這幾天追蹤一個AP 呼叫 Oracle SP 的案例
測試AP怎麼跑怎麼死
本機AP爽連無錯誤

原因
測試AP連DB的 緩衝太小 造成buffer overflow 想死就死不看心情
解決辦法
註解所有的 DBMS_OUTPUT.PUT_LINE

思路
目前找不到 Oracle jdbc 如何設定 buffer的教學
先這樣子吧

參考
http://tw.gitbook.net/plsql/plsql_dbms_output.html