plsql

Dynamic Pivot Query using Sql Developer Oracle

喜夏-厌秋 提交于 2021-01-29 07:09:12
问题 Initial table students NAME School Class John Hs English Steve Hs Maths Matthew Hs Science Jim Hs History Output Needed: I need the query to auto pick up Name column data from initial table and change it to column headers in output and since the names will continuously change i cannot hard code the names using simple pivot query. I am new to pivot queries so I wanted to request if someone can help me out. Thank You. School John Steve Matthew Jim Hs English Maths Science History Here's what i

Retrieving and displaying data from oracle database

二次信任 提交于 2021-01-29 07:01:04
问题 First of all, I would like to THANK YOU for stopping by and spending your precious time for looking at my problem. I have 2 different tables within an Oracle Database. The first table holds metadata about the columns present in the other table. Think of the first (COL_TAB) table as a custom version of the ALL_TAB_COLS which comes by default with Oracle. COL_TAB ---------------------------------------------- | TABLE_NAME | COL_NAME | COL_DESC | ---------------------------------------------- |

How Can I Send Emails in PL/SQL (Oracle)?

橙三吉。 提交于 2021-01-29 06:44:06
问题 I have a procedure which count the number of rows in SMS_OUTBOX table and send emails if its row cont is over 1000. My procedure is given below: CREATE OR REPLACE PROCEDURE SEND_EMAIL_ABOUT_PENDING_SMS IS CHECK_SMS_COUNT NUMBER := 1000; CURRENT_SMS_COUNT NUMBER; BEGIN SELECT COUNT(1) INTO CURRENT_SMS_COUNT FROM SMS_SCHEMA.SMS_OUTBOX; IF CURRENT_SMS_COUNT >= CHECK_SMS_COUNT THEN UTL_MAIL.SEND( sender=>'<SENDER_EMAIL>', recipients=>'<RECIPIENT_EMAIL>', subject=>'Pending SMS', Message=>'Pending

How do I re-order data in the same table?

心不动则不痛 提交于 2021-01-29 05:47:44
问题 AS-IS: ID Version 5587138 1 6460704 2 6537612 3 6264608 4 TO-BE: ID Version 5587138 1 6264608 2 6460704 3 6537612 4 I have to re-order the IDs to match the version order. The data is coming from the same table. I am currently trying to use PL/SQL. I really need help on this issue. Thank you. 回答1: You can use the merge statement as follows: merge into your_table trg using (select id, row_number() over (order by id) as version from your_table) src on (trg.id = src.id) when matched then update

Use dbms_xmldom.writetofile without a Named Directory

不问归期 提交于 2021-01-29 05:30:53
问题 I am trying to write an XML file using PL/SQL using the procedure dbms_xmldom.writetofile . However, the code above only works when I supply a named directory taken from DBA_DIRECTORIES like below: procedure PRINT_XML (p_xml xmltype ,p_requestid number) is l_filename varchar2(100); doc dbms_xmldom.domdocument; l_directory request_history.OUTPUTWORKDIRECTORY%type; l_dml_stmnt request_history.OUTPUTWORKDIRECTORY%type; begin l_filename := 'JPK_Accounting_Books_'||g_jpk_ess_request_id||'.xml';

PL/SQL raise handled exception

落爺英雄遲暮 提交于 2021-01-29 04:45:48
问题 How can I throw cached exception in PL/SQL? For example I have procedure, where I catch all exceptions: EXCEPTION WHEN OTHERS THEN rollback; and then I want to throw catched exception to procedure caller. Thanks in advance! 回答1: Just add raise; : EXCEPTION WHEN OTHERS THEN rollback; raise; 回答2: To re-raise the exception, just use raise; To define a custom application error, look at raise_application_error, e.g. raise_application_error(-20001, 'Warp core implosion imminent', true); It's worth

Taking table name as input in sql

独自空忆成欢 提交于 2021-01-29 04:37:44
问题 I need to take a table name as input from user to my PL / SQL script and then update that table. I am not sure if this is possible because ORACLE might have problem parsing the script. Please guild me as to how to solve this problem. Thnx. 回答1: Use EXECUTE IMMEDIATE. It allows you to build a SQL statement as a VARCHAR2 string and then execute that statement. eg. lStr := 'UPDATE '||table-name||' SET COLUMN-NAME = VALUE'; EXECUTE IMMEDIATE lStr; COLUMN-NAME and VALUE can also be changed

PL/SQL raise handled exception

穿精又带淫゛_ 提交于 2021-01-29 04:36:37
问题 How can I throw cached exception in PL/SQL? For example I have procedure, where I catch all exceptions: EXCEPTION WHEN OTHERS THEN rollback; and then I want to throw catched exception to procedure caller. Thanks in advance! 回答1: Just add raise; : EXCEPTION WHEN OTHERS THEN rollback; raise; 回答2: To re-raise the exception, just use raise; To define a custom application error, look at raise_application_error, e.g. raise_application_error(-20001, 'Warp core implosion imminent', true); It's worth

how to pass object type as a parameter in oracle

早过忘川 提交于 2021-01-29 02:33:09
问题 below abstarct type created create or replace TYPE callbck as table of callback_t; abstract table create or replace TYPE CALLBACK_T as object ( url varchar2(50), uri_key number, ); below is the procedure used, procedure get_callback_info ( pi_clbk callbck := callbck (), requestor varchar2, msg varchar2) how to pass the parameter for the abstract object type to the procedure get_callback_info. i have the abstract values 'http://test.com', and 1345 as the url and uri_key 回答1: Say you have these

Oracle Function to return similarity between strings

梦想的初衷 提交于 2021-01-28 03:09:23
问题 I have an interesting problem and am wondering if oracle has a built-in function to do this or I need to find a fast way to do it in plsql. Take 2 strings: s1 = 'abc def hijk' s2 = 'abc def iosk' The function needs to return abc def because the strings are exactly the same up to that point. Another example: s1 = 'abc def hijk www' s2 = 'abc def iosk www' The function needs to return abc def . The only way I can think of doing this is loop through string1 and compare each character with substr