Here is my SQL script and I want the code to check if ExitPermissionNo Column has no CCS_Reference then Update the column with new CCS_reference number and If ExitPermissionNo already has a CCS_Reference number then give an error message stating "Already in Database" and If ExitPermissionNo was not found, give an error message " The ExitPermissionNo Not Found". I wrote it like this and it does not work with all 3 conditions. Any help would be appreciated.
if ((SELECT ExitPermissionNo FROM ExitPermission WHERE (ExitPermissionNo = '333333333'))!=1)
begin
if (SELECT 'CCS_Reference' FROM ExitPermission WHERE 'CCS_Reference' IS NULL )=1
begin
PRINT 'Already In DataBase'
end
else
begin
UPDATE ExitPermission
SET CCS_Reference = 'joon'
WHERE ExitPermissionNo = '333333333';
PRINT 'The ReferenceCCS Update Successfully!'
end
end
else
begin
PRINT 'The ExitPermission Not Found!'
RAISERROR('The ExitPermission Not Found!',18,1)
end
Related
Getting the above error but the offending column is not a number. Somehow it is related to the cycle_code column which is a string. My query is hacky since I dont have full control over building it so I have to append another condition at the end ( "!= 'ABC'"). If I remove that condition the query works. I dont understand why im getting an invalid number error though?
select * from my_view WHERE ... CYCLE_CODE IN ( 'XYZ' ) AND CYCLE_CODE != 'ABC';
I would like to create a trigger with I can check the uploaded data and I can insert into another table as well. In the initial table (capture) I have 15 columns, but I would like to transfer only 5 columns (ring_number, code, year, date, species, location) to another table (ring).
The ring table is a background table in which I am collecting the combinations of ring_number and code, more specifically one ring_number could be paired only with one code. There is one exception, when the code include "X", than it can be changed later, and in this case this code can be paired with more ring_number, and if originally belongs to the ring_number a code with "X" it can be changed later.
In the capture table, could be possible to upload the same combination of code and ring_number multiple times with a condition of a third column. But still the ring_number can be paired only with one code, with exceptions of codes included "X". The name of the conditional column is recapture. If recapture (boolean column type) is "true", then you can upload the combination of code and ring_number again. If it is "empty" or "no" you can upload only new combinations of code and ring_number. If somebody uploads old combinations then the following error message has to raise: this combination already exists, please check your data and if it is a recapture, then set the recapture column to yes.
Additionally: ring_number is a not null column, but code can be empty. And different ring_number can be paired with empty code than later can be paired with actual value.
I have several problems with my code:
1: I would like to define the exception to X with regex, and the X can be anywhere in the code. But can not manage the regex in a good way. It does just not work.
2: I write conditional checkpoint with recapture column and if I have an old combination this is work on the right way and say please set the recapture column to yes. But! If I set the recapture column to yes I get the same error message.
Could you help to solve these issues?
Here is my code:
Declare
a integer := 0;
b integer := 0;
c integer := 0;
d integer := 0;
Begin
IF new.code <> '' THEN
--Az 'a' means whether the given ring_number already exist in the database with a code, which is not empty
SELECT INTO a COUNT(*) FROM plover_captures PC WHERE PC.ring_number = new.ring_number AND PC.code <> new.code AND PC.code <> '' AND PC.code ~ '[X]{2}[\.]{1}[X]{2}[|]{1}[X]{2}[\.]{1}[X]{2}';
--Az 'b' means the given code already exist in the database with a ring_number
SELECT INTO b COUNT(*) FROM plover_captures PC WHERE PC.ring_number <> new.ring_number AND PC.code = new.code AND PC.code ~ '[X]{2}[\.]{1}[X]{2}[|]{1}[X]{2}[\.]{1}[X]{2}';
--Az 'c' how much times exist the given ring_number with the given code in the database
SELECT INTO c COUNT(*) FROM plover_captures PC WHERE PC.ring_number = new.ring_number AND PC.code = new.code AND PC.code ~ '[X]{2}[\.]{1}[X]{2}[|]{1}[X]{2}[\.]{1}[X]{2}';
--Az 'd' means the given combination already exist in ring table or not
SELECT INTO d COUNT(*) FROM plover_rings PC WHERE PC.ring_number = new.ring_number AND PC.code = new.code;
IF a > 0 THEN
raise exception 'This ring_number is already paired with another code before. %', new.ring_number;
END IF;
IF b > 0 THEN
raise exception 'This code is already paired with another ring_number before. %', new.code;
END IF;
IF c > 0 AND (new.rettrap IS null OR new.rettrap IS false) THEN
raise exception 'This ring_number and code pair is already in the database. So it is a rettrap but the rettrap attribute set to false or null. %, %, %', new.ring_number, new.code, new.rettrap;
END IF;
IF c = 0 AND new.rettrap IS true THEN
raise exception 'The rettrap attribute set to true but this ring_number and code pair is not in this database yet. %, %, %', new.ring_number, new.code, new.rettrap;
END IF;
IF c = 0 AND d = 0 THEN
Insert into plover_rings values(new.ring_number,new.code,new.species,new.location,new.year, new.date);
END IF;
END IF;
Return new;
End
I want to calling oracle array package in oracle apex page process.
My package "CREATE OR REPLACE PACKAGE SBPA.DPG_SBPA_ITEM_SUB_CAT AS
/..........................................................................
Program Purpose : SBPA_ITEM_SUB_CAT_ENTRY
Process Execution Time :
Generate By : Morshed
Generate Date : 27-Feb-2020
Modifyed Date :
...................................................................../
TYPE RefCursor is REF CURSOR;
TYPE Array_Item_Sub_Id IS TABLE OF SBPA_ITEM_SUB_CAT.ITEM_SUB_ID % TYPE INDEX BY BINARY_INTEGER;
TYPE Array_Item_Sub_Code IS TABLE OF SBPA_ITEM_SUB_CAT.ITEM_SUB_CODE % TYPE INDEX BY BINARY_INTEGER;
TYPE Array_Item_Sub_Desc IS TABLE OF SBPA_ITEM_SUB_CAT.ITEM_SUB_DESC % TYPE INDEX BY BINARY_INTEGER;
TYPE Array_Item_Cat_Code IS TABLE OF SBPA_ITEM_SUB_CAT.ITEM_CAT_CODE % TYPE INDEX BY BINARY_INTEGER;
TYPE Array_RowStatus IS TABLE OF VARCHAR2(5) INDEX BY BINARY_INTEGER;
PROCEDURE DPD_SBPA_ITEM_SUB_CAT (O_Status OUT NUMBER,
P_Item_Sub_Id IN Array_Item_Sub_Id,
P_Item_Sub_Code IN Array_Item_Sub_Code,
P_Item_Sub_Desc IN Array_Item_Sub_Desc,
P_Item_Cat_Code IN Array_Item_Cat_Code,
P_RowStatus IN Array_RowStatus,
P_USER VARCHAR2);
PROCEDURE DPD_SBPA_ITEM_SUB_CAT_GRID (Cur_Data OUT RefCursor);
END DPG_SBPA_ITEM_SUB_CAT;
/"
And Package body "CREATE OR REPLACE PACKAGE BODY SBPA.DPG_SBPA_ITEM_SUB_CAT AS
/..........................................................................
Program Purpose : SBPA_ITEM_SUB_CAT_ENTRY
Process Execution Time :
Generate By : Morshed
Generate Date : 27-Feb-2020
Modifyed Date :
...................................................................../
PROCEDURE DPD_SBPA_ITEM_SUB_CAT (O_Status OUT NUMBER,
P_Item_Sub_Id IN Array_Item_Sub_Id,
P_Item_Sub_Code IN Array_Item_Sub_Code,
P_Item_Sub_Desc IN Array_Item_Sub_Desc,
P_Item_Cat_Code IN Array_Item_Cat_Code,
P_RowStatus IN Array_RowStatus,
P_USER VARCHAR2) IS
V_DataType VARCHAR2(20) :='ITEM_SUBCAT_SAVE';
V_ErrDesc VARCHAR2(500);
BEGIN
/*O_Status :=1;*/
FOR I IN P_Item_Sub_Desc.FIRST..P_Item_Sub_Desc.LAST
LOOP
IF P_RowStatus(I)=1 THEN
INSERT INTO SBPA_ITEM_SUB_CAT
(ITEM_SUB_ID, ITEM_SUB_CODE, ITEM_SUB_DESC, ITEM_CAT_CODE, STATUS, CREATE_DATE, CREATE_BY) VALUES
(SBPA_ITEM_SUB_ID_SEQ.NEXTVAL,'ITMSC-'||LPAD(SBPA_ITEM_SUB_CODE_SEQ.NEXTVAL,4,'0'),P_Item_Sub_Desc(I),P_Item_Cat_Code(I),'A',SYSDATE,P_USER);
ELSIF P_RowStatus(I)=2 THEN
UPDATE SBPA_ITEM_SUB_CAT SET
ITEM_SUB_DESC=P_Item_Sub_Desc(I),
Item_Cat_Code=P_Item_Cat_Code(I),
UPDATE_BY=P_User,
UPDATE_DATE =SYSDATE
WHERE Item_Sub_Code=P_Item_Sub_Code(I);
ELSIF P_RowStatus(I)=3 THEN
DELETE FROM SBPA_ITEM_SUB_CAT
WHERE Item_Sub_Code=P_Item_Sub_Code(I);
END IF;
END LOOP;
COMMIT;
EXCEPTION WHEN OTHERS THEN ROLLBACK;
/* O_Status :=0;*/
V_ErrDesc:=SUBSTR(SQLERRM,1,500);
INSERT INTO SBPA_ERROR_LOG
(RUN_ID, DATA_TYPE, ERROR_DESC, STATUS, RUN_DATE, RUN_BY) VALUES
(SBPA_RUN_ID_SEQ.NEXTVAL,V_DataType,V_ErrDesc,'E',SYSDATE,P_User);
COMMIT;
END DPD_SBPA_ITEM_SUB_CAT;
PROCEDURE DPD_SBPA_ITEM_SUB_CAT_GRID (Cur_Data OUT RefCursor) IS
BEGIN
OPEN CUR_DATA FOR
SELECT ITEM_SUB_ID, ITEM_SUB_CODE, ITEM_SUB_DESC,S.ITEM_CAT_CODE,C.ITEM_CAT_DESC FROM SBPA_ITEM_SUB_CAT S,SBPA_ITEM_CAT C
WHERE S.ITEM_CAT_CODE=C.ITEM_CAT_CODE
ORDER BY ITEM_SUB_ID DESC;
END DPD_SBPA_ITEM_SUB_CAT_GRID;
END DPG_SBPA_ITEM_SUB_CAT;
/"
This database code. So how can i call this package in oracle apex tabular form. Please help me..
(1) Create a button, so the processing(DML) will be performed on click of the button.
(2) Button Action -> Submit Page.
(3) Create a page Process
Point -> Processing.
Tabular Form -> Select your tabular form.
Pl/SQL Code -> Begin
package_name.procedure_name(parameters);
END;
(4) When Button Pressed: Select the created button.
(5) Execution Scope: For Created and Modified rows.
I'm working to programmatically clean up a field in my dataset by using a Helper column that I will later filter on and remove the 'junk' records. The junk records are ID's, and the valid records are full names (in the format of "Tom Jones"). Almost all (there is a valid name value of "University") junk records do not contain a space. The pseudo code would read
Set Helper_IsName? = True
WHERE ValueField CONTAINS " " unless ValueField = "University"
ELSE False
Here is the M code excerpt that is getting me 95% of the way there:
Helper_IsName? = Text.Contains([OldValue]," ")
All results are good, except when the formula reads "University", it sets the value as FALSE, when I need it to equal TRUE.
I think you can just add that condition with an or:
Helper_IsName? = Text.Contains([OldValue]," ") or [OldValue] = "University"
This procedure should list all project IDs mapped to the active user, and on passing an invalid user id it should print "User is not valid". However, no message is getting displayed.
PROCEDURE get_pid_info (p_return_status_o OUT VARCHAR2,
p_error_message_o OUT VARCHAR2,
p_user_id IN VARCHAR2)
IS
CURSOR c_pid
IS
SELECT DISTINCT xpppa.project_id,
papf.person_type_id,
xpppp.end_date_active,
papf.person_id,
COUNT (DISTINCT xpppa.project_id) pid_count
FROM xxcas_prj_pa_projects_all xpppa,
xxcas_prj_pa_project_players xpppp,
per_all_people_f papf
WHERE xpppa.project_id = xpppp.project_id
AND xpppp.person_id = papf.person_id
AND papf.person_id = 61--p_user_id
AND xpppp.project_role_type = 'PROJECT MANAGER'
AND papf.person_type_id = 6
and sysdate between xpppa.start_date and nvl(xpppa.completion_date,sysdate+1)
and sysdate between xpppp.start_date_active and nvl(xpppp.end_date_active,sysdate+1)
AND EXISTS
(SELECT 1
FROM pa_lookups
WHERE lookup_type = 'XXCAS_PRJ_USER_DETAILS'
AND description=papf.email_address
AND enabled_flag = 'Y'
AND SYSDATE BETWEEN start_date_active
AND NVL (end_date_active,
SYSDATE + 1))
GROUP BY xpppa.project_id,
papf.person_type_id,
xpppp.end_date_active,
papf.person_id;
BEGIN
FOR l_rec IN c_pid
LOOP
IF l_rec.project_id IS NOT NULL
THEN
dbms_output.put_line (
'The Projects mapped to the active user ID are : '
|| l_rec.project_id);
ELSIF l_rec.end_date_active < SYSDATE
THEN
dbms_output.put_line (
'The user has been end dated in the system on : ' || l_rec.end_date_active);
ELSIF l_rec.pid_count = 0
THEN
dbms_output.put_line (
'There are no projects mapped to the user having PM role');
ELSE
dbms_output.put_line ('Please check the user ID passed');
END IF;
IF SQL%NOTFOUND
THEN
dbms_output.put_line('Entered user id is not valid');
end if;
END LOOP;
EXCEPTION
WHEN NO_DATA_FOUND
THEN
dbms_output.put_line ('Please provide valid user ID');
WHEN OTHERS
THEN
dbms_output.put_line ('Error in get_pid' || SQLERRM);
END get_pid_info;
Anonymous Block:
declare
status varchar2(30);
msg varchar2(30);
begin
--DBMS_OUTPUT.ENABLE('20000000');
XXCAS_PRJ_PROJECT_DTLS.GET_PID_INFO(status,msg,61);
end;
Firstly, if there are no rows to process then the loop is not entered and so any check inside it will not be executed.
Secondly, the SQL% cursor attributes apply to implicit cursors, not named ones like c_pid in your procedure. It would be simplest to declare a Boolean variable, initialise it to FALSE and set it to TRUE in the loop; then you can check its value after the loop. (Or if you want the actual number of rows, use c_pid%rowcount and initialise it to 0.)
I'm assuming this is a simplified version of your actual procedure, as dbms_output is not generally useful in production code unless the caller is set up to capture it.