發表文章

目前顯示的是有「PL/SQL」標籤的文章

PL-SQL筆記5_ORA-06550_PLS-00428: 在此SELECT敘述句中預期會出現一個INTO子句

 在PLSQL Develoepr 想進行腳本測試時 DECLARE   v_groupName VARCHAR2(300); BEGIN   v_groupName := 'some group name';   SELECT R.*     FROM ROLE_TABLE R,          USER_ROLE_RELATION UR,          USER_CONTACT UC    WHERE R.ROLE_NAME = v_groupName      AND R.ROLE_ID   = UR.ROLE_ID      AND UR.USER_ID  = UC.USER_ID; END; 報以下錯誤 ORA-06550: 第四行,第 3 個欄位: PLS-00428: 在此SELECT敘述句中預期會出現一個INTO子句 原因: 要在 PL/SQL 區塊裡查詢 → 必須用 INTO 或 Cursor。 在 PL/SQL 區塊裡,不可能直接寫裸的 SELECT。 若不想用 INTO,就不要包在 PL/SQL 區塊裡,直接寫 SQL 查詢。

PL-SQL筆記4_Oracle Listener與Listener.ora檔案,lsnrctl(Listener control)

圖片
  Oracle Net Listener : a separate process that runs on the database server computer. It receives incoming client connection requests and manages the traffic of these requests to the database server. Listener.ora檔案 : is the configuration file for a listener. It can include the protocol address it is accepting connection requests on a list of the database and other services it is listening for, and control paramaters used by the listener. 預設windows安裝好的位置 C:\app\你的User名\product\21c\homes\OraDB21Home1\network\admin 配置檔案內文 # listener.ora Network Configuration File: C:\app\chous\product\21c\homes\OraDB21Home1\NETWORK\ADMIN\listener.ora # Generated by Oracle configuration tools. DEFAULT_SERVICE_LISTENER = XE SID_LIST_LISTENER = (SID_LIST = (SID_DESC = (SID_NAME = CLRExtProc) (ORACLE_HOME = C:\app\chous\product\21c\dbhomeXE) (PROGRAM = extproc) (ENVS = "EXTPROC_DLLS=ONLY:C:\app\chous\product\21c\dbhomeXE\bin\oraclr.dll") ) ) LISTENER = (DESCR...

PL-SQL筆記2_延伸XEPDB1登入_列出有哪些DB_連線登入到指定DB_建立新User並Grant權限

圖片
  在之前篇章已經知道如何去安裝Express免費用於學習或開發階段的Oracle DB PL-SQL筆記1_OracleOracle Database 21c Express Edition下載安裝筆記 https://coolmandiary.blogspot.com/2023/04/oracle-database-21c-express-edition.html 在這邊如果點選Oracle 執行處裡管理員跳出來的就是如下視窗 而點選SQL Plus則可以開啟終端 以DBA身分登入 / as sysdba 可以先撈取顯示幕前有哪些資料庫 select name from v$pdbs; 這邊可看到XEPDB1  這邊PDB這字眼代表的是 A pluggable database is a portable collection of schemas,schema objects, and nonschema objects in an oracle database. 登入指定的資料庫語法 connect sys/你一開始設置的SYS密碼@localhost:1521/資料庫名稱 as sysdba; 建立新User並Grant權限 (建立可登入、可建表的使用者,且表預設放在 USERS 表空間並有足夠空間。) create user demouser identified by demouser default tablespace users quota unlimited on users; 建立一個名為 demouser 的資料庫使用者,密碼也是 demouser(預設大小寫敏感) default tablespace users 將 USERS 設為這個使用者建立物件時的「預設永久表空間」。 quota unlimited on users 給予這個使用者在 USERS 表空間「不限額度」的配額,因此他可以在該表空間建立/擴張自己的物件(表、索引…)。若未設定配額或沒有 UNLIMITED,即使有建表權限也可能因為「沒有表空間配額」而建不起來。 grant create session, create table to demouser; create session:允許 demouser 登入資料庫(沒有此權限就不能連線)。 cr...

PL-SQL筆記3_ORA-28000: 帳戶已被鎖定又忘記密碼怎麼辦?

圖片
PL-SQL筆記1_OracleOracle Database 21c Express Edition下載安裝筆記 https://coolmandiary.blogspot.com/2023/04/oracle-database-21c-express-edition.html 在個人電腦上練習Oracle時候 發覺太久沒登入忘記密碼多次輸入後被鎖住了QQ Step1.以管理員身份連接到數據庫 sqlplus / as sysdba Step2.確查目前有哪些帳號被鎖(或指定該帳號名稱)確認當前帳戶的LOCK狀態 SELECT username, account_status FROM dba_users WHERE username = 'username' ; Step3.解鎖用戶帳戶 ALTER USER 用戶名 ACCOUNT UNLOCK; Step4.忘記了密碼,修改用戶密碼 ALTER USER username IDENTIFIED BY new_password; Step5.重登一次試試看就皆大歡喜。

PL/SQL Developer如何去產生ERD

File > New > Diagram Window 將table物件給拖曳進來會自動顯示表與表之間關聯 Ref: https://forums.allroundautomations.com/ubb/ubbthreads.php?ubb=showflat&Number=39589 https://origin2.cdn.componentsource.com/sites/default/files/resources/allround-automations/680211/plsqldeveloper1306-manual.pdf

PL/SQL筆記2_如何去撈取確查某View實際定義

圖片
方法1.(最全面) select * FROM all_VIEWS where VIEW_NAME = '<view_name>' ; 方法2. select DBMS_METADATA.GET_DDL ( 'VIEW' , 'view_name' , 'owner' ) from dual; 方法3.某view有reference到哪些table跟view呢? select owner as view_schema, name as view_name, referenced_owner as referenced_schema, referenced_name as referenced_name, referenced_type from sys.all_dependencies where type = 'VIEW' and referenced_type in ( 'TABLE' , 'VIEW' ) -- and owner = 'SCHEMA_NAME' -- put schema name here -- and name = 'VIEW NAME' -- put view name here order by owner , view_name; Ref: Get Oracle View Definition with limited control https://stackoverflow.com/questions/31104012/get-oracle-view-definition-with-limited-control Find tables and views used by specific view in Oracle database https://dataedo.com/kb/query/oracle/find-tables-used-by-specific-view

PL/SQL筆記1_如何確查當前Oracle使用的版本號

圖片
  方法1.藉由V$VERSION 的View SELECT BANNER, BANNER_FULL FROM v $ version ; 方法2.藉由 PRODUCT_COMPONENT_VERSION 的View SELECT VERSION , VERSION_FULL FROM PRODUCT_COMPONENT_VERSION; Ref: https://www.beekeeperstudio.io/blog/how-to-check-oracle-version-and-edition https://database.guide/7-ways-to-check-your-oracle-version/