diff --git a/.github/workflows/veracode-analysis.yml b/.github/workflows/veracode-analysis.yml new file mode 100644 index 0000000..1dd5dd2 --- /dev/null +++ b/.github/workflows/veracode-analysis.yml @@ -0,0 +1,51 @@ +# This workflow uses actions that are not certified by GitHub. +# They are provided by a third-party and are governed by +# separate terms of service, privacy policy, and support +# documentation. + +# This workflow will initiate a Veracode Static Analysis Pipeline scan, return a results.json and convert to SARIF for upload as a code scanning alert + +name: Veracode Static Analysis Pipeline Scan + +on: + push: + branches: [ master ] + pull_request: + # The branches below must be a subset of the branches above + branches: [ master ] + schedule: + - cron: '34 4 * * 1' + +# A workflow run is made up of one or more jobs that can run sequentially or in parallel +jobs: + # This workflow contains a job to build and submit pipeline scan, you will need to customize the build process accordingly and make sure the artifact you build is used as the file input to the pipeline scan file parameter + build-and-pipeline-scan: + # The type of runner that the job will run on + runs-on: ubuntu-latest + steps: + + # Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it and copies all sources into ZIP file for submitting for analysis. Replace this section with your applications build steps + - uses: actions/checkout@v2 + with: + repository: '' + + - run: zip -r veracode-scan-target.zip ./ + + # download the Veracode Static Analysis Pipeline scan jar + - run: curl --silent --show-error --fail -O https://downloads.veracode.com/securityscan/pipeline-scan-LATEST.zip + - run: unzip -o pipeline-scan-LATEST.zip + + - uses: actions/setup-java@v1 + with: + java-version: 1.8 + - run: java -jar pipeline-scan.jar --veracode_api_id "${{secrets.VERACODE_API_ID}}" --veracode_api_key "${{secrets.VERACODE_API_KEY}}" --fail_on_severity="Very High, High" --file veracode-scan-target.zip + continue-on-error: true + - name: Convert pipeline scan output to SARIF format + id: convert + uses: veracode/veracode-pipeline-scan-results-to-sarif@ff08ae5b45d5384cb4679932f184c013d34da9be + with: + pipeline-results-json: results.json + - uses: github/codeql-action/upload-sarif@v1 + with: + # Path to SARIF file relative to the root of the repository + sarif_file: veracode-results.sarif diff --git a/COMM_PACKAGE.pkb b/COMM_PACKAGE.pkb new file mode 100644 index 0000000..ff4f91e --- /dev/null +++ b/COMM_PACKAGE.pkb @@ -0,0 +1,11 @@ +CREATE OR REPLACE PACKAGE BODY comm_package IS + FUNCTION validate_comm (p_comm IN NUMBER) RETURN BOOLEAN + IS v_max_comm NUMBER; + BEGIN -- validates commission to be less than maximum + -- commission in the table + END validate_comm; + PROCEDURE reset_comm (p_comm IN NUMBER) + IS BEGIN -- calls validate_comm with specified value + END reset_comm; +END comm_package; +/ diff --git a/Create For Trigger Operation On Table.trg b/Create For Trigger Operation On Table.trg new file mode 100644 index 0000000..5985bf4 --- /dev/null +++ b/Create For Trigger Operation On Table.trg @@ -0,0 +1,5 @@ + +CREATE TABLE employee( +employee_id int NOT NULL,last_name varchar(255) NOT NULL, job_id varchar(255) NOT NULL,salary varchar(255) NOT NULL, + PRIMARY KEY (employee_id) +); \ No newline at end of file diff --git a/DECODE.sql b/DECODE.sql new file mode 100644 index 0000000..a592126 --- /dev/null +++ b/DECODE.sql @@ -0,0 +1,9 @@ +/* Formatted on 21-Oct-21 5:11:34 AM (QP5 v5.287) */ +SELECT * + FROM HR.EMPLOYEES + WHERE department_id = + DECODE ( :PDEPT, + 'ALL', department_id, + 'TEN', 10, + 'NINTY', 90, + 20); \ No newline at end of file diff --git a/DML_EMP_VALUES.trg b/DML_EMP_VALUES.trg new file mode 100644 index 0000000..f2fdc32 --- /dev/null +++ b/DML_EMP_VALUES.trg @@ -0,0 +1,90 @@ +/* Formatted on 03-Nov-21 11:55:31 AM (QP5 v5.287) */ +CREATE OR REPLACE TRIGGER dml_emp_values + AFTER DELETE OR INSERT OR UPDATE + ON employee + FOR EACH ROW + ENABLE +DECLARE + idn NUMBER (6, 0); + user_name VARCHAR2 (25); + timestampn VARCHAR2 (25); + old_last_name VARCHAR2 (25); + new_last_name VARCHAR2 (25); + old_title VARCHAR2 (10); + new_title VARCHAR2 (10); + old_salary VARCHAR2 (10); + new_salary VARCHAR2 (10); +BEGIN + SELECT USER, TO_CHAR (SYSDATE, 'DD/MON/YYYY HH24:MI:SS') + INTO user_name, timestampn + FROM DUAL; + + IF INSERTING + THEN + INSERT INTO t_emp_table (user_name, + timestampn, + idn, + old_last_name, + new_last_name, + old_title, + new_title, + old_salary, + new_salary, + operation) + VALUES (USER, + SYSDATE, + :NEW.employee_id, + :NEW.last_name, + :NEW.last_name, + :NEW.job_id, + :NEW.last_name, + :NEW.salary, + :NEW.salary, + 'Insert'); + ELSIF DELETING + THEN + INSERT INTO t_emp_table (user_name, + timestampn, + idn, + old_last_name, + new_last_name, + old_title, + new_title, + old_salary, + new_salary, + operation) + VALUES (USER, + SYSDATE, + :OLD.employee_id, + :OLD.last_name, + :OLD.last_name, + :OLD.job_id, + :OLD.last_name, + :OLD.salary, + :OLD.salary, + 'Delete'); + ELSIF UPDATING + THEN + INSERT INTO t_emp_table (user_name, + timestampn, + idn, + old_last_name, + new_last_name, + old_title, + new_title, + old_salary, + new_salary, + operation) + VALUES (USER, + SYSDATE, + :OLD.employee_id, + :OLD.last_name, + :NEW.last_name, + :OLD.job_id, + :NEW.last_name, + :OLD.salary, + :NEW.salary, + 'Insert'); + END IF; +END; +/ \ No newline at end of file diff --git a/DPK_RADWAN PROCEDURE.pkb b/DPK_RADWAN PROCEDURE.pkb new file mode 100644 index 0000000..e46b8d7 --- /dev/null +++ b/DPK_RADWAN PROCEDURE.pkb @@ -0,0 +1,79 @@ +CREATE OR REPLACE PACKAGE BODY dpk_radwan +AS + PROCEDURE p_email_validation (email_address IN VARCHAR2) IS + at_the_rate NUMBER; + dot_symbol NUMBER; + c_at_the_rate NUMBER; + c_dot_symbol NUMBER; + string_length NUMBER; + before_dot NUMBER; + temp NUMBER; + after_dot NUMBER; + undefine_symbol NUMBER; + BEGIN -- domain := INSTR (email_address, 'com'or '.in'or'.bd'or '.gov'or '.org'); + + at_the_rate := INSTR (email_address, '@'); + dot_symbol := INSTR (email_address, '.'); + string_length := LENGTH (email_address); + c_at_the_rate := + ROUND (LENGTH (email_address) - LENGTH (REPLACE (email_address, '@'))); + c_dot_symbol := + ROUND (LENGTH (email_address) - LENGTH (REPLACE (email_address, '.'))); + -- after_at_the_rate := at_the_rate+1; + before_dot := INSTR (email_address, '.'); + after_dot := INSTR (email_address, '.'); + temp := dot_symbol; + --DBMS_OUTPUT.put_line ('TEMP' || ' : ' || temp); + undefine_symbol := + INSTR (email_address, '!') + || INSTR (email_address, '/') + || INSTR (email_address, '#') + || INSTR (email_address, '%') + || INSTR (email_address, '$') + || INSTR (email_address, '^') + || INSTR (email_address, '&') + || INSTR (email_address, '*') + || INSTR (email_address, '(') + || INSTR (email_address, '(') + || INSTR (email_address, '-') + || INSTR (email_address, '+') + || INSTR (email_address, '=') + || INSTR (email_address, '`') + || INSTR (email_address, '~') + || INSTR (email_address, '?') + || INSTR (email_address, '{') + || INSTR (email_address, '}') + || INSTR (email_address, '[') + || INSTR (email_address, ']') + || INSTR (email_address, '\') + || INSTR (email_address, '|') + || INSTR (email_address, '"') + || INSTR (email_address, ':') + || INSTR (email_address, ';') + || INSTR (email_address, ']') + || INSTR (email_address, '[') + || INSTR (email_address, '?') + || INSTR (email_address, '>') + || INSTR (email_address, '<') + || INSTR (email_address, ',') + || INSTR (email_address, '..') + || INSTR (email_address, '.@') + || INSTR (email_address, '@.'); + -- DBMS_OUTPUT.put_line (before_dot || ' AND ' || after_dot); + IF ( ( (dot_symbol = 0) + OR (at_the_rate = 0) + OR (undefine_symbol >= 1) + OR (at_the_rate = 1) + OR (c_at_the_rate > 1) + OR (at_the_rate = string_length) + OR (dot_symbol = string_length))) + THEN + DBMS_OUTPUT.put_line ('Invalid email addresses'); + END IF; + DBMS_OUTPUT.put_line ('Valid email addresses'); + EXCEPTION + WHEN OTHERS + THEN + DBMS_OUTPUT.put_line ('Can not able to say valid or invalid'); + END p_email_validation; +END dpk_radwan; \ No newline at end of file diff --git a/DPK_RADWAN Package Create.pks b/DPK_RADWAN Package Create.pks new file mode 100644 index 0000000..648d861 --- /dev/null +++ b/DPK_RADWAN Package Create.pks @@ -0,0 +1,5 @@ +/* Formatted on 02-Nov-21 4:43:58 PM (QP5 v5.287) */ +CREATE OR REPLACE PACKAGE dpk_radwan +AS + PROCEDURE p_email_validation (email_address IN VARCHAR2); +END dpk_radwan; diff --git a/Drop Trigger.trg b/Drop Trigger.trg new file mode 100644 index 0000000..30016fb --- /dev/null +++ b/Drop Trigger.trg @@ -0,0 +1 @@ +DROP TRIGGER dml_emp_values; \ No newline at end of file diff --git a/E_TPP package and procedures creating with UP date Procedure.pks b/E_TPP package and procedures creating with UP date Procedure.pks new file mode 100644 index 0000000..17c08a6 --- /dev/null +++ b/E_TPP package and procedures creating with UP date Procedure.pks @@ -0,0 +1,14 @@ +CREATE OR REPLACE PACKAGE e_tpp +AS + + PROCEDURE delEmployee (e_id employee.employee_id%TYPE); + + PROCEDURE addEmployee (e_id employee.employee_id%TYPE, + e_name employee.last_name%TYPE, + e_job employee.job_id%TYPE, + e_sal employee.salary%TYPE); + PROCEDURE upEmployee (e_id employee.employee_id%TYPE, + e_name employee.last_name%TYPE, + e_job employee.job_id%TYPE, + e_sal employee.salary%TYPE); +END e_tpp; diff --git a/E_TPP package and procedures creating.pks b/E_TPP package and procedures creating.pks new file mode 100644 index 0000000..53fda44 --- /dev/null +++ b/E_TPP package and procedures creating.pks @@ -0,0 +1,10 @@ +CREATE OR REPLACE PACKAGE e_tpp +AS + + PROCEDURE delEmployee (e_id employee.employee_id%TYPE); + PROCEDURE listEmployee; + PROCEDURE addEmployee (e_id employee.employee_id%TYPE, + e_name employee.last_name%TYPE, + e_job employee.job_id%TYPE, + e_sal employee.salary%TYPE); +END e_tpp; diff --git a/Execution of e_tpp add employee by package to perfrom trigger.pks b/Execution of e_tpp add employee by package to perfrom trigger.pks new file mode 100644 index 0000000..44aea4a --- /dev/null +++ b/Execution of e_tpp add employee by package to perfrom trigger.pks @@ -0,0 +1,2 @@ +--EXECUTE p_email_validation( 'radwanromy@gmail.com'); + EXECUTE e_tpp.addEmployee(033,'Radwan','CEO',5000); diff --git a/FORWARD_PACK.pkb b/FORWARD_PACK.pkb new file mode 100644 index 0000000..bd5d2de --- /dev/null +++ b/FORWARD_PACK.pkb @@ -0,0 +1,18 @@ +/* Formatted on 25-Oct-21 4:53:03 AM (QP5 v5.287) */ +CREATE OR REPLACE PACKAGE BODY forward_pack +IS + PROCEDURE award_bonus(1000) + IS + BEGIN + calc_rating(5); --illegal reference + + END; + + PROCEDURE calc_rating(5) + IS + BEGIN + ... + END; + +END forward_pack; +/ \ No newline at end of file diff --git a/FUNCTION_EMAIL_VALIDATION.fnc b/FUNCTION_EMAIL_VALIDATION.fnc new file mode 100644 index 0000000..da60ae2 --- /dev/null +++ b/FUNCTION_EMAIL_VALIDATION.fnc @@ -0,0 +1,75 @@ +/* Formatted on 28/Oct/21 11:51:07 AM (QP5 v5.287) */ +CREATE OR REPLACE FUNCTION email_validation (email_address IN VARCHAR2) + RETURN VARCHAR2 +IS + at_the_rate NUMBER; + dot_symbol NUMBER; + c_at_the_rate NUMBER; + c_dot_symbol NUMBER; + string_length NUMBER; + before_dot NUMBER; + temp NUMBER; + after_dot NUMBER; + undefine_symbol NUMBER; +BEGIN + -- domain := INSTR (email_address, 'com'or '.in'or'.bd'or '.gov'or '.org'); + at_the_rate := INSTR (email_address, '@'); + dot_symbol := INSTR (email_address, '.'); + string_length := LENGTH (email_address); + c_at_the_rate := + ROUND (LENGTH (email_address) - LENGTH (REPLACE (email_address, '@'))); + c_dot_symbol := + ROUND (LENGTH (email_address) - LENGTH (REPLACE (email_address, '.'))); + -- after_at_the_rate := at_the_rate+1; + before_dot := INSTR (email_address, '.'); + after_dot := INSTR (email_address, '.'); + temp := dot_symbol; + DBMS_OUTPUT.put_line ('TEMP' || ' : ' || temp); + undefine_symbol := + INSTR (email_address, '!') + || INSTR (email_address, '/') + || INSTR (email_address, '#') + || INSTR (email_address, '%') + || INSTR (email_address, '$') + || INSTR (email_address, '^') + || INSTR (email_address, '&') + || INSTR (email_address, '*') + || INSTR (email_address, '(') + || INSTR (email_address, '(') + || INSTR (email_address, '-') + || INSTR (email_address, '+') + || INSTR (email_address, '=') + || INSTR (email_address, '`') + || INSTR (email_address, '~') + || INSTR (email_address, '?') + || INSTR (email_address, '{') + || INSTR (email_address, '}') + || INSTR (email_address, '[') + || INSTR (email_address, ']') + || INSTR (email_address, '\') + || INSTR (email_address, '|') + || INSTR (email_address, '"') + || INSTR (email_address, ':') + || INSTR (email_address, ';') + || INSTR (email_address, ']') + || INSTR (email_address, '[') + || INSTR (email_address, '?') + || INSTR (email_address, '>') + || INSTR (email_address, '<') + || INSTR (email_address, ',') + || INSTR (email_address, '..') + || INSTR (email_address, '.@') + || INSTR (email_address, '@.'); + DBMS_OUTPUT.put_line (before_dot || ' AND ' || after_dot); + IF ( ( (dot_symbol = 0) + OR (at_the_rate = 0) + OR (undefine_symbol >= 1) + OR (at_the_rate = 1) + OR (c_at_the_rate > 1) + OR (at_the_rate = string_length) + OR (dot_symbol = string_length))) + THEN + RETURN 'Invalid email addresses'; + END IF; + RETURN 'Valid email addresses'; +END email_validation; \ No newline at end of file diff --git a/LOG_IN.fnc b/LOG_IN.fnc new file mode 100644 index 0000000..c0c4bd8 --- /dev/null +++ b/LOG_IN.fnc @@ -0,0 +1,22 @@ +/* Formatted on 04/Jan/22 12:36:03 PM (QP5 v5.287) */ +CREATE OR REPLACE FUNCTION log_in (x IN VARCHAR2, y IN VARCHAR2) + RETURN VARCHAR2 +AS + check_count NUMBER; +BEGIN + SELECT COUNT (*) + INTO check_count + FROM employees + WHERE first_name = x AND last_name = y; + + IF check_count = 0 + THEN + RETURN 'Wrong username or password!'; + ELSIF check_count = 1 + THEN + RETURN 'Login successful!'; + ELSE + RETURN 'Too many matches, this should never happen!'; + END IF; +END; +/ \ No newline at end of file diff --git a/LOG_INN.prc b/LOG_INN.prc new file mode 100644 index 0000000..b1774ae --- /dev/null +++ b/LOG_INN.prc @@ -0,0 +1,21 @@ +CREATE OR REPLACE procedure log_inn (x IN VARCHAR2, y IN VARCHAR2) + +AS + check_count NUMBER; +BEGIN + SELECT COUNT (*) + INTO check_count + FROM employees + WHERE first_name = x AND last_name = y; + + IF check_count = 0 + THEN + dbms_output.put_line( 'Wrong username or password!'); + ELSIF check_count = 1 + THEN +dbms_output.put_line( 'Login successful!'); + ELSE + dbms_output.put_line( 'Too many matches, this should never happen!'); + END IF; +END; +/ \ No newline at end of file diff --git a/New 1.sql b/New 1.sql new file mode 100644 index 0000000..d795981 --- /dev/null +++ b/New 1.sql @@ -0,0 +1 @@ +SELECT * FROM EMPLOYEE; \ No newline at end of file diff --git a/New 2.sql b/New 2.sql new file mode 100644 index 0000000..ae00f98 --- /dev/null +++ b/New 2.sql @@ -0,0 +1 @@ +SELECT * FROM t_emp_table ; \ No newline at end of file diff --git a/New 3.sql b/New 3.sql new file mode 100644 index 0000000..b61cd94 --- /dev/null +++ b/New 3.sql @@ -0,0 +1,12 @@ +DECLARE + CURSOR emp_cursor IS + SELECT employee_id, last_name, department_name + FROM employees,departments + WHERE employees.department_id = + departments.department_id + AND employees.department_id = 80 + FOR UPDATE OF salary NOWAIT; +BEGIN + OPEN emp_cursor ; + CLOSE emp_cursor; +END; diff --git a/PACKAGE_ADV 02.pkb b/PACKAGE_ADV 02.pkb new file mode 100644 index 0000000..125cb01 --- /dev/null +++ b/PACKAGE_ADV 02.pkb @@ -0,0 +1,74 @@ +/* Formatted on 21-Nov-21 11:11:35 AM (QP5 v5.287) */ +CREATE OR REPLACE PACKAGE BODY package_adv +IS + e_sal EMPLOYEE.salary%TYPE; + e_eid EMPLOYEE.employee_id%TYPE; + e_ln EMPLOYEE.last_Name%TYPE; + e_jid EMPLOYEE.job_id%TYPE; + + PROCEDURE e_salary (e_id EMPLOYEE.EMPLOYEE_ID%TYPE) + IS + BEGIN + SELECT salary + INTO e_sal + FROM employee + WHERE employee_id = e_id; + + DBMS_OUTPUT.put_line (e_Sal); + END e_salary; + + PROCEDURE e_all (e_eeid EMPLOYEE.EMPLOYEE_ID%TYPE) + IS + BEGIN + SELECT * + INTO e_eid, + e_ln, + e_jid, + e_sal + FROM employee + WHERE employee_id = e_eeid; + + DBMS_OUTPUT.put_line (e_eid || + e_ln || + e_jid || + e_sal); + END e_all; + /* IS | AS + variable declarations; + constant declarations; + BEGIN + statement(s); + EXCEPTION + WHEN ... + END + ] +[PROCEDURE [Schema..] procedure_name + [ (parameter [,parameter]) ] + IS | AS + variable declarations; + constant declarations; + BEGIN + statement(s); + EXCEPTION + WHEN ... + END + ] + [FUNCTION [Schema..] function_name + [ (parameter [,parameter]) ] + RETURN return_datatype + IS | AS + variable declarations; + constant declarations; + BEGIN + statement(s); + EXCEPTION + WHEN ... + END + ] + [EXCEPTION + WHEN built-in_exception_name_1 THEN + User defined statement (action) will be taken; + ] + */ +END; +/ \ No newline at end of file diff --git a/PACKAGE_ADV.pkb b/PACKAGE_ADV.pkb new file mode 100644 index 0000000..f12ecaf --- /dev/null +++ b/PACKAGE_ADV.pkb @@ -0,0 +1,48 @@ +CREATE OR REPLACE PACKAGE BODY package_adv + IS + + PROCEDURE e_salary( e_id EMPLOYEE.EMPLOYEE_ID%TYPE) + IS + BEGIN + DELETE FROM employee + WHERE employee_id = e_id; + END e_salary; + /* IS | AS + variable declarations; + constant declarations; + BEGIN + statement(s); + EXCEPTION + WHEN ... + END + ] +[PROCEDURE [Schema..] procedure_name + [ (parameter [,parameter]) ] + IS | AS + variable declarations; + constant declarations; + BEGIN + statement(s); + EXCEPTION + WHEN ... + END + ] + [FUNCTION [Schema..] function_name + [ (parameter [,parameter]) ] + RETURN return_datatype + IS | AS + variable declarations; + constant declarations; + BEGIN + statement(s); + EXCEPTION + WHEN ... + END + ] + [EXCEPTION + WHEN built-in_exception_name_1 THEN + User defined statement (action) will be taken; + ] + */ +END; +/ \ No newline at end of file diff --git a/PACKAGE_ADV.pks b/PACKAGE_ADV.pks new file mode 100644 index 0000000..d8e8b1e --- /dev/null +++ b/PACKAGE_ADV.pks @@ -0,0 +1,19 @@ +CREATE OR REPLACE +PACKAGE package_adv + IS + PROCEDURE e_salary( e_id EMPLOYEE.EMPLOYEE_ID%TYPE); + + -- [variable_declaration ...] + -- [constant_declaration ...] + --[exception_declaration ...] + -- [cursor_specification ...] + /* [PROCEDURE [Schema..] procedure_name + [ (parameter {IN,OUT,IN OUT} datatype [,parameter]) ] + ] + [FUNCTION [Schema..] function_name + [ (parameter {IN,OUT,IN OUT} datatype [,parameter]) ] + RETURN return_datatype + ] + */ + +END package_adv; \ No newline at end of file diff --git a/PACKAGE_ADV02.pkb b/PACKAGE_ADV02.pkb new file mode 100644 index 0000000..5cb1aaa --- /dev/null +++ b/PACKAGE_ADV02.pkb @@ -0,0 +1,52 @@ +CREATE OR REPLACE PACKAGE BODY package_adv + IS + e_sal EMPLOYEE.salary%TYPE; + + PROCEDURE e_salary( e_id EMPLOYEE.EMPLOYEE_ID%TYPE) + IS + BEGIN + SELECT salary + INto e_sal + FROM employee + WHERE employee_id = e_id; + dbms_output.put_line(e_Sal); + END e_salary; + /* IS | AS + variable declarations; + constant declarations; + BEGIN + statement(s); + EXCEPTION + WHEN ... + END + ] +[PROCEDURE [Schema..] procedure_name + [ (parameter [,parameter]) ] + IS | AS + variable declarations; + constant declarations; + BEGIN + statement(s); + EXCEPTION + WHEN ... + END + ] + [FUNCTION [Schema..] function_name + [ (parameter [,parameter]) ] + RETURN return_datatype + IS | AS + variable declarations; + constant declarations; + BEGIN + statement(s); + EXCEPTION + WHEN ... + END + ] + [EXCEPTION + WHEN built-in_exception_name_1 THEN + User defined statement (action) will be taken; + ] + */ +END; +/ \ No newline at end of file diff --git a/PACKAGE_ADV02.pks b/PACKAGE_ADV02.pks new file mode 100644 index 0000000..8ac0d33 --- /dev/null +++ b/PACKAGE_ADV02.pks @@ -0,0 +1,19 @@ +CREATE OR REPLACE +PACKAGE package_adv + IS + PROCEDURE e_salary( e_id EMPLOYEE.EMPLOYEE_ID%TYPE); + PROCEDURE e_all( e_eeid EMPLOYEE.EMPLOYEE_ID%TYPE); + -- [variable_declaration ...] + -- [constant_declaration ...] + --[exception_declaration ...] + -- [cursor_specification ...] + /* [PROCEDURE [Schema..] procedure_name + [ (parameter {IN,OUT,IN OUT} datatype [,parameter]) ] + ] + [FUNCTION [Schema..] function_name + [ (parameter {IN,OUT,IN OUT} datatype [,parameter]) ] + RETURN return_datatype + ] + */ + +END package_adv; \ No newline at end of file diff --git a/PL SQL HR.ADD_DEPT.prc b/PL SQL HR.ADD_DEPT.prc new file mode 100644 index 0000000..a6bcfdb --- /dev/null +++ b/PL SQL HR.ADD_DEPT.prc @@ -0,0 +1,9 @@ +BEGIN + add_dept; + add_dept ('TRAINING', 2500); + add_dept ( p_loc => 2400, p_name =>'EDUCATION'); + add_dept ( p_loc => 1200) ; +END; +/ +SELECT department_id, department_name, location_id +FROM departments; diff --git a/PL SQL QUERY_EMP.prc b/PL SQL QUERY_EMP.prc new file mode 100644 index 0000000..8583178 --- /dev/null +++ b/PL SQL QUERY_EMP.prc @@ -0,0 +1,13 @@ +CREATE OR REPLACE PROCEDURE query_emp + (p_id IN employees.employee_id%TYPE, + p_name OUT employees.last_name%TYPE, + p_salary OUT employees.salary%TYPE, + p_comm OUT employees.commission_pct%TYPE) +IS +BEGIN + SELECT last_name, salary, commission_pct + INTO p_name, p_salary, p_comm + FROM employees + WHERE employee_id = p_id; +END query_emp; +/ diff --git a/PLSQL 12 Message.sql b/PLSQL 12 Message.sql new file mode 100644 index 0000000..ee354ae --- /dev/null +++ b/PLSQL 12 Message.sql @@ -0,0 +1,17 @@ +DECLARE + v_sal NUMBER(7,2) := 60000; + v_comm NUMBER(7,2) := v_sal * 0.20; + v_message VARCHAR2(255) := ' eligible for commission'; +BEGIN + DECLARE + v_sal NUMBER(7,2) := 50000; + v_comm NUMBER(7,2) := 0; + v_total_comp NUMBER(7,2) := v_sal + v_comm; + BEGIN + v_message := 'CLERK not'||v_message; + v_comm := v_sal * 0.30; + + END; + v_message := 'SALESMAN'||v_message; + +END; diff --git a/PLSQL ADD_DEPT.prc b/PLSQL ADD_DEPT.prc new file mode 100644 index 0000000..01ebc08 --- /dev/null +++ b/PLSQL ADD_DEPT.prc @@ -0,0 +1,12 @@ +CREATE OR REPLACE PROCEDURE add_dept + (p_name IN departments.department_name%TYPE + DEFAULT 'unknown', + p_loc IN departments.location_id%TYPE + DEFAULT 1700) +IS +BEGIN + INSERT INTO departments(department_id, + department_name, location_id) + VALUES (departments_seq.NEXTVAL, p_name, p_loc); +END add_dept; +/ diff --git a/PLSQL BFILE 02.sql b/PLSQL BFILE 02.sql new file mode 100644 index 0000000..8c47241 --- /dev/null +++ b/PLSQL BFILE 02.sql @@ -0,0 +1,15 @@ +/* Formatted on 25/Oct/21 10:45:43 PM (QP5 v5.287) */ +CREATE OR REPLACE PROCEDURE load_emp_bfile (p_file_loc IN VARCHAR2) +IS + v_file BFILE; + v_filename VARCHAR2 (16); + v_file_exists BOOLEAN; + + CURSOR emp_cursor IS +BEGIN + FOR emp_record IN emp_cursor LOOP + v_filename := emp_record.first_name || '.bmp'; + v_file := BFILENAME (p_file_loc, v_filename); + v_file_exists := (DBMS_LOB.FILEEXISTS(v_file) = 1); + IF v_file_exists THEN + DBMS_LOB.FILEOPEN (v_file); \ No newline at end of file diff --git a/PLSQL BFILE.prc b/PLSQL BFILE.prc new file mode 100644 index 0000000..da40291 --- /dev/null +++ b/PLSQL BFILE.prc @@ -0,0 +1,15 @@ +/* Formatted on 25/Oct/21 10:34:56 PM (QP5 v5.287) */ +CREATE OR REPLACE PROCEDURE load_emp_bfile +(p_file_loc IN VARCHAR2) +IS + v_file BFILE; v_filename VARCHAR2(16); + v_file_exists BOOLEAN; + CURSOR emp_cursor IS +BEGIN + FOR emp_record IN emp_cursor LOOP + v_filename := emp_record.first_name || '.bmp'; + v_file := BFILENAME (p_file_loc, v_filename); + v_file_exists := (DBMS_LOB.FILEEXISTS(v_file) = 1); + IF v_file_exists THEN + DBMS_LOB.FILEOPEN (v_file); +END; \ No newline at end of file diff --git a/PLSQL BLOB CLOB ALTER.sql b/PLSQL BLOB CLOB ALTER.sql new file mode 100644 index 0000000..b28d1bd --- /dev/null +++ b/PLSQL BLOB CLOB ALTER.sql @@ -0,0 +1,3 @@ +ALTER TABLE employees ADD + (resume CLOB, + picture BLOB); diff --git a/PLSQL BLOB CLOB INSERT.sql b/PLSQL BLOB CLOB INSERT.sql new file mode 100644 index 0000000..6c9eddc --- /dev/null +++ b/PLSQL BLOB CLOB INSERT.sql @@ -0,0 +1,2 @@ +INSERT INTO employees (employee_id, first_name,last_name, email, hire_date, job_id, salary, resume, picture) +VALUES (405, 'Marvin', 'Ellis', 'MELLIS', SYSDATE, 'AD_ASST', 4000, EMPTY_CLOB(),NULL); diff --git a/PLSQL BLOB CLOB UPDATE.sql b/PLSQL BLOB CLOB UPDATE.sql new file mode 100644 index 0000000..ce97d04 --- /dev/null +++ b/PLSQL BLOB CLOB UPDATE.sql @@ -0,0 +1,4 @@ +UPDATE employees +SET resume = 'Date of Birth: 8 February 1951', + picture = EMPTY_BLOB() +WHERE employee_id = 405; diff --git a/PLSQL Bio.sql b/PLSQL Bio.sql new file mode 100644 index 0000000..8ee3527 --- /dev/null +++ b/PLSQL Bio.sql @@ -0,0 +1,23 @@ +DECLARE + name varchar2(20); + company varchar2(30); + introduction clob; + choice char(1); + hiredate varchar2(20); + details clob; +BEGIN + name := 'A. S. M. Radwan'; + company := 'ERA Infotech Limited'; + introduction := ' Hello! I''m A. S. M. Radwan from Infotech.'; + hiredate := '10th June 1998'; + details := 'You have not put your details yet.'; + choice := 'y'; + IF choice = 'y' THEN + dbms_output.put_line(name); + dbms_output.put_line(company); + dbms_output.put_line(introduction); + dbms_output.put_line(hiredate); + dbms_output.put_line(details); + END IF; +END; +/ \ No newline at end of file diff --git a/PLSQL CLOB DML.sql b/PLSQL CLOB DML.sql new file mode 100644 index 0000000..6a0e31b --- /dev/null +++ b/PLSQL CLOB DML.sql @@ -0,0 +1,3 @@ +SELECT employee_id, last_name , resume -- CLOB +FROM employees +WHERE employee_id IN (405, 170); diff --git a/PLSQL COMMIT JOB NUMBER.prc b/PLSQL COMMIT JOB NUMBER.prc new file mode 100644 index 0000000..279cd7c --- /dev/null +++ b/PLSQL COMMIT JOB NUMBER.prc @@ -0,0 +1,12 @@ +VARIABLE jobno NUMBER +BEGIN + DBMS_JOB.SUBMIT ( + job => :jobno, + what => 'OVER_PACK.ADD_DEPT(''EDUCATION'',2710);', + next_date => TRUNC(SYSDATE + 1), + interval => 'TRUNC(SYSDATE + 1)' + ); + COMMIT; +END; +/ +PRINT jobno diff --git a/PLSQL CREATE OR REPLACE FUNCTION TAX.fnc b/PLSQL CREATE OR REPLACE FUNCTION TAX.fnc new file mode 100644 index 0000000..7245fd9 --- /dev/null +++ b/PLSQL CREATE OR REPLACE FUNCTION TAX.fnc @@ -0,0 +1,14 @@ +/* Formatted on 25-Oct-21 3:27:30 AM (QP5 v5.287) */ +CREATE OR REPLACE FUNCTION tax (p_value IN NUMBER) + RETURN NUMBER +IS +BEGIN + RETURN (p_value * 0.08); +END tax; +/ +SELECT employee_id, + last_name, + salary, + tax (salary) + FROM employees + WHERE department_id = 100; \ No newline at end of file diff --git a/PLSQL CURSOR 02.sql b/PLSQL CURSOR 02.sql new file mode 100644 index 0000000..e6496ac --- /dev/null +++ b/PLSQL CURSOR 02.sql @@ -0,0 +1,13 @@ + DECLARE + v_empno employees.employee_id%TYPE; + v_ename employees.last_name%TYPE; + CURSOR emp_cursor IS + SELECT employee_id, last_name + FROM employees; + BEGIN + OPEN emp_cursor; + FOR i IN 1..10 LOOP + FETCH emp_cursor INTO v_empno, v_ename; + DBMS_OUTPUT.PUT_LINE (TO_CHAR(v_empno)||' '|| v_ename); + END LOOP; + END ; \ No newline at end of file diff --git a/PLSQL CURSOR 13.sql b/PLSQL CURSOR 13.sql new file mode 100644 index 0000000..63fcef1 --- /dev/null +++ b/PLSQL CURSOR 13.sql @@ -0,0 +1,12 @@ +DECLARE + CURSOR emp_cursor + (p_deptno NUMBER, p_job VARCHAR2) IS + SELECT employee_id, last_name + FROM employees + WHERE department_id = p_deptno + AND job_id = p_job; +BEGIN + OPEN emp_cursor (80, 'SA_REP'); + CLOSE emp_cursor; + OPEN emp_cursor (60, 'IT_PROG'); +END; diff --git a/PLSQL DBMS LOB SUBSTR INSTR.sql b/PLSQL DBMS LOB SUBSTR INSTR.sql new file mode 100644 index 0000000..1325ee2 --- /dev/null +++ b/PLSQL DBMS LOB SUBSTR INSTR.sql @@ -0,0 +1,4 @@ +SELECT DBMS_LOB.SUBSTR (resume, 5, 18), + DBMS_LOB.INSTR (resume,' = ') +FROM employees +WHERE employee_id IN (170, 405); diff --git a/PLSQL DBMS OUTPUT EXECUTION.pkb b/PLSQL DBMS OUTPUT EXECUTION.pkb new file mode 100644 index 0000000..123fa37 --- /dev/null +++ b/PLSQL DBMS OUTPUT EXECUTION.pkb @@ -0,0 +1,9 @@ +CREATE OR REPLACE PACKAGE global_consts IS + mile_2_kilo CONSTANT NUMBER := 1.6093; + kilo_2_mile CONSTANT NUMBER := 0.6214; + yard_2_meter CONSTANT NUMBER := 0.9144; + meter_2_yard CONSTANT NUMBER := 1.0936; +END global_consts; +/ + +EXECUTE DBMS_OUTPUT.PUT_LINE('20 miles = '||20* global_consts.mile_2_kilo||' km') diff --git a/PLSQL DBMSOutput Resume.txt b/PLSQL DBMSOutput Resume.txt new file mode 100644 index 0000000..fcbca38 --- /dev/null +++ b/PLSQL DBMSOutput Resume.txt @@ -0,0 +1,6 @@ +text is: +text is: +text is: +text is: +text is: +Radwan diff --git a/PLSQL DEL NUMBER.prc b/PLSQL DEL NUMBER.prc new file mode 100644 index 0000000..3e5c2c7 --- /dev/null +++ b/PLSQL DEL NUMBER.prc @@ -0,0 +1,3 @@ +VARIABLE deleted NUMBER +EXECUTE del_rows('test_employees',:deleted) +PRINT deleted diff --git a/PLSQL DELETE _.prc b/PLSQL DELETE _.prc new file mode 100644 index 0000000..4251958 --- /dev/null +++ b/PLSQL DELETE _.prc @@ -0,0 +1,3 @@ +VARIABLE deleted NUMBER +EXECUTE delete_all_rows('employees', :deleted) +PRINT deleted diff --git a/PLSQL DESCRIBE.prc b/PLSQL DESCRIBE.prc new file mode 100644 index 0000000..e690ef3 --- /dev/null +++ b/PLSQL DESCRIBE.prc @@ -0,0 +1,3 @@ +DESCRIBE query_employee +DESCRIBE add_dept +DESCRIBE tax diff --git a/PLSQL Exception Handling.sql b/PLSQL Exception Handling.sql new file mode 100644 index 0000000..efd2cd8 --- /dev/null +++ b/PLSQL Exception Handling.sql @@ -0,0 +1,58 @@ +/* Formatted on 27/Oct/21 12:21:41 PM (QP5 v5.287) */ +DECLARE + v_variable VARCHAR2 (100); + v_eid employees.employee_id%TYPE; + v_dptid departments.department_id%TYPE := 90; +BEGIN + SELECT e.last_name, e.department_id, e.employee_id + INTO v_variable, v_dptid, v_eid + FROM employees e, departments d + WHERE d.department_id = e.department_id + AND e.department_id = v_dptid + AND e.employee_id = v_eid; + + DBMS_OUTPUT.put_line ( + 'Empolyee ID: ' + || v_eid + || ' And The Name Of The Employee Is: ' + || v_variable + || ' Department ID Is: ' + || v_dptid); +EXCEPTION + WHEN TOO_MANY_ROWS + THEN + v_eid := 101; + DBMS_OUTPUT.put_line ( + 'Too many rows found that why we take on specific employee id'); + DBMS_OUTPUT.put_line ( + 'Empolyee ID: ' + || v_eid + || ' And The Name Of The Employee Is: ' + || v_variable + || ' Department ID Is: ' + || v_dptid); + WHEN NO_DATA_FOUND + THEN + v_eid := 101; + v_dptid := 90; + + SELECT e.last_name, e.department_id, e.employee_id + INTO v_variable, v_dptid, v_eid + FROM employees e, departments d + WHERE d.department_id = e.department_id + AND e.department_id = v_dptid + AND e.employee_id = v_eid; + + DBMS_OUTPUT.put_line ('No citizen detail found'); + DBMS_OUTPUT.put_line ( + 'Empolyee ID: ' + || v_eid + || ' And The Name Of The Employee Is: ' + || v_variable + || ' Department ID Is: ' + || v_dptid); + WHEN OTHERS + THEN + DBMS_OUTPUT.put_line ('Empolyee ID: ' || v_eid || ' ' || v_variable); +END; +/ \ No newline at end of file diff --git a/PLSQL Functions.sql b/PLSQL Functions.sql new file mode 100644 index 0000000..4e77e73 --- /dev/null +++ b/PLSQL Functions.sql @@ -0,0 +1,23 @@ +DECLARE + a number; + b number; + c number; +FUNCTION findMax(x IN number, y IN number) +RETURN number +IS + z number; +BEGIN + IF x > y THEN + z:= x; + ELSE + Z:= y; + END IF; + RETURN z; +END; +BEGIN + a:= 23; + b:= 45; + c := findMax(a, b); + dbms_output.put_line(' Maximum of (23,45): ' || c); +END; +/ \ No newline at end of file diff --git a/PLSQL GET_SAL.fnc b/PLSQL GET_SAL.fnc new file mode 100644 index 0000000..d8a1d65 --- /dev/null +++ b/PLSQL GET_SAL.fnc @@ -0,0 +1,14 @@ +/* Formatted on 25/Oct/21 3:14:41 AM (QP5 v5.287) */ +CREATE OR REPLACE FUNCTION get_sal (p_id IN employees.employee_id%TYPE) + RETURN NUMBER +IS + v_salary employees.salary%TYPE := 0; +BEGIN + SELECT salary + INTO v_salary + FROM employees + WHERE employee_id = p_id; + + RETURN v_salary; +END get_sal; +/ \ No newline at end of file diff --git a/PLSQL ISTEMPLOBOPEN.prc b/PLSQL ISTEMPLOBOPEN.prc new file mode 100644 index 0000000..331ae5a --- /dev/null +++ b/PLSQL ISTEMPLOBOPEN.prc @@ -0,0 +1,15 @@ +/* Formatted on 26-Oct-21 3:15:06 AM (QP5 v5.287) */ +CREATE OR REPLACE PROCEDURE IsTempLOBOpen (p_lob_loc IN OUT BLOB, + p_retval OUT INTEGER) +IS +BEGIN + -- create a temporary LOB + DBMS_LOB.CREATETEMPORARY (p_lob_loc, TRUE); + -- see if the LOB is open: returns 1 if open + p_retval := DBMS_LOB.ISOPEN (p_lob_loc); + DBMS_OUTPUT.PUT_LINE ( + 'The file returned a value ....' || p_retval); + -- free the temporary LOB + DBMS_LOB.FREETEMPORARY (p_lob_loc); +END; +/ \ No newline at end of file diff --git a/PLSQL Inner Outter Loop.sql b/PLSQL Inner Outter Loop.sql new file mode 100644 index 0000000..5d4a4cc --- /dev/null +++ b/PLSQL Inner Outter Loop.sql @@ -0,0 +1,16 @@ +/* Formatted on 24-Oct-21 11:49:38 PM (QP5 v5.287) */ +DECLARE + i NUMBER (1); + j NUMBER (1); +BEGIN + <> + FOR i IN 1 .. 3 + LOOP + <> + FOR j IN 1 .. 3 + LOOP + DBMS_OUTPUT.put_line ('i is: ' || i || ' and j is: ' || j); + END LOOP inner_loop; + END LOOP outer_loop; +END; +/ \ No newline at end of file diff --git a/PLSQL LEAVE_EMP2.prc b/PLSQL LEAVE_EMP2.prc new file mode 100644 index 0000000..7eaad8c --- /dev/null +++ b/PLSQL LEAVE_EMP2.prc @@ -0,0 +1,15 @@ +CREATE OR REPLACE PROCEDURE leave_emp2 + (p_id IN employees.employee_id%TYPE) +IS + PROCEDURE log_exec + IS + BEGIN + INSERT INTO log_table (user_id, log_date) + VALUES (USER, SYSDATE); + END log_exec; +BEGIN + DELETE FROM employees + WHERE employee_id = p_id; + log_exec; +END leave_emp2; +/ diff --git a/PLSQL PACK CUR.pkb b/PLSQL PACK CUR.pkb new file mode 100644 index 0000000..21974f4 --- /dev/null +++ b/PLSQL PACK CUR.pkb @@ -0,0 +1,9 @@ + CREATE OR REPLACE PACKAGE pack_cur +IS + CURSOR c1 IS SELECT employee_id + FROM employees + ORDER BY employee_id DESC; + PROCEDURE proc1_3rows; + PROCEDURE proc4_6rows; + END pack_cur; +/ diff --git a/PLSQL PROCEDURE QUERY EMP.prc b/PLSQL PROCEDURE QUERY EMP.prc new file mode 100644 index 0000000..3f3dfcd --- /dev/null +++ b/PLSQL PROCEDURE QUERY EMP.prc @@ -0,0 +1,4 @@ +SELECT * +FROM user_source +WHERE name = 'QUERY_EMPLOYEE' +ORDER BY line; diff --git a/PLSQL Package.prc b/PLSQL Package.prc new file mode 100644 index 0000000..3298b43 --- /dev/null +++ b/PLSQL Package.prc @@ -0,0 +1,8 @@ +/* Formatted on 25-Oct-21 4:06:12 AM (QP5 v5.287) */ +CREATE OR REPLACE PACKAGE comm_package +IS + g_comm NUMBER := 0.10; --initialized to 0.10 + + PROCEDURE reset_comm (p_comm IN NUMBER); +END comm_package; +/ \ No newline at end of file diff --git a/PLSQL Problem Solving/binary/.exercism/config.json b/PLSQL Problem Solving/binary/.exercism/config.json new file mode 100644 index 0000000..a0b3ee4 --- /dev/null +++ b/PLSQL Problem Solving/binary/.exercism/config.json @@ -0,0 +1,19 @@ +{ + "blurb": "Convert a binary number, represented as a string (e.g. '101010'), to its decimal equivalent using first principles", + "authors": [ + "chezwicker" + ], + "files": { + "solution": [ + "ut_binary#.plsql" + ], + "test": [ + "ut_binary#.plsql" + ], + "example": [ + ".meta/example.plsql" + ] + }, + "source": "All of Computer Science", + "source_url": "http://www.wolframalpha.com/input/?i=binary&a=*C.binary-_*MathWorld-" +} diff --git a/PLSQL Problem Solving/binary/.exercism/metadata.json b/PLSQL Problem Solving/binary/.exercism/metadata.json new file mode 100644 index 0000000..69cdeb2 --- /dev/null +++ b/PLSQL Problem Solving/binary/.exercism/metadata.json @@ -0,0 +1 @@ +{"track":"plsql","exercise":"binary","id":"d3911cb8dcdf4a3f89eaf8751040af78","url":"https://exercism.org/tracks/plsql/exercises/binary","handle":"radwanromy","is_requester":true,"auto_approve":false} \ No newline at end of file diff --git a/PLSQL Problem Solving/binary/HELP.md b/PLSQL Problem Solving/binary/HELP.md new file mode 100644 index 0000000..cbc17c1 --- /dev/null +++ b/PLSQL Problem Solving/binary/HELP.md @@ -0,0 +1,34 @@ +# Help + +## Running the tests + +Execute the tests by calling the `run` method in the respective `ut_#` package, +where `` is replaced with the exercise name. + +## Submitting your solution + +You can submit your solution using the `exercism submit ut_binary#.plsql` command. +This command will upload your solution to the Exercism website and print the solution page's URL. + +It's possible to submit an incomplete solution which allows you to: + +- See how others have completed the exercise +- Request help from a mentor + +## Need to get help? + +If you'd like help solving the exercise, check the following pages: + +- The [PL/SQL track's documentation](https://exercism.org/docs/tracks/plsql) +- [Exercism's support channel on gitter](https://gitter.im/exercism/support) +- The [Frequently Asked Questions](https://exercism.org/docs/using/faqs) + +Should those resources not suffice, you could submit your (incomplete) solution to request mentoring. + +To get help if you're having trouble, you can use one of the following resources: + +- [Oracle - PL/SQL Language Reference](http://docs.oracle.com/cd/E11882_01/appdev.112/e25519/toc.htm) +- [Builtin Function Reference](http://psoug.org/reference/builtin_functions.html) +- [Ask Tom](https://asktom.oracle.com/) - Advice by the PL/SQL Guru +- [/r/plsql](https://www.reddit.com/r/plsql) is the C# subreddit. +- [StackOverflow](http://stackoverflow.com/questions/tagged/plsql) can be used to search for your problem and see if it has been answered already. You can also ask and answer questions. \ No newline at end of file diff --git a/PLSQL Problem Solving/binary/README.md b/PLSQL Problem Solving/binary/README.md new file mode 100644 index 0000000..1218094 --- /dev/null +++ b/PLSQL Problem Solving/binary/README.md @@ -0,0 +1,46 @@ +# Binary + +Welcome to Binary on Exercism's PL/SQL Track. +If you need help running the tests or submitting your code, check out `HELP.md`. + +## Instructions + +Convert a binary number, represented as a string (e.g. '101010'), to its decimal equivalent using first principles. + +Implement binary to decimal conversion. Given a binary input +string, your program should produce a decimal output. The +program should handle invalid inputs. + +## Note + +- Implement the conversion yourself. + Do not use something else to perform the conversion for you. + +## About Binary (Base-2) + +Decimal is a base-10 system. + +A number 23 in base 10 notation can be understood +as a linear combination of powers of 10: + +- The rightmost digit gets multiplied by 10^0 = 1 +- The next number gets multiplied by 10^1 = 10 +- ... +- The *n*th number gets multiplied by 10^*(n-1)*. +- All these values are summed. + +So: `23 => 2*10^1 + 3*10^0 => 2*10 + 3*1 = 23 base 10` + +Binary is similar, but uses powers of 2 rather than powers of 10. + +So: `101 => 1*2^2 + 0*2^1 + 1*2^0 => 1*4 + 0*2 + 1*1 => 4 + 1 => 5 base 10`. + +## Source + +### Created by + +- @chezwicker + +### Based on + +All of Computer Science - http://www.wolframalpha.com/input/?i=binary&a=*C.binary-_*MathWorld- \ No newline at end of file diff --git a/PLSQL Problem Solving/binary/ut_binary#.plsql b/PLSQL Problem Solving/binary/ut_binary#.plsql new file mode 100644 index 0000000..a0d22b2 --- /dev/null +++ b/PLSQL Problem Solving/binary/ut_binary#.plsql @@ -0,0 +1,99 @@ +/**/ +create or replace package ut_binary# +is + procedure run; +end ut_binary#; +/ + +/**/ +/* Formatted on 22/Nov/21 11:08:55 AM (QP5 v5.287) */ +CREATE OR REPLACE PACKAGE BODY ut_binary# +IS + FUNCTION to_decimal (binary_string VARCHAR2) + RETURN INTEGER + AS + num_string VARCHAR2 (32000 CHAR) := binary_string; + decimal_num INTEGER := 0; + current_char CHAR (1); + BEGIN + FOR counter IN 1 .. LENGTH (num_string) + LOOP + current_char := SUBSTR (num_string, LENGTH (num_string), 1); + + IF (current_char != '0' AND current_char != '1') + THEN + decimal_num := 0; + EXIT; + END IF; + + decimal_num := + decimal_num + TO_NUMBER (current_char) * POWER (10, counter - 1); + num_string := SUBSTR (num_string, 0, LENGTH (num_string) - 1); + END LOOP; + + RETURN decimal_num; + END to_decimal; + + PROCEDURE test (i_descn VARCHAR2, i_exp PLS_INTEGER, i_act PLS_INTEGER) + IS + BEGIN + IF i_exp = i_act + THEN + DBMS_OUTPUT.put_line ('SUCCESS: ' || i_descn); + ELSE + DBMS_OUTPUT.put_line ( + 'FAILURE: ' + || i_descn + || ' - expected ' + || NVL ('' || i_exp, 'null') + || ', but received ' + || NVL ('' || i_act, 'null')); + END IF; + END test; + + PROCEDURE run + IS + BEGIN + test (i_descn => 'test_binary_1_is_decimal_1', + i_exp => 1, + i_act => ut_binary#.to_decimal ('1')); + test (i_descn => 'test_binary_10_is_decimal_2', + i_exp => 2, + i_act => ut_binary#.to_decimal ('10')); + test (i_descn => 'test_binary_11_is_decimal_3', + i_exp => 3, + i_act => ut_binary#.to_decimal ('11')); + test (i_descn => 'test_binary_100_is_decimal_4', + i_exp => 4, + i_act => ut_binary#.to_decimal ('100')); + test (i_descn => 'test_binary_1001_is_decimal_9', + i_exp => 9, + i_act => ut_binary#.to_decimal ('1001')); + test (i_descn => 'test_binary_11010_is_decimal_26', + i_exp => 26, + i_act => ut_binary#.to_decimal ('11010')); + test (i_descn => 'test_binary_10001101000_is_decimal_1128', + i_exp => 1128, + i_act => ut_binary#.to_decimal ('10001101000')); + test (i_descn => 'test_invalid_binary_postfix_is_decimal_0', + i_exp => 0, + i_act => ut_binary#.to_decimal ('10110a')); + test (i_descn => 'test_invalid_binary_prefix_is_decimal_0', + i_exp => 0, + i_act => ut_binary#.to_decimal ('a10110')); + test (i_descn => 'test_invalid_binary_infix_is_decimal_0', + i_exp => 0, + i_act => ut_binary#.to_decimal ('101a10')); + test (i_descn => 'test_invalid_binary_is_decimal_0', + i_exp => 0, + i_act => ut_binary#.to_decimal ('101210')); + END run; +END ut_binary#; +/ + +/**/ +begin + ut_binary#.run; +end; +/ + diff --git a/PLSQL Problem Solving/difference-of-squares/.exercism/config.json b/PLSQL Problem Solving/difference-of-squares/.exercism/config.json new file mode 100644 index 0000000..fa2167c --- /dev/null +++ b/PLSQL Problem Solving/difference-of-squares/.exercism/config.json @@ -0,0 +1,19 @@ +{ + "blurb": "Find the difference between the square of the sum and the sum of the squares of the first N natural numbers.", + "authors": [ + "chezwicker" + ], + "files": { + "solution": [ + "ut_series#.plsql" + ], + "test": [ + "ut_series#.plsql" + ], + "example": [ + ".meta/example.plsql" + ] + }, + "source": "Problem 6 at Project Euler", + "source_url": "http://projecteuler.net/problem=6" +} diff --git a/PLSQL Problem Solving/difference-of-squares/.exercism/metadata.json b/PLSQL Problem Solving/difference-of-squares/.exercism/metadata.json new file mode 100644 index 0000000..8ada875 --- /dev/null +++ b/PLSQL Problem Solving/difference-of-squares/.exercism/metadata.json @@ -0,0 +1 @@ +{"track":"plsql","exercise":"difference-of-squares","id":"e10f9781057c426ba66e70a7145d02c9","url":"https://exercism.org/tracks/plsql/exercises/difference-of-squares","handle":"radwanromy","is_requester":true,"auto_approve":false} \ No newline at end of file diff --git a/PLSQL Problem Solving/difference-of-squares/HELP.md b/PLSQL Problem Solving/difference-of-squares/HELP.md new file mode 100644 index 0000000..5422c25 --- /dev/null +++ b/PLSQL Problem Solving/difference-of-squares/HELP.md @@ -0,0 +1,34 @@ +# Help + +## Running the tests + +Execute the tests by calling the `run` method in the respective `ut_#` package, +where `` is replaced with the exercise name. + +## Submitting your solution + +You can submit your solution using the `exercism submit ut_series#.plsql` command. +This command will upload your solution to the Exercism website and print the solution page's URL. + +It's possible to submit an incomplete solution which allows you to: + +- See how others have completed the exercise +- Request help from a mentor + +## Need to get help? + +If you'd like help solving the exercise, check the following pages: + +- The [PL/SQL track's documentation](https://exercism.org/docs/tracks/plsql) +- [Exercism's support channel on gitter](https://gitter.im/exercism/support) +- The [Frequently Asked Questions](https://exercism.org/docs/using/faqs) + +Should those resources not suffice, you could submit your (incomplete) solution to request mentoring. + +To get help if you're having trouble, you can use one of the following resources: + +- [Oracle - PL/SQL Language Reference](http://docs.oracle.com/cd/E11882_01/appdev.112/e25519/toc.htm) +- [Builtin Function Reference](http://psoug.org/reference/builtin_functions.html) +- [Ask Tom](https://asktom.oracle.com/) - Advice by the PL/SQL Guru +- [/r/plsql](https://www.reddit.com/r/plsql) is the C# subreddit. +- [StackOverflow](http://stackoverflow.com/questions/tagged/plsql) can be used to search for your problem and see if it has been answered already. You can also ask and answer questions. \ No newline at end of file diff --git a/PLSQL Problem Solving/difference-of-squares/README.md b/PLSQL Problem Solving/difference-of-squares/README.md new file mode 100644 index 0000000..b69bdbf --- /dev/null +++ b/PLSQL Problem Solving/difference-of-squares/README.md @@ -0,0 +1,32 @@ +# Difference Of Squares + +Welcome to Difference Of Squares on Exercism's PL/SQL Track. +If you need help running the tests or submitting your code, check out `HELP.md`. + +## Instructions + +Find the difference between the square of the sum and the sum of the squares of the first N natural numbers. + +The square of the sum of the first ten natural numbers is +(1 + 2 + ... + 10)² = 55² = 3025. + +The sum of the squares of the first ten natural numbers is +1² + 2² + ... + 10² = 385. + +Hence the difference between the square of the sum of the first +ten natural numbers and the sum of the squares of the first ten +natural numbers is 3025 - 385 = 2640. + +You are not expected to discover an efficient solution to this yourself from +first principles; research is allowed, indeed, encouraged. Finding the best +algorithm for the problem is a key skill in software engineering. + +## Source + +### Created by + +- @chezwicker + +### Based on + +Problem 6 at Project Euler - http://projecteuler.net/problem=6 \ No newline at end of file diff --git a/PLSQL Problem Solving/difference-of-squares/ut_series#.plsql b/PLSQL Problem Solving/difference-of-squares/ut_series#.plsql new file mode 100644 index 0000000..61d0d6d --- /dev/null +++ b/PLSQL Problem Solving/difference-of-squares/ut_series#.plsql @@ -0,0 +1,77 @@ +/**/ +/* Formatted on 23/Nov/21 12:38:54 PM (QP5 v5.287) */ +CREATE OR REPLACE PACKAGE ut_series# +IS + FUNCTION square_of_sums (i_n PLS_INTEGER) + RETURN PLS_INTEGER; + + FUNCTION sum_of_squares (i_n PLS_INTEGER) + RETURN PLS_INTEGER; + + FUNCTION diff_of_squares (i_n PLS_INTEGER) + RETURN PLS_INTEGER; + + PROCEDURE run; +END ut_series#; +/ + +/**/ +create or replace package body ut_series# +is + function square_of_sums ( + i_n pls_integer + ) return pls_integer + is + begin + return power(i_n * (i_n + 1) / 2, 2); + end square_of_sums; + function sum_of_squares ( + i_n pls_integer + ) return pls_integer + is + begin + return (i_n * (i_n + 1) * (2 * i_n + 1)) / 6; + end sum_of_squares; + function diff_of_squares ( + i_n pls_integer + ) return pls_integer + is + begin + return square_of_sums(i_n) - sum_of_squares(i_n); + end diff_of_squares; + procedure test ( + i_descn varchar2 + ,i_exp number + ,i_act number + ) + is + begin + if i_exp = i_act then + dbms_output.put_line('SUCCESS: ' || i_descn); + else + dbms_output.put_line('FAILURE: ' || i_descn || ' - expected ' || nvl('' || i_exp, 'null') || ', but received ' || nvl('' || i_act, 'null')); + end if; + end test; + + procedure run + is + begin + test(i_descn => 'test_square_of_sums_to_5' , i_exp => 225 , i_act => ut_series#.square_of_sums(5) ); + test(i_descn => 'test_sum_of_squares_to_5' , i_exp => 55 , i_act => ut_series#.sum_of_squares(5) ); + test(i_descn => 'test_difference_of_sums_to_5' , i_exp => 170 , i_act => ut_series#.diff_of_squares(5) ); + test(i_descn => 'test_square_of_sums_to_10' , i_exp => 3025 , i_act => ut_series#.square_of_sums(10) ); + test(i_descn => 'test_sum_of_squares_to_10' , i_exp => 385 , i_act => ut_series#.sum_of_squares(10) ); + test(i_descn => 'test_difference_of_sums_to_10' , i_exp => 2640 , i_act => ut_series#.diff_of_squares(10) ); + test(i_descn => 'test_square_of_sums_to_100' , i_exp => 25502500, i_act => ut_series#.square_of_sums(100) ); + test(i_descn => 'test_sum_of_squares_to_100' , i_exp => 338350 , i_act => ut_series#.sum_of_squares(100) ); + test(i_descn => 'test_difference_of_sums_to_100', i_exp => 25164150, i_act => ut_series#.diff_of_squares(100)); + end run; +end ut_series#; +/ + +/**/ +begin + ut_series#.run; +end; +/ + diff --git a/PLSQL Problem Solving/gigasecond/.exercism/config.json b/PLSQL Problem Solving/gigasecond/.exercism/config.json new file mode 100644 index 0000000..e87351a --- /dev/null +++ b/PLSQL Problem Solving/gigasecond/.exercism/config.json @@ -0,0 +1,19 @@ +{ + "blurb": "Given a moment, determine the moment that would be after a gigasecond has passed.", + "authors": [ + "chezwicker" + ], + "files": { + "solution": [ + "ut_gigasecond#.plsql" + ], + "test": [ + "ut_gigasecond#.plsql" + ], + "example": [ + ".meta/example.plsql" + ] + }, + "source": "Chapter 9 in Chris Pine's online Learn to Program tutorial.", + "source_url": "http://pine.fm/LearnToProgram/?Chapter=09" +} diff --git a/PLSQL Problem Solving/gigasecond/.exercism/metadata.json b/PLSQL Problem Solving/gigasecond/.exercism/metadata.json new file mode 100644 index 0000000..6a742b4 --- /dev/null +++ b/PLSQL Problem Solving/gigasecond/.exercism/metadata.json @@ -0,0 +1 @@ +{"track":"plsql","exercise":"gigasecond","id":"f4e0beeb51b2459f81bd32deaf23e6bc","url":"https://exercism.org/tracks/plsql/exercises/gigasecond","handle":"radwanromy","is_requester":true,"auto_approve":false} \ No newline at end of file diff --git a/PLSQL Problem Solving/gigasecond/HELP.md b/PLSQL Problem Solving/gigasecond/HELP.md new file mode 100644 index 0000000..fefe387 --- /dev/null +++ b/PLSQL Problem Solving/gigasecond/HELP.md @@ -0,0 +1,34 @@ +# Help + +## Running the tests + +Execute the tests by calling the `run` method in the respective `ut_#` package, +where `` is replaced with the exercise name. + +## Submitting your solution + +You can submit your solution using the `exercism submit ut_gigasecond#.plsql` command. +This command will upload your solution to the Exercism website and print the solution page's URL. + +It's possible to submit an incomplete solution which allows you to: + +- See how others have completed the exercise +- Request help from a mentor + +## Need to get help? + +If you'd like help solving the exercise, check the following pages: + +- The [PL/SQL track's documentation](https://exercism.org/docs/tracks/plsql) +- [Exercism's support channel on gitter](https://gitter.im/exercism/support) +- The [Frequently Asked Questions](https://exercism.org/docs/using/faqs) + +Should those resources not suffice, you could submit your (incomplete) solution to request mentoring. + +To get help if you're having trouble, you can use one of the following resources: + +- [Oracle - PL/SQL Language Reference](http://docs.oracle.com/cd/E11882_01/appdev.112/e25519/toc.htm) +- [Builtin Function Reference](http://psoug.org/reference/builtin_functions.html) +- [Ask Tom](https://asktom.oracle.com/) - Advice by the PL/SQL Guru +- [/r/plsql](https://www.reddit.com/r/plsql) is the C# subreddit. +- [StackOverflow](http://stackoverflow.com/questions/tagged/plsql) can be used to search for your problem and see if it has been answered already. You can also ask and answer questions. \ No newline at end of file diff --git a/PLSQL Problem Solving/gigasecond/README.md b/PLSQL Problem Solving/gigasecond/README.md new file mode 100644 index 0000000..b315d33 --- /dev/null +++ b/PLSQL Problem Solving/gigasecond/README.md @@ -0,0 +1,21 @@ +# Gigasecond + +Welcome to Gigasecond on Exercism's PL/SQL Track. +If you need help running the tests or submitting your code, check out `HELP.md`. + +## Instructions + +Given a moment, determine the moment that would be after a gigasecond +has passed. + +A gigasecond is 10^9 (1,000,000,000) seconds. + +## Source + +### Created by + +- @chezwicker + +### Based on + +Chapter 9 in Chris Pine's online Learn to Program tutorial. - http://pine.fm/LearnToProgram/?Chapter=09 \ No newline at end of file diff --git a/PLSQL Problem Solving/gigasecond/ut_gigasecond#.plsql b/PLSQL Problem Solving/gigasecond/ut_gigasecond#.plsql new file mode 100644 index 0000000..c46be69 --- /dev/null +++ b/PLSQL Problem Solving/gigasecond/ut_gigasecond#.plsql @@ -0,0 +1,39 @@ +create or replace package ut_gigasecond# +is + procedure run; +end ut_gigasecond#; +/ + +create or replace package body ut_gigasecond# +is + procedure test ( + i_descn varchar2 + ,i_exp date + ,i_act date + ) + is + begin + if i_exp = i_act then + dbms_output.put_line('SUCCESS: ' || i_descn); + else + dbms_output.put_line('FAILURE: ' || i_descn || ' - expected ' || nvl('' || i_exp, 'null') || ', but received ' || nvl('' || i_act, 'null')); + end if; + end test; + + procedure run + is + begin + test(i_descn => 'test_1', i_exp => to_date('2043-01-01', 'YYYY-MM-DD'), i_act => gigasecond#.since(to_date('2011-04-25', 'YYYY-MM-DD'))); + test(i_descn => 'test_2', i_exp => to_date('2009-02-19', 'YYYY-MM-DD'), i_act => gigasecond#.since(to_date('1977-06-13', 'YYYY-MM-DD'))); + test(i_descn => 'test_3', i_exp => to_date('1991-03-27', 'YYYY-MM-DD'), i_act => gigasecond#.since(to_date('1959-07-19', 'YYYY-MM-DD'))); + test(i_descn => 'test_time_with_seconds', i_exp => to_date('1991-03-28', 'YYYY-MM-DD'), i_act => gigasecond#.since(to_date('1959-07-19 23:59:59', 'YYYY-MM-DD HH24:Mi:SS'))); + ---- modify the test to test your 1 Gs anniversary + --test(i_descn => 'test_yourself', i_exp => to_date('AAAA-BB-CC', 'YYYY-MM-DD'), i_act => gigasecond#.since(to_date('XXXX-YY-ZZ', 'YYYY-MM-DD'))); + end run; +end ut_gigasecond#; +/ + +begin + ut_gigasecond#.run; +end; +/ diff --git a/PLSQL Problem Solving/grains/.exercism/config.json b/PLSQL Problem Solving/grains/.exercism/config.json new file mode 100644 index 0000000..3591c13 --- /dev/null +++ b/PLSQL Problem Solving/grains/.exercism/config.json @@ -0,0 +1,19 @@ +{ + "blurb": "Calculate the number of grains of wheat on a chessboard given that the number on each square doubles.", + "authors": [ + "chezwicker" + ], + "files": { + "solution": [ + "ut_grains#.plsql" + ], + "test": [ + "ut_grains#.plsql" + ], + "example": [ + ".meta/example.plsql" + ] + }, + "source": "JavaRanch Cattle Drive, exercise 6", + "source_url": "http://www.javaranch.com/grains.jsp" +} diff --git a/PLSQL Problem Solving/grains/.exercism/metadata.json b/PLSQL Problem Solving/grains/.exercism/metadata.json new file mode 100644 index 0000000..92f41a3 --- /dev/null +++ b/PLSQL Problem Solving/grains/.exercism/metadata.json @@ -0,0 +1 @@ +{"track":"plsql","exercise":"grains","id":"c4b3767ccd9341e0943afab8cf5a95c3","url":"https://exercism.org/tracks/plsql/exercises/grains","handle":"radwanromy","is_requester":true,"auto_approve":false} \ No newline at end of file diff --git a/PLSQL Problem Solving/grains/HELP.md b/PLSQL Problem Solving/grains/HELP.md new file mode 100644 index 0000000..98affde --- /dev/null +++ b/PLSQL Problem Solving/grains/HELP.md @@ -0,0 +1,34 @@ +# Help + +## Running the tests + +Execute the tests by calling the `run` method in the respective `ut_#` package, +where `` is replaced with the exercise name. + +## Submitting your solution + +You can submit your solution using the `exercism submit ut_grains#.plsql` command. +This command will upload your solution to the Exercism website and print the solution page's URL. + +It's possible to submit an incomplete solution which allows you to: + +- See how others have completed the exercise +- Request help from a mentor + +## Need to get help? + +If you'd like help solving the exercise, check the following pages: + +- The [PL/SQL track's documentation](https://exercism.org/docs/tracks/plsql) +- [Exercism's support channel on gitter](https://gitter.im/exercism/support) +- The [Frequently Asked Questions](https://exercism.org/docs/using/faqs) + +Should those resources not suffice, you could submit your (incomplete) solution to request mentoring. + +To get help if you're having trouble, you can use one of the following resources: + +- [Oracle - PL/SQL Language Reference](http://docs.oracle.com/cd/E11882_01/appdev.112/e25519/toc.htm) +- [Builtin Function Reference](http://psoug.org/reference/builtin_functions.html) +- [Ask Tom](https://asktom.oracle.com/) - Advice by the PL/SQL Guru +- [/r/plsql](https://www.reddit.com/r/plsql) is the C# subreddit. +- [StackOverflow](http://stackoverflow.com/questions/tagged/plsql) can be used to search for your problem and see if it has been answered already. You can also ask and answer questions. \ No newline at end of file diff --git a/PLSQL Problem Solving/grains/README.md b/PLSQL Problem Solving/grains/README.md new file mode 100644 index 0000000..05980f9 --- /dev/null +++ b/PLSQL Problem Solving/grains/README.md @@ -0,0 +1,42 @@ +# Grains + +Welcome to Grains on Exercism's PL/SQL Track. +If you need help running the tests or submitting your code, check out `HELP.md`. + +## Instructions + +Calculate the number of grains of wheat on a chessboard given that the number +on each square doubles. + +There once was a wise servant who saved the life of a prince. The king +promised to pay whatever the servant could dream up. Knowing that the +king loved chess, the servant told the king he would like to have grains +of wheat. One grain on the first square of a chess board, with the number +of grains doubling on each successive square. + +There are 64 squares on a chessboard (where square 1 has one grain, square 2 has two grains, and so on). + +Write code that shows: +- how many grains were on a given square, and +- the total number of grains on the chessboard + +## For bonus points + +Did you get the tests passing and the code clean? If you want to, these +are some additional things you could try: + +- Optimize for speed. +- Optimize for readability. + +Then please share your thoughts in a comment on the submission. Did this +experiment make the code better? Worse? Did you learn anything from it? + +## Source + +### Created by + +- @chezwicker + +### Based on + +JavaRanch Cattle Drive, exercise 6 - http://www.javaranch.com/grains.jsp \ No newline at end of file diff --git a/PLSQL Problem Solving/grains/ut_grains#.plsql b/PLSQL Problem Solving/grains/ut_grains#.plsql new file mode 100644 index 0000000..ed677ad --- /dev/null +++ b/PLSQL Problem Solving/grains/ut_grains#.plsql @@ -0,0 +1,41 @@ +create or replace package ut_grains# +is + procedure run; +end ut_grains#; +/ + +create or replace package body ut_grains# +is + procedure test ( + i_descn varchar2 + ,i_exp number + ,i_act number + ) + is + begin + if i_exp = i_act then + dbms_output.put_line('SUCCESS: ' || i_descn); + else + dbms_output.put_line('FAILURE: ' || i_descn || ' - expected ' || nvl('' || i_exp, 'null') || ', but received ' || nvl('' || i_act, 'null')); + end if; + end test; + + procedure run + is + begin + test(i_descn => 'test_square_1' , i_exp => 1 , i_act => grains#.at_square(1 )); + test(i_descn => 'test_square_2' , i_exp => 2 , i_act => grains#.at_square(2 )); + test(i_descn => 'test_square_3' , i_exp => 4 , i_act => grains#.at_square(3 )); + test(i_descn => 'test_square_4' , i_exp => 8 , i_act => grains#.at_square(4 )); + test(i_descn => 'test_square_16' , i_exp => 32768 , i_act => grains#.at_square(16)); + test(i_descn => 'test_square_32' , i_exp => 2147483648 , i_act => grains#.at_square(32)); + test(i_descn => 'test_square_64' , i_exp => 9223372036854775808 , i_act => grains#.at_square(64)); + test(i_descn => 'test_total_grains', i_exp => 18446744073709551615, i_act => grains#.total ); + end run; +end ut_grains#; +/ + +begin + ut_grains#.run; +end; +/ diff --git a/PLSQL Problem Solving/hamming/.exercism/config.json b/PLSQL Problem Solving/hamming/.exercism/config.json new file mode 100644 index 0000000..f0d9b2c --- /dev/null +++ b/PLSQL Problem Solving/hamming/.exercism/config.json @@ -0,0 +1,19 @@ +{ + "blurb": "Calculate the Hamming difference between two DNA strands.", + "authors": [ + "chezwicker" + ], + "files": { + "solution": [ + "ut_hamming#.plsql" + ], + "test": [ + "ut_hamming#.plsql" + ], + "example": [ + ".meta/example.plsql" + ] + }, + "source": "The Calculating Point Mutations problem at Rosalind", + "source_url": "http://rosalind.info/problems/hamm/" +} diff --git a/PLSQL Problem Solving/hamming/.exercism/metadata.json b/PLSQL Problem Solving/hamming/.exercism/metadata.json new file mode 100644 index 0000000..5468143 --- /dev/null +++ b/PLSQL Problem Solving/hamming/.exercism/metadata.json @@ -0,0 +1 @@ +{"track":"plsql","exercise":"hamming","id":"d95586666d214385ab4176696fbb88fc","url":"https://exercism.org/tracks/plsql/exercises/hamming","handle":"radwanromy","is_requester":true,"auto_approve":false} \ No newline at end of file diff --git a/PLSQL Problem Solving/hamming/GETTING_STARTED.md b/PLSQL Problem Solving/hamming/GETTING_STARTED.md new file mode 100644 index 0000000..10c0231 --- /dev/null +++ b/PLSQL Problem Solving/hamming/GETTING_STARTED.md @@ -0,0 +1,77 @@ +# Getting Started + +These exercises lean on Test-Driven Development (TDD), but they're not an +exact match. + +## Setup + +You'll need access to a mounted Oracle DB. If you don't have one already +installed, here are a few options: +* download VirtualBox from Oracle and run one of the freely +available images; at the time of writing, the easiest to get started with +at the time of writing might be _Database App Development VM_. The +image is quite large... +* download and install the a version of the Oracle DB itself. Developer licenses +are free. +* get a free workspace at https://apex.oracle.com + +**Note**: if you're using the online version of APEX, compilation errors will +not be indicated very clearly when working in _SQL Commands_ - you will simply +get "Error at line XX: PL/SQL: Statement ignored"... More insight can be +found using the _Object Browser_ and navigating to the object you created +(select either _Packages_ or _Procedures_ in the dropdown menu showing _Tables_, +depending on what you created for the exercise). Also, when you run statements, +"run" each individual `create` statement individually by selecting its text. +APEX does not seem to like doing too much work at once... + +To work on individual problems, a nice and free way is to use SQL Developer. If +you don't want to use yet another IDE, you can simply copy and paste your code +into a terminal / command prompt connected to the database. The files are +prepared in a way that will simply overwrite the previously compiled version. + +#Exercise + +## Step 1 + +Compile the test suite. You can easily do that by copy / pasting (let's call +that _installing_ for simplicity) into your terminal connected to a mounted +Oracle database. + +This will fail, complaining that there is no package called `HAMMING#`. + +To fix the error create the package by installing the prepared solution stub. +Note that you will have to re-install the package body of `UT_HAMMING#`. + +A few words about naming: the `#` at the end of the name signifies that this +is a package. `UT` means _unit test_. _PL/SQL_ has a maximum identifier length +of 30 characters, which is why you will find that many words are abbreviated. + +If you've worked with PL/SQL before, you might wonder why the template is a +package and not simply a standalone function. That would of course also be a +possibility, but in practice standalone procedures or functions are rarely used. + +## Step 2 + +Try to run the test. You will notice that you are missing the function's +implementation. Create it (see the test package for examples). + +Note that functions have to return a value, so for now just `return null;`. + +## Step 3 + +Run the test again. It should now execute, but the test will fail. +That's where you get to actually implement the function! + +## Wash, Rinse, Repeat + +Only the first test is enabled at first, the others are commented out. To enable +them, simply delete the `--` in front of the procedure call and they'll run +when you next install the test package! + +## Submit + +When everything is passing, you can submit your code with the following +command: + + $ exercism submit hamming#.plsql + diff --git a/PLSQL Problem Solving/hamming/HELP.md b/PLSQL Problem Solving/hamming/HELP.md new file mode 100644 index 0000000..c006633 --- /dev/null +++ b/PLSQL Problem Solving/hamming/HELP.md @@ -0,0 +1,34 @@ +# Help + +## Running the tests + +Execute the tests by calling the `run` method in the respective `ut_#` package, +where `` is replaced with the exercise name. + +## Submitting your solution + +You can submit your solution using the `exercism submit ut_hamming#.plsql` command. +This command will upload your solution to the Exercism website and print the solution page's URL. + +It's possible to submit an incomplete solution which allows you to: + +- See how others have completed the exercise +- Request help from a mentor + +## Need to get help? + +If you'd like help solving the exercise, check the following pages: + +- The [PL/SQL track's documentation](https://exercism.org/docs/tracks/plsql) +- [Exercism's support channel on gitter](https://gitter.im/exercism/support) +- The [Frequently Asked Questions](https://exercism.org/docs/using/faqs) + +Should those resources not suffice, you could submit your (incomplete) solution to request mentoring. + +To get help if you're having trouble, you can use one of the following resources: + +- [Oracle - PL/SQL Language Reference](http://docs.oracle.com/cd/E11882_01/appdev.112/e25519/toc.htm) +- [Builtin Function Reference](http://psoug.org/reference/builtin_functions.html) +- [Ask Tom](https://asktom.oracle.com/) - Advice by the PL/SQL Guru +- [/r/plsql](https://www.reddit.com/r/plsql) is the C# subreddit. +- [StackOverflow](http://stackoverflow.com/questions/tagged/plsql) can be used to search for your problem and see if it has been answered already. You can also ask and answer questions. \ No newline at end of file diff --git a/PLSQL Problem Solving/hamming/README.md b/PLSQL Problem Solving/hamming/README.md new file mode 100644 index 0000000..5e1f7f2 --- /dev/null +++ b/PLSQL Problem Solving/hamming/README.md @@ -0,0 +1,37 @@ +# Hamming + +Welcome to Hamming on Exercism's PL/SQL Track. +If you need help running the tests or submitting your code, check out `HELP.md`. + +## Instructions + +Calculate the Hamming Distance between two DNA strands. + +Your body is made up of cells that contain DNA. Those cells regularly wear out and need replacing, which they achieve by dividing into daughter cells. In fact, the average human body experiences about 10 quadrillion cell divisions in a lifetime! + +When cells divide, their DNA replicates too. Sometimes during this process mistakes happen and single pieces of DNA get encoded with the incorrect information. If we compare two strands of DNA and count the differences between them we can see how many mistakes occurred. This is known as the "Hamming Distance". + +We read DNA using the letters C,A,G and T. Two strands might look like this: + + GAGCCTACTAACGGGAT + CATCGTAATGACGGCCT + ^ ^ ^ ^ ^ ^^ + +They have 7 differences, and therefore the Hamming Distance is 7. + +The Hamming Distance is useful for lots of things in science, not just biology, so it's a nice phrase to be familiar with :) + +The Hamming distance is only defined for sequences of equal length, so +an attempt to calculate it between sequences of different lengths should +not work. The general handling of this situation (e.g., raising an +exception vs returning a special value) may differ between languages. + +## Source + +### Created by + +- @chezwicker + +### Based on + +The Calculating Point Mutations problem at Rosalind - http://rosalind.info/problems/hamm/ \ No newline at end of file diff --git a/PLSQL Problem Solving/hamming/ut_hamming#.plsql b/PLSQL Problem Solving/hamming/ut_hamming#.plsql new file mode 100644 index 0000000..e8b6ad4 --- /dev/null +++ b/PLSQL Problem Solving/hamming/ut_hamming#.plsql @@ -0,0 +1,81 @@ +/**/ +/* Formatted on 23/Nov/21 12:50:14 PM (QP5 v5.287) */ +CREATE OR REPLACE PACKAGE ut_hamming# +IS + FUNCTION distance (i_first VARCHAR2, i_second VARCHAR2) + RETURN PLS_INTEGER; + + PROCEDURE run; +END ut_hamming#; +/ + +/**/ +/* Formatted on 23/Nov/21 12:50:12 PM (QP5 v5.287) */ +CREATE OR REPLACE PACKAGE BODY ut_hamming# +IS + FUNCTION distance (i_first VARCHAR2, i_second VARCHAR2) + RETURN PLS_INTEGER + AS + first_dna VARCHAR2 (3200 CHAR) := i_first; + second_dna VARCHAR2 (3200 CHAR) := i_second; + hamming_d PLS_INTEGER := 0; + BEGIN + FOR counter IN 1 .. LENGTH (first_dna) + LOOP + IF SUBSTR (first_dna, counter, 1) != SUBSTR (second_dna, counter, 1) + THEN + hamming_d := hamming_d + 1; + END IF; + END LOOP; + + RETURN hamming_d; + END distance; + + PROCEDURE test (i_descn VARCHAR2, i_exp PLS_INTEGER, i_act PLS_INTEGER) + IS + BEGIN + IF i_exp = i_act + THEN + DBMS_OUTPUT.put_line ('SUCCESS: ' || i_descn); + ELSE + DBMS_OUTPUT.put_line ( + 'FAILURE: ' + || i_descn + || ': expected ' + || NVL ('' || i_exp, 'null') + || ', but got ' + || NVL ('' || i_act, 'null') + || '!'); + END IF; + END test; + + PROCEDURE run + IS + BEGIN + test ('test_no_difference_between_identical_strands', + 0, + ut_hamming#.distance (i_first => 'A', i_second => 'A')); + --test('test_complete_hamming_distance_of_for_single_nucleotide_strand', 1, hamming#.distance(i_first => 'A' , i_second => 'G' )); + --test('test_complete_hamming_distance_of_for_small_strand' , 2, hamming#.distance(i_first => 'AG' , i_second => 'CT' )); + --test('test_small_hamming_distance' , 1, hamming#.distance(i_first => 'AG' , i_second => 'AT' )); + --test('test_small_hamming_distance_in_longer_strand' , 1, hamming#.distance(i_first => 'GGACG' , i_second => 'GGTCG' )); + --test('test_nonunique_characters_within_first_strand' , 1, hamming#.distance(i_first => 'AGA' , i_second => 'AGG' )); + --test('test_nonunique_characters_within_second_strand' , 1, hamming#.distance(i_first => 'AGG' , i_second => 'AGA' )); + --test('test_large_hamming_distance' , 4, hamming#.distance(i_first => 'GATACA' , i_second => 'GCATAA' )); + --test('test_hamming_distance_in_very_long_strand' , 9, hamming#.distance(i_first => 'GGACGGATTCTG', i_second => 'AGGACGGATTCT')); + EXCEPTION + WHEN OTHERS + THEN + DBMS_OUTPUT.put_line ('Test execution failed.'); + DBMS_OUTPUT.put_line (SQLERRM); + END run; +END ut_hamming#; +/ + +/**/ +/* Formatted on 23/Nov/21 12:50:16 PM (QP5 v5.287) */ +BEGIN + ut_hamming#.run; +END; +/ + diff --git a/PLSQL Problem Solving/hello-world/.exercism/config.json b/PLSQL Problem Solving/hello-world/.exercism/config.json new file mode 100644 index 0000000..2268c4d --- /dev/null +++ b/PLSQL Problem Solving/hello-world/.exercism/config.json @@ -0,0 +1,20 @@ +{ + "blurb": "The classical introductory exercise. Just say \"Hello, World!\"", + "authors": [], + "contributors": [ + "kytrinyx" + ], + "files": { + "solution": [ + "ut_hello_world#.plsql" + ], + "test": [ + "ut_hello_world#.plsql" + ], + "example": [ + ".meta/example.plsql" + ] + }, + "source": "This is an exercise to introduce users to using Exercism", + "source_url": "http://en.wikipedia.org/wiki/%22Hello,_world!%22_program" +} diff --git a/PLSQL Problem Solving/hello-world/.exercism/metadata.json b/PLSQL Problem Solving/hello-world/.exercism/metadata.json new file mode 100644 index 0000000..e65147a --- /dev/null +++ b/PLSQL Problem Solving/hello-world/.exercism/metadata.json @@ -0,0 +1 @@ +{"track":"plsql","exercise":"hello-world","id":"c79c7df537b14e429bb2a7c08548c83d","url":"https://exercism.org/tracks/plsql/exercises/hello-world","handle":"radwanromy","is_requester":true,"auto_approve":false} \ No newline at end of file diff --git a/PLSQL Problem Solving/hello-world/HELP.md b/PLSQL Problem Solving/hello-world/HELP.md new file mode 100644 index 0000000..e34669f --- /dev/null +++ b/PLSQL Problem Solving/hello-world/HELP.md @@ -0,0 +1,34 @@ +# Help + +## Running the tests + +Execute the tests by calling the `run` method in the respective `ut_#` package, +where `` is replaced with the exercise name. + +## Submitting your solution + +You can submit your solution using the `exercism submit ut_hello_world#.plsql` command. +This command will upload your solution to the Exercism website and print the solution page's URL. + +It's possible to submit an incomplete solution which allows you to: + +- See how others have completed the exercise +- Request help from a mentor + +## Need to get help? + +If you'd like help solving the exercise, check the following pages: + +- The [PL/SQL track's documentation](https://exercism.org/docs/tracks/plsql) +- [Exercism's support channel on gitter](https://gitter.im/exercism/support) +- The [Frequently Asked Questions](https://exercism.org/docs/using/faqs) + +Should those resources not suffice, you could submit your (incomplete) solution to request mentoring. + +To get help if you're having trouble, you can use one of the following resources: + +- [Oracle - PL/SQL Language Reference](http://docs.oracle.com/cd/E11882_01/appdev.112/e25519/toc.htm) +- [Builtin Function Reference](http://psoug.org/reference/builtin_functions.html) +- [Ask Tom](https://asktom.oracle.com/) - Advice by the PL/SQL Guru +- [/r/plsql](https://www.reddit.com/r/plsql) is the C# subreddit. +- [StackOverflow](http://stackoverflow.com/questions/tagged/plsql) can be used to search for your problem and see if it has been answered already. You can also ask and answer questions. \ No newline at end of file diff --git a/PLSQL Problem Solving/hello-world/README.md b/PLSQL Problem Solving/hello-world/README.md new file mode 100644 index 0000000..4c32d11 --- /dev/null +++ b/PLSQL Problem Solving/hello-world/README.md @@ -0,0 +1,30 @@ +# Hello World + +Welcome to Hello World on Exercism's PL/SQL Track. +If you need help running the tests or submitting your code, check out `HELP.md`. + +## Instructions + +The classical introductory exercise. Just say "Hello, World!". + +["Hello, World!"](http://en.wikipedia.org/wiki/%22Hello,_world!%22_program) is +the traditional first program for beginning programming in a new language +or environment. + +The objectives are simple: + +- Write a function that returns the string "Hello, World!". +- Run the test suite and make sure that it succeeds. +- Submit your solution and check it at the website. + +If everything goes well, you will be ready to fetch your first real exercise. + +## Source + +### Contributed to by + +- @kytrinyx + +### Based on + +This is an exercise to introduce users to using Exercism - http://en.wikipedia.org/wiki/%22Hello,_world!%22_program \ No newline at end of file diff --git a/PLSQL Problem Solving/hello-world/ut_hello_world#.plsql b/PLSQL Problem Solving/hello-world/ut_hello_world#.plsql new file mode 100644 index 0000000..1394d35 --- /dev/null +++ b/PLSQL Problem Solving/hello-world/ut_hello_world#.plsql @@ -0,0 +1,65 @@ +CREATE OR REPLACE PACKAGE hello_world# IS + FUNCTION hello() + RETURN varchar2; + +END hello_world#; +/ + +CREATE OR REPLACE PACKAGE BODY hello_world# IS + FUNCTION hello() + RETURN varchar2 + AS + BEGIN + RETURN 'Goodbye, Mars!'; + END hello; +END hello_world#; +/ + +CREATE OR REPLACE PACKAGE ut_hello_world# +IS + PROCEDURE run; +END ut_hello_world#; +/ + +CREATE OR REPLACE PACKAGE BODY ut_hello_world# +IS + + PROCEDURE TEST ( + i_descn varchar2, + i_exp varchar2, + i_act varchar2 + ) + IS + BEGIN + IF i_exp = i_act THEN + dbms_output.put_line('SUCCESS: ' || i_descn); + ELSE + dbms_output.put_line( + 'FAILURE: ' || i_descn || + ': expected ''' || NVL('' || i_exp, 'NULL') || + ''', but got ''' || NVL('' || i_act, 'null') || '''!' + ); + END IF; + END TEST; + + PROCEDURE run + IS + BEGIN + TEST( + i_descn => 'no name', + i_exp => 'Hello, World!', + i_act => hello_world#.hello() + ); + EXCEPTION + WHEN others THEN + dbms_output.put_line('Test execution failed.'); + dbms_output.put_line(sqlerrm); + END run; + +END ut_hello_world#; +/ + +BEGIN + ut_hello_world#.run; +END; +/ diff --git a/PLSQL Problem Solving/leap/.exercism/config.json b/PLSQL Problem Solving/leap/.exercism/config.json new file mode 100644 index 0000000..4b4394d --- /dev/null +++ b/PLSQL Problem Solving/leap/.exercism/config.json @@ -0,0 +1,19 @@ +{ + "blurb": "Given a year, report if it is a leap year.", + "authors": [ + "chezwicker" + ], + "files": { + "solution": [ + "ut_leap#.plsql" + ], + "test": [ + "ut_leap#.plsql" + ], + "example": [ + ".meta/example.plsql" + ] + }, + "source": "JavaRanch Cattle Drive, exercise 3", + "source_url": "http://www.javaranch.com/leap.jsp" +} diff --git a/PLSQL Problem Solving/leap/.exercism/metadata.json b/PLSQL Problem Solving/leap/.exercism/metadata.json new file mode 100644 index 0000000..0b8440e --- /dev/null +++ b/PLSQL Problem Solving/leap/.exercism/metadata.json @@ -0,0 +1 @@ +{"track":"plsql","exercise":"leap","id":"ab747eb58b424df0acc31cd206b3c128","url":"https://exercism.org/tracks/plsql/exercises/leap","handle":"radwanromy","is_requester":true,"auto_approve":false} \ No newline at end of file diff --git a/PLSQL Problem Solving/leap/HELP.md b/PLSQL Problem Solving/leap/HELP.md new file mode 100644 index 0000000..abc7c72 --- /dev/null +++ b/PLSQL Problem Solving/leap/HELP.md @@ -0,0 +1,34 @@ +# Help + +## Running the tests + +Execute the tests by calling the `run` method in the respective `ut_#` package, +where `` is replaced with the exercise name. + +## Submitting your solution + +You can submit your solution using the `exercism submit ut_leap#.plsql` command. +This command will upload your solution to the Exercism website and print the solution page's URL. + +It's possible to submit an incomplete solution which allows you to: + +- See how others have completed the exercise +- Request help from a mentor + +## Need to get help? + +If you'd like help solving the exercise, check the following pages: + +- The [PL/SQL track's documentation](https://exercism.org/docs/tracks/plsql) +- [Exercism's support channel on gitter](https://gitter.im/exercism/support) +- The [Frequently Asked Questions](https://exercism.org/docs/using/faqs) + +Should those resources not suffice, you could submit your (incomplete) solution to request mentoring. + +To get help if you're having trouble, you can use one of the following resources: + +- [Oracle - PL/SQL Language Reference](http://docs.oracle.com/cd/E11882_01/appdev.112/e25519/toc.htm) +- [Builtin Function Reference](http://psoug.org/reference/builtin_functions.html) +- [Ask Tom](https://asktom.oracle.com/) - Advice by the PL/SQL Guru +- [/r/plsql](https://www.reddit.com/r/plsql) is the C# subreddit. +- [StackOverflow](http://stackoverflow.com/questions/tagged/plsql) can be used to search for your problem and see if it has been answered already. You can also ask and answer questions. \ No newline at end of file diff --git a/PLSQL Problem Solving/leap/README.md b/PLSQL Problem Solving/leap/README.md new file mode 100644 index 0000000..0b593eb --- /dev/null +++ b/PLSQL Problem Solving/leap/README.md @@ -0,0 +1,39 @@ +# Leap + +Welcome to Leap on Exercism's PL/SQL Track. +If you need help running the tests or submitting your code, check out `HELP.md`. + +## Instructions + +Given a year, report if it is a leap year. + +The tricky thing here is that a leap year in the Gregorian calendar occurs: + +```text +on every year that is evenly divisible by 4 + except every year that is evenly divisible by 100 + unless the year is also evenly divisible by 400 +``` + +For example, 1997 is not a leap year, but 1996 is. 1900 is not a leap +year, but 2000 is. + +## Notes + +Though our exercise adopts some very simple rules, there is more to +learn! + +For a delightful, four minute explanation of the whole leap year +phenomenon, go watch [this youtube video][video]. + +[video]: http://www.youtube.com/watch?v=xX96xng7sAE + +## Source + +### Created by + +- @chezwicker + +### Based on + +JavaRanch Cattle Drive, exercise 3 - http://www.javaranch.com/leap.jsp \ No newline at end of file diff --git a/PLSQL Problem Solving/leap/ut_leap#.plsql b/PLSQL Problem Solving/leap/ut_leap#.plsql new file mode 100644 index 0000000..292782b --- /dev/null +++ b/PLSQL Problem Solving/leap/ut_leap#.plsql @@ -0,0 +1,38 @@ +create or replace package ut_year# +is + procedure run; +end ut_year#; +/ + +create or replace package body ut_year# +is + procedure test ( + i_descn varchar2 + ,i_exp varchar2 + ,i_act varchar2 + ) + is + begin + if i_exp = i_act then + dbms_output.put_line('SUCCESS: ' || i_descn); + else + dbms_output.put_line('FAILURE: ' || i_descn || ' - expected ' || nvl(i_exp, 'null') || ', but received ' || nvl(i_act, 'null')); + end if; + end test; + + procedure run + is + begin + test(i_descn => 'test_leap_year' , i_exp => 'Yes, 1996 is a leap year' , i_act => year#.is_leap(1996)); + test(i_descn => 'test_non_leap_year' , i_exp => 'No, 1997 is not a leap year', i_act => year#.is_leap(1997)); + test(i_descn => 'test_non_leap_even_year', i_exp => 'No, 1998 is not a leap year', i_act => year#.is_leap(1998)); + test(i_descn => 'test_century' , i_exp => 'No, 1900 is not a leap year', i_act => year#.is_leap(1900)); + test(i_descn => 'test_fourth_century' , i_exp => 'Yes, 2400 is a leap year' , i_act => year#.is_leap(2400)); + end run; +end ut_year#; +/ + +begin + ut_year#.run; +end; +/ diff --git a/PLSQL Problem Solving/nth-prime/.exercism/config.json b/PLSQL Problem Solving/nth-prime/.exercism/config.json new file mode 100644 index 0000000..34c4697 --- /dev/null +++ b/PLSQL Problem Solving/nth-prime/.exercism/config.json @@ -0,0 +1,19 @@ +{ + "blurb": "Given a number n, determine what the nth prime is.", + "authors": [ + "chezwicker" + ], + "files": { + "solution": [ + "ut_prime#.plsql" + ], + "test": [ + "ut_prime#.plsql" + ], + "example": [ + ".meta/example.plsql" + ] + }, + "source": "A variation on Problem 7 at Project Euler", + "source_url": "http://projecteuler.net/problem=7" +} diff --git a/PLSQL Problem Solving/nth-prime/.exercism/metadata.json b/PLSQL Problem Solving/nth-prime/.exercism/metadata.json new file mode 100644 index 0000000..97703c5 --- /dev/null +++ b/PLSQL Problem Solving/nth-prime/.exercism/metadata.json @@ -0,0 +1 @@ +{"track":"plsql","exercise":"nth-prime","id":"504533a68a74480fb63d4232505434c2","url":"https://exercism.org/tracks/plsql/exercises/nth-prime","handle":"radwanromy","is_requester":true,"auto_approve":false} \ No newline at end of file diff --git a/PLSQL Problem Solving/nth-prime/HELP.md b/PLSQL Problem Solving/nth-prime/HELP.md new file mode 100644 index 0000000..4813953 --- /dev/null +++ b/PLSQL Problem Solving/nth-prime/HELP.md @@ -0,0 +1,34 @@ +# Help + +## Running the tests + +Execute the tests by calling the `run` method in the respective `ut_#` package, +where `` is replaced with the exercise name. + +## Submitting your solution + +You can submit your solution using the `exercism submit ut_prime#.plsql` command. +This command will upload your solution to the Exercism website and print the solution page's URL. + +It's possible to submit an incomplete solution which allows you to: + +- See how others have completed the exercise +- Request help from a mentor + +## Need to get help? + +If you'd like help solving the exercise, check the following pages: + +- The [PL/SQL track's documentation](https://exercism.org/docs/tracks/plsql) +- [Exercism's support channel on gitter](https://gitter.im/exercism/support) +- The [Frequently Asked Questions](https://exercism.org/docs/using/faqs) + +Should those resources not suffice, you could submit your (incomplete) solution to request mentoring. + +To get help if you're having trouble, you can use one of the following resources: + +- [Oracle - PL/SQL Language Reference](http://docs.oracle.com/cd/E11882_01/appdev.112/e25519/toc.htm) +- [Builtin Function Reference](http://psoug.org/reference/builtin_functions.html) +- [Ask Tom](https://asktom.oracle.com/) - Advice by the PL/SQL Guru +- [/r/plsql](https://www.reddit.com/r/plsql) is the C# subreddit. +- [StackOverflow](http://stackoverflow.com/questions/tagged/plsql) can be used to search for your problem and see if it has been answered already. You can also ask and answer questions. \ No newline at end of file diff --git a/PLSQL Problem Solving/nth-prime/README.md b/PLSQL Problem Solving/nth-prime/README.md new file mode 100644 index 0000000..719d843 --- /dev/null +++ b/PLSQL Problem Solving/nth-prime/README.md @@ -0,0 +1,24 @@ +# Nth Prime + +Welcome to Nth Prime on Exercism's PL/SQL Track. +If you need help running the tests or submitting your code, check out `HELP.md`. + +## Instructions + +Given a number n, determine what the nth prime is. + +By listing the first six prime numbers: 2, 3, 5, 7, 11, and 13, we can see that +the 6th prime is 13. + +If your language provides methods in the standard library to deal with prime +numbers, pretend they don't exist and implement them yourself. + +## Source + +### Created by + +- @chezwicker + +### Based on + +A variation on Problem 7 at Project Euler - http://projecteuler.net/problem=7 \ No newline at end of file diff --git a/PLSQL Problem Solving/nth-prime/ut_prime#.plsql b/PLSQL Problem Solving/nth-prime/ut_prime#.plsql new file mode 100644 index 0000000..69d179d --- /dev/null +++ b/PLSQL Problem Solving/nth-prime/ut_prime#.plsql @@ -0,0 +1,103 @@ +/**/ +/* Formatted on 23/Nov/21 12:54:20 PM (QP5 v5.287) */ +CREATE OR REPLACE PACKAGE ut_prime# +IS + FUNCTION f_prime (i_num PLS_INTEGER) + RETURN BOOLEAN; + + FUNCTION nth (i_num_prime PLS_INTEGER) + RETURN PLS_INTEGER; + + PROCEDURE run; +END ut_prime#; +/ + +/**/ +/* Formatted on 23/Nov/21 12:54:36 PM (QP5 v5.287) */ +CREATE OR REPLACE PACKAGE BODY ut_prime# +IS + FUNCTION f_prime (i_num PLS_INTEGER) + RETURN BOOLEAN + IS + l_prime BOOLEAN := TRUE; + BEGIN + FOR i IN 2 .. ROUND (SQRT (i_num)) + LOOP + IF MOD (i_num, i) = 0 + THEN + l_prime := FALSE; + EXIT; + END IF; + END LOOP; + + RETURN l_prime; + END f_prime; + + FUNCTION nth (i_num_prime PLS_INTEGER) + RETURN PLS_INTEGER + IS + i_count PLS_INTEGER := 1; + i_cur PLS_INTEGER := 2; + BEGIN + WHILE i_count < i_num_prime + LOOP + i_cur := i_cur + 1; + + IF f_prime (i_cur) + THEN + i_count := i_count + 1; + END IF; + END LOOP; + + RETURN i_cur; + END nth; + + PROCEDURE test (i_descn VARCHAR2, i_exp NUMBER, i_act NUMBER) + IS + BEGIN + IF i_exp = i_act + THEN + DBMS_OUTPUT.put_line ('SUCCESS: ' || i_descn); + ELSE + DBMS_OUTPUT.put_line ( + 'FAILURE: ' + || i_descn + || ' - expected ' + || NVL ('' || i_exp, 'null') + || ', but received ' + || NVL ('' || i_act, 'null')); + END IF; + END test; + + PROCEDURE run + IS + l_act NUMBER; + BEGIN + test (i_descn => 'test_first', i_exp => 2, i_act => ut_prime#.nth (1)); + test (i_descn => 'test_second', i_exp => 3, i_act => ut_prime#.nth (2)); + test (i_descn => 'test_sixth', i_exp => 13, i_act => ut_prime#.nth (6)); + test (i_descn => 'test_big_prime', + i_exp => 104743, + i_act => ut_prime#.nth (10001)); + + BEGIN + l_act := ut_prime#.nth (0); + DBMS_OUTPUT.put_line ( + 'FAILURE: test_weird_case - expected invalid_argument_error to be raised, but received ' + || NVL ('' || l_act, 'null')); + EXCEPTION + WHEN ut_prime#.invalid_argument_error + THEN + DBMS_OUTPUT.put_line ('SUCCESS: test_weird_case'); + END; + END run; +END ut_prime#; +/ + +/**/ +/* Formatted on 23/Nov/21 12:54:37 PM (QP5 v5.287) */ +BEGIN + ut_prime#.run; +END; +/ + diff --git a/PLSQL Problem Solving/raindrops/.exercism/config.json b/PLSQL Problem Solving/raindrops/.exercism/config.json new file mode 100644 index 0000000..cac41fd --- /dev/null +++ b/PLSQL Problem Solving/raindrops/.exercism/config.json @@ -0,0 +1,19 @@ +{ + "blurb": "Convert a number to a string, the content of which depends on the number's factors.", + "authors": [ + "chezwicker" + ], + "files": { + "solution": [ + "ut_raindrops#.plsql" + ], + "test": [ + "ut_raindrops#.plsql" + ], + "example": [ + ".meta/example.plsql" + ] + }, + "source": "A variation on FizzBuzz, a famous technical interview question that is intended to weed out potential candidates. That question is itself derived from Fizz Buzz, a popular children's game for teaching division.", + "source_url": "https://en.wikipedia.org/wiki/Fizz_buzz" +} diff --git a/PLSQL Problem Solving/raindrops/.exercism/metadata.json b/PLSQL Problem Solving/raindrops/.exercism/metadata.json new file mode 100644 index 0000000..2613375 --- /dev/null +++ b/PLSQL Problem Solving/raindrops/.exercism/metadata.json @@ -0,0 +1 @@ +{"track":"plsql","exercise":"raindrops","id":"4f2d22c09fdb4bb69e96efe04157b6cd","url":"https://exercism.org/tracks/plsql/exercises/raindrops","handle":"radwanromy","is_requester":true,"auto_approve":false} \ No newline at end of file diff --git a/PLSQL Problem Solving/raindrops/HELP.md b/PLSQL Problem Solving/raindrops/HELP.md new file mode 100644 index 0000000..792d982 --- /dev/null +++ b/PLSQL Problem Solving/raindrops/HELP.md @@ -0,0 +1,34 @@ +# Help + +## Running the tests + +Execute the tests by calling the `run` method in the respective `ut_#` package, +where `` is replaced with the exercise name. + +## Submitting your solution + +You can submit your solution using the `exercism submit ut_raindrops#.plsql` command. +This command will upload your solution to the Exercism website and print the solution page's URL. + +It's possible to submit an incomplete solution which allows you to: + +- See how others have completed the exercise +- Request help from a mentor + +## Need to get help? + +If you'd like help solving the exercise, check the following pages: + +- The [PL/SQL track's documentation](https://exercism.org/docs/tracks/plsql) +- [Exercism's support channel on gitter](https://gitter.im/exercism/support) +- The [Frequently Asked Questions](https://exercism.org/docs/using/faqs) + +Should those resources not suffice, you could submit your (incomplete) solution to request mentoring. + +To get help if you're having trouble, you can use one of the following resources: + +- [Oracle - PL/SQL Language Reference](http://docs.oracle.com/cd/E11882_01/appdev.112/e25519/toc.htm) +- [Builtin Function Reference](http://psoug.org/reference/builtin_functions.html) +- [Ask Tom](https://asktom.oracle.com/) - Advice by the PL/SQL Guru +- [/r/plsql](https://www.reddit.com/r/plsql) is the C# subreddit. +- [StackOverflow](http://stackoverflow.com/questions/tagged/plsql) can be used to search for your problem and see if it has been answered already. You can also ask and answer questions. \ No newline at end of file diff --git a/PLSQL Problem Solving/raindrops/README.md b/PLSQL Problem Solving/raindrops/README.md new file mode 100644 index 0000000..f58b1bd --- /dev/null +++ b/PLSQL Problem Solving/raindrops/README.md @@ -0,0 +1,31 @@ +# Raindrops + +Welcome to Raindrops on Exercism's PL/SQL Track. +If you need help running the tests or submitting your code, check out `HELP.md`. + +## Instructions + +Your task is to convert a number into a string that contains raindrop sounds corresponding to certain potential factors. A factor is a number that evenly divides into another number, leaving no remainder. The simplest way to test if a one number is a factor of another is to use the [modulo operation](https://en.wikipedia.org/wiki/Modulo_operation). + +The rules of `raindrops` are that if a given number: + +- has 3 as a factor, add 'Pling' to the result. +- has 5 as a factor, add 'Plang' to the result. +- has 7 as a factor, add 'Plong' to the result. +- _does not_ have any of 3, 5, or 7 as a factor, the result should be the digits of the number. + +## Examples + +- 28 has 7 as a factor, but not 3 or 5, so the result would be "Plong". +- 30 has both 3 and 5 as factors, but not 7, so the result would be "PlingPlang". +- 34 is not factored by 3, 5, or 7, so the result would be "34". + +## Source + +### Created by + +- @chezwicker + +### Based on + +A variation on FizzBuzz, a famous technical interview question that is intended to weed out potential candidates. That question is itself derived from Fizz Buzz, a popular children's game for teaching division. - https://en.wikipedia.org/wiki/Fizz_buzz \ No newline at end of file diff --git a/PLSQL Problem Solving/raindrops/ut_raindrops#.plsql b/PLSQL Problem Solving/raindrops/ut_raindrops#.plsql new file mode 100644 index 0000000..3a40133 --- /dev/null +++ b/PLSQL Problem Solving/raindrops/ut_raindrops#.plsql @@ -0,0 +1,49 @@ +create or replace package ut_raindrops# +is + procedure run; +end ut_raindrops#; +/ + +create or replace package body ut_raindrops# +is + procedure test ( + i_descn varchar2 + ,i_exp varchar2 + ,i_act varchar2 + ) + is + begin + if i_exp = i_act then + dbms_output.put_line('SUCCESS: ' || i_descn); + else + dbms_output.put_line('FAILURE: ' || i_descn || ' - expected ' || nvl(i_exp, 'null') || ', but received ' || nvl(i_act, 'null')); + end if; + end test; + + procedure run + is + begin + test(i_descn => 'test_1' , i_exp => '1' , i_act => raindrops#.convert(1)); + test(i_descn => 'test_3' , i_exp => 'Pling' , i_act => raindrops#.convert(3)); + test(i_descn => 'test_5' , i_exp => 'Plang' , i_act => raindrops#.convert(5)); + test(i_descn => 'test_7' , i_exp => 'Plong' , i_act => raindrops#.convert(7)); + test(i_descn => 'test_6' , i_exp => 'Pling' , i_act => raindrops#.convert(6)); + test(i_descn => 'test_9' , i_exp => 'Pling' , i_act => raindrops#.convert(9)); + test(i_descn => 'test_10' , i_exp => 'Plang' , i_act => raindrops#.convert(10)); + test(i_descn => 'test_14' , i_exp => 'Plong' , i_act => raindrops#.convert(14)); + test(i_descn => 'test_15' , i_exp => 'PlingPlang' , i_act => raindrops#.convert(15)); + test(i_descn => 'test_21' , i_exp => 'PlingPlong' , i_act => raindrops#.convert(21)); + test(i_descn => 'test_25' , i_exp => 'Plang' , i_act => raindrops#.convert(25)); + test(i_descn => 'test_35' , i_exp => 'PlangPlong' , i_act => raindrops#.convert(35)); + test(i_descn => 'test_49' , i_exp => 'Plong' , i_act => raindrops#.convert(49)); + test(i_descn => 'test_52' , i_exp => '52' , i_act => raindrops#.convert(52)); + test(i_descn => 'test_105' , i_exp => 'PlingPlangPlong', i_act => raindrops#.convert(105)); + test(i_descn => 'test_12121', i_exp => '12121' , i_act => raindrops#.convert(12121)); + end run; +end ut_raindrops#; +/ + +begin + ut_raindrops#.run; +end; +/ diff --git a/PLSQL Problem Solving/rna-transcription/.exercism/config.json b/PLSQL Problem Solving/rna-transcription/.exercism/config.json new file mode 100644 index 0000000..2320cae --- /dev/null +++ b/PLSQL Problem Solving/rna-transcription/.exercism/config.json @@ -0,0 +1,19 @@ +{ + "blurb": "Given a DNA strand, return its RNA Complement Transcription.", + "authors": [ + "chezwicker" + ], + "files": { + "solution": [ + "ut_complement#.plsql" + ], + "test": [ + "ut_complement#.plsql" + ], + "example": [ + ".meta/example.plsql" + ] + }, + "source": "Hyperphysics", + "source_url": "http://hyperphysics.phy-astr.gsu.edu/hbase/Organic/transcription.html" +} diff --git a/PLSQL Problem Solving/rna-transcription/.exercism/metadata.json b/PLSQL Problem Solving/rna-transcription/.exercism/metadata.json new file mode 100644 index 0000000..e44b83d --- /dev/null +++ b/PLSQL Problem Solving/rna-transcription/.exercism/metadata.json @@ -0,0 +1 @@ +{"track":"plsql","exercise":"rna-transcription","id":"d78b1772cea94c3fb147b86e10a1de53","url":"https://exercism.org/tracks/plsql/exercises/rna-transcription","handle":"radwanromy","is_requester":true,"auto_approve":false} \ No newline at end of file diff --git a/PLSQL Problem Solving/rna-transcription/HELP.md b/PLSQL Problem Solving/rna-transcription/HELP.md new file mode 100644 index 0000000..c51a775 --- /dev/null +++ b/PLSQL Problem Solving/rna-transcription/HELP.md @@ -0,0 +1,34 @@ +# Help + +## Running the tests + +Execute the tests by calling the `run` method in the respective `ut_#` package, +where `` is replaced with the exercise name. + +## Submitting your solution + +You can submit your solution using the `exercism submit ut_complement#.plsql` command. +This command will upload your solution to the Exercism website and print the solution page's URL. + +It's possible to submit an incomplete solution which allows you to: + +- See how others have completed the exercise +- Request help from a mentor + +## Need to get help? + +If you'd like help solving the exercise, check the following pages: + +- The [PL/SQL track's documentation](https://exercism.org/docs/tracks/plsql) +- [Exercism's support channel on gitter](https://gitter.im/exercism/support) +- The [Frequently Asked Questions](https://exercism.org/docs/using/faqs) + +Should those resources not suffice, you could submit your (incomplete) solution to request mentoring. + +To get help if you're having trouble, you can use one of the following resources: + +- [Oracle - PL/SQL Language Reference](http://docs.oracle.com/cd/E11882_01/appdev.112/e25519/toc.htm) +- [Builtin Function Reference](http://psoug.org/reference/builtin_functions.html) +- [Ask Tom](https://asktom.oracle.com/) - Advice by the PL/SQL Guru +- [/r/plsql](https://www.reddit.com/r/plsql) is the C# subreddit. +- [StackOverflow](http://stackoverflow.com/questions/tagged/plsql) can be used to search for your problem and see if it has been answered already. You can also ask and answer questions. \ No newline at end of file diff --git a/PLSQL Problem Solving/rna-transcription/README.md b/PLSQL Problem Solving/rna-transcription/README.md new file mode 100644 index 0000000..f60caf9 --- /dev/null +++ b/PLSQL Problem Solving/rna-transcription/README.md @@ -0,0 +1,34 @@ +# Rna Transcription + +Welcome to Rna Transcription on Exercism's PL/SQL Track. +If you need help running the tests or submitting your code, check out `HELP.md`. + +## Instructions + +Given a DNA strand, return its RNA complement (per RNA transcription). + +Both DNA and RNA strands are a sequence of nucleotides. + +The four nucleotides found in DNA are adenine (**A**), cytosine (**C**), +guanine (**G**) and thymine (**T**). + +The four nucleotides found in RNA are adenine (**A**), cytosine (**C**), +guanine (**G**) and uracil (**U**). + +Given a DNA strand, its transcribed RNA strand is formed by replacing +each nucleotide with its complement: + +* `G` -> `C` +* `C` -> `G` +* `T` -> `A` +* `A` -> `U` + +## Source + +### Created by + +- @chezwicker + +### Based on + +Hyperphysics - http://hyperphysics.phy-astr.gsu.edu/hbase/Organic/transcription.html \ No newline at end of file diff --git a/PLSQL Problem Solving/rna-transcription/ut_complement#.plsql b/PLSQL Problem Solving/rna-transcription/ut_complement#.plsql new file mode 100644 index 0000000..8d5c65a --- /dev/null +++ b/PLSQL Problem Solving/rna-transcription/ut_complement#.plsql @@ -0,0 +1,84 @@ +/**/ +create or replace package ut_complement# +is + FUNCTION of_rna(chars VARCHAR2) RETURN VARCHAR2; + FUNCTION of_dna(chars VARCHAR2) RETURN VARCHAR2; + procedure run; +end ut_complement#; +/ + +/**/ +/* Formatted on 22/Nov/21 12:21:44 PM (QP5 v5.287) */ +CREATE OR REPLACE PACKAGE BODY ut_complement# +IS + FUNCTION of_rna(chars VARCHAR2) RETURN VARCHAR2 + AS + BEGIN + RETURN TRANSLATE(chars, 'CGAU', 'GCTA'); + END of_rna; + FUNCTION of_dna(chars VARCHAR2) RETURN VARCHAR2 + AS + BEGIN + RETURN TRANSLATE(chars, 'GCTA', 'CGAU'); + END of_dna; + + PROCEDURE test (i_descn VARCHAR2, i_exp VARCHAR2, i_act VARCHAR2) + IS + BEGIN + IF i_exp = i_act + THEN + DBMS_OUTPUT.put_line ('SUCCESS: ' || i_descn); + ELSE + DBMS_OUTPUT.put_line ( + 'FAILURE: ' + || i_descn + || ' - expected ' + || NVL (i_exp, 'null') + || ', but received ' + || NVL (i_act, 'null')); + END IF; + END test; + + PROCEDURE run + IS + BEGIN + test (i_descn => 'test_rna_complement_of_cytosine_is_guanine', + i_exp => 'G', + i_act => ut_complement#.of_dna ('C')); + test (i_descn => 'test_rna_complement_of_guanine_is_cytosine', + i_exp => 'C', + i_act => ut_complement#.of_dna ('G')); + test (i_descn => 'test_rna_complement_of_thymine_is_adenine', + i_exp => 'A', + i_act => ut_complement#.of_dna ('T')); + test (i_descn => 'test_rna_complement_of_adenine_is_uracil', + i_exp => 'U', + i_act => ut_complement#.of_dna ('A')); + test (i_descn => 'test_rna_complement', + i_exp => 'UGCACCAGAAUU', + i_act => ut_complement#.of_dna ('ACGTGGTCTTAA')); + test (i_descn => 'test_dna_complement_of_cytosine_is_guanine', + i_exp => 'G', + i_act => ut_complement#.of_rna ('C')); + test (i_descn => 'test_dna_complement_of_guanine_is_cytosine', + i_exp => 'C', + i_act => ut_complement#.of_rna ('G')); + test (i_descn => 'test_dna_complement_of_uracil_is_adenine', + i_exp => 'A', + i_act => ut_complement#.of_rna ('U')); + test (i_descn => 'test_dna_complement_of_adenine_is_thymine', + i_exp => 'T', + i_act => ut_complement#.of_rna ('A')); + test (i_descn => 'test_dna_complement', + i_exp => 'ACTTGGGCTGTAC', + i_act => ut_complement#.of_rna ('UGAACCCGACAUG')); + END run; +END ut_complement#; +/ + +/**/ +begin + ut_complement#.run; +end; +/ + diff --git a/PLSQL Problem Solving/roman-numerals/.exercism/config.json b/PLSQL Problem Solving/roman-numerals/.exercism/config.json new file mode 100644 index 0000000..ac39bfb --- /dev/null +++ b/PLSQL Problem Solving/roman-numerals/.exercism/config.json @@ -0,0 +1,19 @@ +{ + "blurb": "Write a function to convert from normal numbers to Roman Numerals.", + "authors": [ + "chezwicker" + ], + "files": { + "solution": [ + "ut_numeral#.plsql" + ], + "test": [ + "ut_numeral#.plsql" + ], + "example": [ + ".meta/example.plsql" + ] + }, + "source": "The Roman Numeral Kata", + "source_url": "http://codingdojo.org/cgi-bin/index.pl?KataRomanNumerals" +} diff --git a/PLSQL Problem Solving/roman-numerals/.exercism/metadata.json b/PLSQL Problem Solving/roman-numerals/.exercism/metadata.json new file mode 100644 index 0000000..1bc00c0 --- /dev/null +++ b/PLSQL Problem Solving/roman-numerals/.exercism/metadata.json @@ -0,0 +1 @@ +{"track":"plsql","exercise":"roman-numerals","id":"86fa443992e3474e8599761e687f7d56","url":"https://exercism.org/tracks/plsql/exercises/roman-numerals","handle":"radwanromy","is_requester":true,"auto_approve":false} \ No newline at end of file diff --git a/PLSQL Problem Solving/roman-numerals/HELP.md b/PLSQL Problem Solving/roman-numerals/HELP.md new file mode 100644 index 0000000..00275ea --- /dev/null +++ b/PLSQL Problem Solving/roman-numerals/HELP.md @@ -0,0 +1,34 @@ +# Help + +## Running the tests + +Execute the tests by calling the `run` method in the respective `ut_#` package, +where `` is replaced with the exercise name. + +## Submitting your solution + +You can submit your solution using the `exercism submit ut_numeral#.plsql` command. +This command will upload your solution to the Exercism website and print the solution page's URL. + +It's possible to submit an incomplete solution which allows you to: + +- See how others have completed the exercise +- Request help from a mentor + +## Need to get help? + +If you'd like help solving the exercise, check the following pages: + +- The [PL/SQL track's documentation](https://exercism.org/docs/tracks/plsql) +- [Exercism's support channel on gitter](https://gitter.im/exercism/support) +- The [Frequently Asked Questions](https://exercism.org/docs/using/faqs) + +Should those resources not suffice, you could submit your (incomplete) solution to request mentoring. + +To get help if you're having trouble, you can use one of the following resources: + +- [Oracle - PL/SQL Language Reference](http://docs.oracle.com/cd/E11882_01/appdev.112/e25519/toc.htm) +- [Builtin Function Reference](http://psoug.org/reference/builtin_functions.html) +- [Ask Tom](https://asktom.oracle.com/) - Advice by the PL/SQL Guru +- [/r/plsql](https://www.reddit.com/r/plsql) is the C# subreddit. +- [StackOverflow](http://stackoverflow.com/questions/tagged/plsql) can be used to search for your problem and see if it has been answered already. You can also ask and answer questions. \ No newline at end of file diff --git a/PLSQL Problem Solving/roman-numerals/README.md b/PLSQL Problem Solving/roman-numerals/README.md new file mode 100644 index 0000000..4ee83a0 --- /dev/null +++ b/PLSQL Problem Solving/roman-numerals/README.md @@ -0,0 +1,58 @@ +# Roman Numerals + +Welcome to Roman Numerals on Exercism's PL/SQL Track. +If you need help running the tests or submitting your code, check out `HELP.md`. + +## Instructions + +Write a function to convert from normal numbers to Roman Numerals. + +The Romans were a clever bunch. They conquered most of Europe and ruled +it for hundreds of years. They invented concrete and straight roads and +even bikinis. One thing they never discovered though was the number +zero. This made writing and dating extensive histories of their exploits +slightly more challenging, but the system of numbers they came up with +is still in use today. For example the BBC uses Roman numerals to date +their programmes. + +The Romans wrote numbers using letters - I, V, X, L, C, D, M. (notice +these letters have lots of straight lines and are hence easy to hack +into stone tablets). + +```text + 1 => I +10 => X + 7 => VII +``` + +There is no need to be able to convert numbers larger than about 3000. +(The Romans themselves didn't tend to go any higher) + +Wikipedia says: Modern Roman numerals ... are written by expressing each +digit separately starting with the left most digit and skipping any +digit with a value of zero. + +To see this in practice, consider the example of 1990. + +In Roman numerals 1990 is MCMXC: + +1000=M +900=CM +90=XC + +2008 is written as MMVIII: + +2000=MM +8=VIII + +See also: http://www.novaroma.org/via_romana/numbers.html + +## Source + +### Created by + +- @chezwicker + +### Based on + +The Roman Numeral Kata - http://codingdojo.org/cgi-bin/index.pl?KataRomanNumerals \ No newline at end of file diff --git a/PLSQL Problem Solving/roman-numerals/ut_numeral#.plsql b/PLSQL Problem Solving/roman-numerals/ut_numeral#.plsql new file mode 100644 index 0000000..5d2c0ae --- /dev/null +++ b/PLSQL Problem Solving/roman-numerals/ut_numeral#.plsql @@ -0,0 +1,51 @@ +create or replace package ut_numeral# +is + procedure run; +end ut_numeral#; +/ + +create or replace package body ut_numeral# +is + procedure test ( + i_descn varchar2 + ,i_exp varchar2 + ,i_act varchar2 + ) + is + begin + if i_exp = i_act then + dbms_output.put_line('SUCCESS: ' || i_descn); + else + dbms_output.put_line('FAILURE: ' || i_descn || ' - expected ' || nvl('' || i_exp, 'null') || ', but received ' || nvl('' || i_act, 'null')); + end if; + end test; + + procedure run + is + begin + test(i_descn => 'test_1', i_exp => 'I', i_act => numeral#.to_roman(1 )); + test(i_descn => 'test_2', i_exp => 'II', i_act => numeral#.to_roman(2 )); + test(i_descn => 'test_3', i_exp => 'III', i_act => numeral#.to_roman(3 )); + test(i_descn => 'test_4', i_exp => 'IV', i_act => numeral#.to_roman(4 )); + test(i_descn => 'test_5', i_exp => 'V', i_act => numeral#.to_roman(5 )); + test(i_descn => 'test_6', i_exp => 'VI', i_act => numeral#.to_roman(6 )); + test(i_descn => 'test_9', i_exp => 'IX', i_act => numeral#.to_roman(9 )); + test(i_descn => 'test_27', i_exp => 'XXVII', i_act => numeral#.to_roman(27 )); + test(i_descn => 'test_48', i_exp => 'XLVIII', i_act => numeral#.to_roman(48 )); + test(i_descn => 'test_59', i_exp => 'LIX', i_act => numeral#.to_roman(59 )); + test(i_descn => 'test_93', i_exp => 'XCIII', i_act => numeral#.to_roman(93 )); + test(i_descn => 'test_141', i_exp => 'CXLI', i_act => numeral#.to_roman(141 )); + test(i_descn => 'test_163', i_exp => 'CLXIII', i_act => numeral#.to_roman(163 )); + test(i_descn => 'test_402', i_exp => 'CDII', i_act => numeral#.to_roman(402 )); + test(i_descn => 'test_575', i_exp => 'DLXXV', i_act => numeral#.to_roman(575 )); + test(i_descn => 'test_911', i_exp => 'CMXI', i_act => numeral#.to_roman(911 )); + test(i_descn => 'test_1024', i_exp => 'MXXIV', i_act => numeral#.to_roman(1024)); + test(i_descn => 'test_3000', i_exp => 'MMM', i_act => numeral#.to_roman(3000)); + end run; +end ut_numeral#; +/ + +begin + ut_numeral#.run; +end; +/ diff --git a/PLSQL QUERY_EMPLOYEE.prc b/PLSQL QUERY_EMPLOYEE.prc new file mode 100644 index 0000000..f8be61f --- /dev/null +++ b/PLSQL QUERY_EMPLOYEE.prc @@ -0,0 +1,16 @@ +CREATE PROCEDURE query_employee +(p_id IN employees.employee_id%TYPE, + p_name OUT employees.last_name%TYPE, + p_salary OUT employees.salary%TYPE, + p_comm OUT + employees.commission_pct%TYPE) +AUTHID CURRENT_USER +IS +BEGIN + SELECT last_name, salary, + commission_pct + INTO p_name, p_salary, p_comm + FROM employees + WHERE employee_id=p_id; +END query_employee; +/ diff --git a/PLSQL TAXES PACK.pkb b/PLSQL TAXES PACK.pkb new file mode 100644 index 0000000..7f8aa04 --- /dev/null +++ b/PLSQL TAXES PACK.pkb @@ -0,0 +1,5 @@ +CREATE OR REPLACE PACKAGE taxes_pack +IS + FUNCTION tax (p_value IN NUMBER) RETURN NUMBER; +END taxes_pack; +/ diff --git a/PLSQL UPDATED PACK_CUR.pkb b/PLSQL UPDATED PACK_CUR.pkb new file mode 100644 index 0000000..755a0d4 --- /dev/null +++ b/PLSQL UPDATED PACK_CUR.pkb @@ -0,0 +1,32 @@ +/* Formatted on 25-Oct-21 5:01:11 AM (QP5 v5.287) */ +CREATE OR REPLACE PACKAGE BODY pack_cur +IS + v_empno NUMBER; + + PROCEDURE proc1_3rows + IS + BEGIN + OPEN c1; + + LOOP + FETCH c1 INTO v_empno; + + DBMS_OUTPUT.PUT_LINE ('Id :' || (v_empno)); + EXIT WHEN c1%ROWCOUNT >= 3; + END LOOP; + END proc1_3rows; + + PROCEDURE proc4_6rows + IS + BEGIN + LOOP + FETCH c1 INTO v_empno; + + DBMS_OUTPUT.PUT_LINE ('Id :' || (v_empno)); + EXIT WHEN c1%ROWCOUNT >= 6; + END LOOP; + + CLOSE c1; + END proc4_6rows; +END pack_cur; +/ \ No newline at end of file diff --git a/PLSQL Update Salary By Cursor.sql b/PLSQL Update Salary By Cursor.sql new file mode 100644 index 0000000..d9c7adc --- /dev/null +++ b/PLSQL Update Salary By Cursor.sql @@ -0,0 +1,13 @@ +/* Formatted on 24/Oct/21 10:12:46 PM (QP5 v5.287) */ +DECLARE + CURSOR emp_cursor(n_department_id NUMBER) + IS + SELECT employee_id, last_name, department_name + FROM employees, departments + WHERE employees.department_id = departments.department_id + AND employees.department_id = n_department_id + FOR UPDATE OF salary NOWAIT; +BEGIN + OPEN emp_cursor(90); + CLOSE emp_cursor; +END; \ No newline at end of file diff --git a/PLSQL Where Current of And Update For Query.sql b/PLSQL Where Current of And Update For Query.sql new file mode 100644 index 0000000..463fd27 --- /dev/null +++ b/PLSQL Where Current of And Update For Query.sql @@ -0,0 +1,23 @@ +/* Formatted on 24/Oct/21 10:32:49 PM (QP5 v5.287) */ +DECLARE + CURSOR sal_cursor + IS + SELECT e.department_id, + employee_id, + last_name, + salary + FROM employees e, departments d + WHERE d.department_id = e.department_id AND d.department_id = 60 + FOR UPDATE OF salary NOWAIT; +BEGIN + FOR emp_record IN sal_cursor + LOOP + IF emp_record.salary < 5000 + THEN + UPDATE employees + SET salary = emp_record.salary * 1.10 + WHERE CURRENT OF sal_cursor; + END IF; + END LOOP; +END; +/ \ No newline at end of file diff --git a/PLSQL create and replace.prc b/PLSQL create and replace.prc new file mode 100644 index 0000000..ae7e53f --- /dev/null +++ b/PLSQL create and replace.prc @@ -0,0 +1,9 @@ +CREATE OR REPLACE PROCEDURE raise_salary + (p_id IN employees.employee_id%TYPE) +IS +BEGIN + UPDATE employees + SET salary = salary * 1.10 + WHERE employee_id = p_id; +END raise_salary; +/ diff --git a/PLSQL_COMM_PACKAGE.pkb b/PLSQL_COMM_PACKAGE.pkb new file mode 100644 index 0000000..48f7f55 --- /dev/null +++ b/PLSQL_COMM_PACKAGE.pkb @@ -0,0 +1,15 @@ +CREATE OR REPLACE PACKAGE BODY comm_package +IS + FUNCTION validate_comm (p_comm IN NUMBER) + RETURN BOOLEAN + IS + v_max_comm NUMBER; + BEGIN + SELECT MAX(commission_pct) + INTO v_max_comm + FROM employees; + IF p_comm > v_max_comm THEN RETURN(FALSE); + ELSE RETURN(TRUE); + END IF; + END validate_comm; +End; diff --git a/PLSQL_COMM_PACKAGE_.pkb b/PLSQL_COMM_PACKAGE_.pkb new file mode 100644 index 0000000..c8fab83 --- /dev/null +++ b/PLSQL_COMM_PACKAGE_.pkb @@ -0,0 +1,14 @@ +/* Formatted on 25-Oct-21 4:12:33 AM (QP5 v5.287) */ +CREATE OR REPLACE PACKAGE BODY comm_package +IS + PROCEDURE reset_comm (p_comm IN NUMBER) + IS + BEGIN + IF validate_comm (p_comm) + THEN + g_comm := p_comm; + ELSE + RAISE_APPLICATION_ERROR (-20210, 'Invalid commission'); + END IF; + END reset_comm; +END comm_package; \ No newline at end of file diff --git a/PLSQL_DELETE_ALL_ROWS.prc b/PLSQL_DELETE_ALL_ROWS.prc new file mode 100644 index 0000000..3006e4d --- /dev/null +++ b/PLSQL_DELETE_ALL_ROWS.prc @@ -0,0 +1,12 @@ +CREATE OR REPLACE PROCEDURE delete_all_rows + (p_tab_name IN VARCHAR2, p_rows_del OUT NUMBER) + IS + cursor_name INTEGER; + BEGIN + cursor_name := DBMS_SQL.OPEN_CURSOR; + DBMS_SQL.PARSE(cursor_name, 'DELETE FROM '||p_tab_name, + DBMS_SQL.NATIVE ); + p_rows_del := DBMS_SQL.EXECUTE (cursor_name); + DBMS_SQL.CLOSE_CURSOR(cursor_name); +END; +/ diff --git a/PLSQL_DEL_ROWS.prc b/PLSQL_DEL_ROWS.prc new file mode 100644 index 0000000..dad7f8f --- /dev/null +++ b/PLSQL_DEL_ROWS.prc @@ -0,0 +1,9 @@ +CREATE PROCEDURE del_rows + (p_table_name IN VARCHAR2, + p_rows_deld OUT NUMBER) +IS +BEGIN + EXECUTE IMMEDIATE 'delete from '||p_table_name; + p_rows_deld := SQL%ROWCOUNT; +END; +/ diff --git a/PLSQL_DML_CALL_SQL.fnc b/PLSQL_DML_CALL_SQL.fnc new file mode 100644 index 0000000..a864a33 --- /dev/null +++ b/PLSQL_DML_CALL_SQL.fnc @@ -0,0 +1,14 @@ +CREATE OR REPLACE FUNCTION dml_call_sql (p_sal NUMBER) + RETURN NUMBER IS +BEGIN + INSERT INTO employees(employee_id, last_name, email, + hire_date, job_id, salary) + VALUES(1, 'employee 1', 'emp1@company.com', + SYSDATE, 'SA_MAN', 1000); + RETURN (p_sal + 100); + +UPDATE employees SET salary = dml_call_sql(2000) + WHERE employee_id = 170; +END; +/ + diff --git a/PLSQL_EMAIL_VALIDATION.fnc b/PLSQL_EMAIL_VALIDATION.fnc new file mode 100644 index 0000000..bc39aef --- /dev/null +++ b/PLSQL_EMAIL_VALIDATION.fnc @@ -0,0 +1,48 @@ +/* Formatted on 27/Oct/21 5:22:57 PM (QP5 v5.287) */ +CREATE OR REPLACE FUNCTION email_validation (email_address IN VARCHAR2) + RETURN VARCHAR2 +IS + at_the_rate NUMBER; + dot_symbol NUMBER; + c_at_the_rate NUMBER; + c_dot_symbol NUMBER; + string_length NUMBER; +BEGIN + -- domain := INSTR (email_address, 'com'or '.in'or'.bd'or '.gov'or '.org'); + at_the_rate := INSTR (email_address, '@'); + dot_symbol := INSTR (email_address, '.'); + string_length := LENGTH (email_address); + c_at_the_rate := Count(email_address, '@'); + c_dot_symbol := Count(email_address, '@'); + + + IF ( ( (dot_symbol = 0) + OR (at_the_rate = 0) + OR (dot_symbol = at_the_rate + 1) + OR (at_the_rate = 1) + OR (at_the_rate = string_length) + OR (dot_symbol = string_length) + OR (COUNT(INSTR (email_address, '@')) > 1))) + THEN + RETURN 'Invalid email addresses'; + END IF; + + /* + IF INSTR (SUBSTR (email_address, at_the_rate), '.') = 0 + THEN + RETURN 'Invalid email addresses'; + END IF; + + IF TO_NUMBER (INSTR (email_address, at_the_rate)) >1 + THEN + RETURN 'Invalid email addresses'; + END IF; + IF TO_NUMBER (INSTR (email_address, dot_symbol)) >1 + THEN + RETURN 'Invalid email addresses'; + END IF; */ + + + + RETURN 'Valid email addresses'; +END email_validation; \ No newline at end of file diff --git a/PLSQL_EMAIL_VALIDATION_UPDATED.fnc b/PLSQL_EMAIL_VALIDATION_UPDATED.fnc new file mode 100644 index 0000000..61bda2d --- /dev/null +++ b/PLSQL_EMAIL_VALIDATION_UPDATED.fnc @@ -0,0 +1,50 @@ +/* Formatted on 27/Oct/21 5:22:57 PM (QP5 v5.287) */ +CREATE OR REPLACE FUNCTION email_validation (email_address IN VARCHAR2) + RETURN VARCHAR2 +IS + at_the_rate NUMBER; + dot_symbol NUMBER; + c_at_the_rate NUMBER; + c_dot_symbol NUMBER; + string_length NUMBER; +BEGIN + -- domain := INSTR (email_address, 'com'or '.in'or'.bd'or '.gov'or '.org'); + at_the_rate := INSTR (email_address, '@'); + dot_symbol := INSTR (email_address, '.'); + string_length := LENGTH (email_address); + c_at_the_rate := ROUND(LENGTH(email_address)-LENGTH(REplace(email_address, '@'))); + c_dot_symbol := ROUND(LENGTH(email_address)-LENGTH(REplace(email_address, '.'))); + -- after_at_the_rate := c_at_the_rate+1; + + + IF ( ( (dot_symbol = 0) + OR (at_the_rate = 0) + OR (dot_symbol = at_the_rate + 1) + OR (at_the_rate = 1) + OR (c_at_the_rate> 1) + OR (c_dot_symbol=c_at_the_rate+1) + OR (at_the_rate = string_length) + OR (dot_symbol = string_length))) + THEN + RETURN 'Invalid email addresses'; + END IF; + + /* + IF INSTR (SUBSTR (email_address, at_the_rate), '.') = 0 + THEN + RETURN 'Invalid email addresses'; + END IF; + + IF TO_NUMBER (INSTR (email_address, at_the_rate)) >1 + THEN + RETURN 'Invalid email addresses'; + END IF; + IF TO_NUMBER (INSTR (email_address, dot_symbol)) >1 + THEN + RETURN 'Invalid email addresses'; + END IF; */ + + + + RETURN 'Valid email addresses'; +END email_validation; \ No newline at end of file diff --git a/PLSQL_EMP_PACK.pks b/PLSQL_EMP_PACK.pks new file mode 100644 index 0000000..85c6101 --- /dev/null +++ b/PLSQL_EMP_PACK.pks @@ -0,0 +1,7 @@ +CREATE OR REPLACE PACKAGE emp_package IS + TYPE emp_table_type IS TABLE OF employees%ROWTYPE + INDEX BY BINARY_INTEGER; + PROCEDURE read_emp_table + (p_emp_table OUT emp_table_type); +END emp_package; +/ diff --git a/PLSQL_EMP_PACKAGE.pkb b/PLSQL_EMP_PACKAGE.pkb new file mode 100644 index 0000000..f71a2d4 --- /dev/null +++ b/PLSQL_EMP_PACKAGE.pkb @@ -0,0 +1,12 @@ +CREATE OR REPLACE PACKAGE BODY emp_package IS + PROCEDURE read_emp_table (p_emp_table OUT emp_table_type) IS + i BINARY_INTEGER := 0; + BEGIN + FOR emp_record IN (SELECT * FROM employees) + LOOP + p_emp_table(i) := emp_record; + i:= i+1; + END LOOP; + END read_emp_table; +END emp_package; +/ diff --git a/PLSQL_GETLEANTH.sql b/PLSQL_GETLEANTH.sql new file mode 100644 index 0000000..e367d4d --- /dev/null +++ b/PLSQL_GETLEANTH.sql @@ -0,0 +1,31 @@ +/* Formatted on 25/Oct/21 11:22:37 PM (QP5 v5.287) */ +DECLARE + lobloc CLOB; -- serves as the LOB locator + text VARCHAR2 (32767) := 'Resigned: 5 August 2000'; + amount NUMBER; -- amount to be written + offset INTEGER; -- where to start writing +BEGIN + SELECT resume + INTO lobloc + FROM employees + WHERE employee_id = 405 + FOR UPDATE; + + offset := DBMS_LOB.GETLENGTH (lobloc) + 2; + amount := LENGTH (text); + DBMS_LOB.WRITE (lobloc, + amount, + offset, + text); + text := ' Resigned: 30 September 2000'; + + SELECT resume + INTO lobloc + FROM employees + WHERE employee_id = 170 + FOR UPDATE; + + amount := LENGTH (text); + DBMS_LOB.WRITEAPPEND (lobloc, amount, text); + COMMIT; +END; \ No newline at end of file diff --git a/PLSQL_LOAD_EMP_BFILE.prc b/PLSQL_LOAD_EMP_BFILE.prc new file mode 100644 index 0000000..e90ef42 --- /dev/null +++ b/PLSQL_LOAD_EMP_BFILE.prc @@ -0,0 +1,32 @@ +/* Formatted on 25/Oct/21 10:42:18 PM (QP5 v5.287) */ +CREATE OR REPLACE PROCEDURE load_emp_bfile (p_file_loc IN VARCHAR2) +IS + v_file BFILE; + v_filename VARCHAR2 (16); + + CURSOR emp_cursor + IS + SELECT first_name + FROM employees + WHERE department_id = 60 + FOR UPDATE; +BEGIN + FOR emp_record IN emp_cursor + LOOP + v_filename := emp_record.first_name || '.bmp'; + v_file := BFILENAME (p_file_loc, v_filename); + DBMS_LOB.FILEOPEN (v_file); + + UPDATE employees + SET emp_video = v_file + WHERE CURRENT OF emp_cursor; + + DBMS_OUTPUT.PUT_LINE ( + 'LOADED FILE: ' + || v_filename + || ' SIZE: ' + || DBMS_LOB.GETLENGTH (v_file)); + DBMS_LOB.FILECLOSE (v_file); + END LOOP; +END load_emp_bfile; +/ \ No newline at end of file diff --git a/PLSQL_METER_TO_YARD.prc b/PLSQL_METER_TO_YARD.prc new file mode 100644 index 0000000..9923681 --- /dev/null +++ b/PLSQL_METER_TO_YARD.prc @@ -0,0 +1,12 @@ +/* Formatted on 25-Oct-21 4:38:12 AM (QP5 v5.287) */ +CREATE OR REPLACE PROCEDURE meter_to_yard (p_meter IN NUMBER, + p_yard OUT NUMBER) +IS +BEGIN + p_yard := p_meter * global_consts.meter_2_yard; +END meter_to_yard; +/ + +VARIABLE yard NUMBER +EXECUTE meter_to_yard (1, :yard) +PRINT yard \ No newline at end of file diff --git a/PLSQL_OVER_PACK.pks b/PLSQL_OVER_PACK.pks new file mode 100644 index 0000000..65bef3d --- /dev/null +++ b/PLSQL_OVER_PACK.pks @@ -0,0 +1,13 @@ +/* Formatted on 25-Oct-21 4:47:21 AM (QP5 v5.287) */ +CREATE OR REPLACE PACKAGE over_pack +IS + PROCEDURE add_dept ( + p_deptno IN departments.department_id%TYPE, + p_name IN departments.department_name%TYPE DEFAULT 'unknown', + p_loc IN departments.location_id%TYPE DEFAULT 0); + + PROCEDURE add_dept ( + p_name IN departments.department_name%TYPE DEFAULT 'unknown', + p_loc IN departments.location_id%TYPE DEFAULT 0); +END over_pack; +/ \ No newline at end of file diff --git a/PLSQL_PROCESS_EMPS.prc b/PLSQL_PROCESS_EMPS.prc new file mode 100644 index 0000000..1dfebdd --- /dev/null +++ b/PLSQL_PROCESS_EMPS.prc @@ -0,0 +1,15 @@ +/* Formatted on 25/Oct/21 3:12:25 AM (QP5 v5.287) */ +CREATE OR REPLACE PROCEDURE process_emps +IS + CURSOR emp_cursor + IS + SELECT employee_id FROM employees; +BEGIN + FOR emp_rec IN emp_cursor + LOOP + raise_salary (emp_rec.employee_id); + END LOOP; + + COMMIT; +END process_emps; +/ \ No newline at end of file diff --git a/PLSQL_UPDATED_OVER_PACK.pkb b/PLSQL_UPDATED_OVER_PACK.pkb new file mode 100644 index 0000000..32f0b1f --- /dev/null +++ b/PLSQL_UPDATED_OVER_PACK.pkb @@ -0,0 +1,23 @@ +/* Formatted on 25-Oct-21 4:49:06 AM (QP5 v5.287) */ +CREATE OR REPLACE PACKAGE BODY over_pack +IS + PROCEDURE add_dept ( + p_deptno IN departments.department_id%TYPE, + p_name IN departments.department_name%TYPE DEFAULT 'unknown', + p_loc IN departments.location_id%TYPE DEFAULT 0) + IS + BEGIN + INSERT INTO departments (department_id, department_name, location_id) + VALUES (p_deptno, p_name, p_loc); + END add_dept; + + PROCEDURE add_dept ( + p_name IN departments.department_name%TYPE DEFAULT 'unknown', + p_loc IN departments.location_id%TYPE DEFAULT 0) + IS + BEGIN + INSERT INTO departments (department_id, department_name, location_id) + VALUES (departments_seq.NEXTVAL, p_name, p_loc); + END add_dept; +END over_pack; +/ \ No newline at end of file diff --git a/PLSQL_UPDATED_TAXES_PACK.pkb b/PLSQL_UPDATED_TAXES_PACK.pkb new file mode 100644 index 0000000..2720cf6 --- /dev/null +++ b/PLSQL_UPDATED_TAXES_PACK.pkb @@ -0,0 +1,10 @@ +CREATE OR REPLACE PACKAGE BODY taxes_pack +IS + FUNCTION tax (p_value IN NUMBER) RETURN NUMBER + IS + v_rate NUMBER := 0.08; + BEGIN + RETURN (p_value * v_rate); + END tax; +END taxes_pack; +/ diff --git a/PLSQP_RESET_COMM.prc b/PLSQP_RESET_COMM.prc new file mode 100644 index 0000000..fee9903 --- /dev/null +++ b/PLSQP_RESET_COMM.prc @@ -0,0 +1,10 @@ + PROCEDURE reset_comm (p_comm IN NUMBER) + IS + BEGIN + IF validate_comm(p_comm) + THEN g_comm:=p_comm; --reset global variable + ELSE + RAISE_APPLICATION_ERROR(-20210,'Invalid commission'); + END IF; + END reset_comm; + / diff --git a/Package Procedure to perform in trigger updated.sql b/Package Procedure to perform in trigger updated.sql new file mode 100644 index 0000000..c961ad2 --- /dev/null +++ b/Package Procedure to perform in trigger updated.sql @@ -0,0 +1,48 @@ +/* Formatted on 09-Nov-21 1:15:34 PM (QP5 v5.287) */ +CREATE OR REPLACE PACKAGE BODY e_tpp +AS + PROCEDURE addEmployee (e_id employee.employee_id%TYPE, + e_name employee.last_name%TYPE, + e_job employee.job_id%TYPE, + e_sal employee.salary%TYPE) + IS + BEGIN + INSERT INTO employee (employee_id, + last_name, + job_id, + salary) + VALUES (e_id, + e_name, + e_job, + e_sal); + END addEmployee; + + PROCEDURE delEmployee (e_id employee.employee_id%TYPE) + IS + BEGIN + DELETE FROM employee + WHERE employee_id = c_id; + END delEmployee; + + PROCEDURE listEmployee + IS + CURSOR e_employees + IS + SELECT name FROM employee; + + TYPE e_list IS TABLE OF employee.last_name%TYPE; + + name_list c_list := c_list (); + counter INTEGER := 0; + BEGIN + FOR n IN e_employees + LOOP + counter := counter + 1; + name_list.EXTEND; + name_list (counter) := n.name; + DBMS_OUTPUT.put_line ( + 'Customer(' || counter || ')' || name_list (counter)); + END LOOP; + END listCustomer; +END e_tpp; +/ \ No newline at end of file diff --git a/Package Procedure to perform in trigger.sql b/Package Procedure to perform in trigger.sql new file mode 100644 index 0000000..c961ad2 --- /dev/null +++ b/Package Procedure to perform in trigger.sql @@ -0,0 +1,48 @@ +/* Formatted on 09-Nov-21 1:15:34 PM (QP5 v5.287) */ +CREATE OR REPLACE PACKAGE BODY e_tpp +AS + PROCEDURE addEmployee (e_id employee.employee_id%TYPE, + e_name employee.last_name%TYPE, + e_job employee.job_id%TYPE, + e_sal employee.salary%TYPE) + IS + BEGIN + INSERT INTO employee (employee_id, + last_name, + job_id, + salary) + VALUES (e_id, + e_name, + e_job, + e_sal); + END addEmployee; + + PROCEDURE delEmployee (e_id employee.employee_id%TYPE) + IS + BEGIN + DELETE FROM employee + WHERE employee_id = c_id; + END delEmployee; + + PROCEDURE listEmployee + IS + CURSOR e_employees + IS + SELECT name FROM employee; + + TYPE e_list IS TABLE OF employee.last_name%TYPE; + + name_list c_list := c_list (); + counter INTEGER := 0; + BEGIN + FOR n IN e_employees + LOOP + counter := counter + 1; + name_list.EXTEND; + name_list (counter) := n.name; + DBMS_OUTPUT.put_line ( + 'Customer(' || counter || ')' || name_list (counter)); + END LOOP; + END listCustomer; +END e_tpp; +/ \ No newline at end of file diff --git a/Package Test Execute.pks b/Package Test Execute.pks new file mode 100644 index 0000000..5a1ec04 --- /dev/null +++ b/Package Test Execute.pks @@ -0,0 +1,2 @@ +--EXECUTE p_email_validation( 'radwanromy@gmail.com'); + EXECUTE dpk_radwan.p_email_validation('radwanromy@gmail.com'); diff --git a/Packages Execute 02.pkb b/Packages Execute 02.pkb new file mode 100644 index 0000000..4789be8 --- /dev/null +++ b/Packages Execute 02.pkb @@ -0,0 +1,2 @@ +EXECUTE package_adv.e_all(30); +EXECUTE package_adv.e_salary(30); \ No newline at end of file diff --git a/SECURITY.md b/SECURITY.md new file mode 100644 index 0000000..034e848 --- /dev/null +++ b/SECURITY.md @@ -0,0 +1,21 @@ +# Security Policy + +## Supported Versions + +Use this section to tell people about which versions of your project are +currently being supported with security updates. + +| Version | Supported | +| ------- | ------------------ | +| 5.1.x | :white_check_mark: | +| 5.0.x | :x: | +| 4.0.x | :white_check_mark: | +| < 4.0 | :x: | + +## Reporting a Vulnerability + +Use this section to tell people how to report a vulnerability. + +Tell them where to go, how often they can expect to get an update on a +reported vulnerability, what to expect if the vulnerability is accepted or +declined, etc. diff --git a/SYS_CONTEXT.sql b/SYS_CONTEXT.sql new file mode 100644 index 0000000..ec6337d --- /dev/null +++ b/SYS_CONTEXT.sql @@ -0,0 +1 @@ +SELECT SYS_CONTEXT('USERENV','Host') FROM dual; \ No newline at end of file diff --git a/Test.fnc b/Test.fnc new file mode 100644 index 0000000..49dd5da --- /dev/null +++ b/Test.fnc @@ -0,0 +1 @@ +Select email_validation('radwanromy@@gmail.com') from dual; \ No newline at end of file diff --git a/Test_Email_Validation.fnc b/Test_Email_Validation.fnc new file mode 100644 index 0000000..35c57dc --- /dev/null +++ b/Test_Email_Validation.fnc @@ -0,0 +1 @@ +Select email_validation('ra.dwan_romy@gmail.bd.in') from dual; \ No newline at end of file diff --git a/Trigger 003 DML_EMP_VALUES.trg b/Trigger 003 DML_EMP_VALUES.trg new file mode 100644 index 0000000..f2fdc32 --- /dev/null +++ b/Trigger 003 DML_EMP_VALUES.trg @@ -0,0 +1,90 @@ +/* Formatted on 03-Nov-21 11:55:31 AM (QP5 v5.287) */ +CREATE OR REPLACE TRIGGER dml_emp_values + AFTER DELETE OR INSERT OR UPDATE + ON employee + FOR EACH ROW + ENABLE +DECLARE + idn NUMBER (6, 0); + user_name VARCHAR2 (25); + timestampn VARCHAR2 (25); + old_last_name VARCHAR2 (25); + new_last_name VARCHAR2 (25); + old_title VARCHAR2 (10); + new_title VARCHAR2 (10); + old_salary VARCHAR2 (10); + new_salary VARCHAR2 (10); +BEGIN + SELECT USER, TO_CHAR (SYSDATE, 'DD/MON/YYYY HH24:MI:SS') + INTO user_name, timestampn + FROM DUAL; + + IF INSERTING + THEN + INSERT INTO t_emp_table (user_name, + timestampn, + idn, + old_last_name, + new_last_name, + old_title, + new_title, + old_salary, + new_salary, + operation) + VALUES (USER, + SYSDATE, + :NEW.employee_id, + :NEW.last_name, + :NEW.last_name, + :NEW.job_id, + :NEW.last_name, + :NEW.salary, + :NEW.salary, + 'Insert'); + ELSIF DELETING + THEN + INSERT INTO t_emp_table (user_name, + timestampn, + idn, + old_last_name, + new_last_name, + old_title, + new_title, + old_salary, + new_salary, + operation) + VALUES (USER, + SYSDATE, + :OLD.employee_id, + :OLD.last_name, + :OLD.last_name, + :OLD.job_id, + :OLD.last_name, + :OLD.salary, + :OLD.salary, + 'Delete'); + ELSIF UPDATING + THEN + INSERT INTO t_emp_table (user_name, + timestampn, + idn, + old_last_name, + new_last_name, + old_title, + new_title, + old_salary, + new_salary, + operation) + VALUES (USER, + SYSDATE, + :OLD.employee_id, + :OLD.last_name, + :NEW.last_name, + :OLD.job_id, + :NEW.last_name, + :OLD.salary, + :NEW.salary, + 'Insert'); + END IF; +END; +/ \ No newline at end of file diff --git a/Trigger Delete Check.trg b/Trigger Delete Check.trg new file mode 100644 index 0000000..5391481 --- /dev/null +++ b/Trigger Delete Check.trg @@ -0,0 +1,3 @@ +/* Formatted on 03-Nov-21 12:25:35 PM (QP5 v5.287) */ +DELETE FROM employee + WHERE employee_id = 12; \ No newline at end of file diff --git a/Trigger Insert Check.trg b/Trigger Insert Check.trg new file mode 100644 index 0000000..8c30e80 --- /dev/null +++ b/Trigger Insert Check.trg @@ -0,0 +1,3 @@ +UPDATE employee +SET last_name = 'Ansu', job_id= 'Player' +WHERE employee_id = 11; \ No newline at end of file diff --git a/Trigger Store Test.trg b/Trigger Store Test.trg new file mode 100644 index 0000000..84f32c3 --- /dev/null +++ b/Trigger Store Test.trg @@ -0,0 +1 @@ +select * from t_emp_table; \ No newline at end of file diff --git a/Trigger Table Check.trg b/Trigger Table Check.trg new file mode 100644 index 0000000..5a6b369 --- /dev/null +++ b/Trigger Table Check.trg @@ -0,0 +1 @@ +Select * from employee; \ No newline at end of file diff --git a/Trigger Test Insert.trg b/Trigger Test Insert.trg new file mode 100644 index 0000000..97ad2a0 --- /dev/null +++ b/Trigger Test Insert.trg @@ -0,0 +1,4 @@ +/* Formatted on 03-Nov-21 12:04:34 PM (QP5 v5.287) */ +INSERT INTO employee (employee_id,last_name,job_id,salary) + VALUES (013, 'FAS' , 'IT', 4000 + ); diff --git a/TriggerExecuting.pks b/TriggerExecuting.pks new file mode 100644 index 0000000..12417e1 --- /dev/null +++ b/TriggerExecuting.pks @@ -0,0 +1,4 @@ +--EXECUTE p_email_validation( 'radwanromy@gmail.com'); + --EXECUTE e_tpp.addEmployee(034,'Radwan','CEO',5000); + EXECUTE e_tpp.delEmployee(034); + EXECUTE e_tpp.upEmployee(033,'Romy','SQT',5000); diff --git a/TriggerPP002.pks b/TriggerPP002.pks new file mode 100644 index 0000000..17c08a6 --- /dev/null +++ b/TriggerPP002.pks @@ -0,0 +1,14 @@ +CREATE OR REPLACE PACKAGE e_tpp +AS + + PROCEDURE delEmployee (e_id employee.employee_id%TYPE); + + PROCEDURE addEmployee (e_id employee.employee_id%TYPE, + e_name employee.last_name%TYPE, + e_job employee.job_id%TYPE, + e_sal employee.salary%TYPE); + PROCEDURE upEmployee (e_id employee.employee_id%TYPE, + e_name employee.last_name%TYPE, + e_job employee.job_id%TYPE, + e_sal employee.salary%TYPE); +END e_tpp; diff --git a/Trigger_Temp_Table.trg b/Trigger_Temp_Table.trg new file mode 100644 index 0000000..517ace1 --- /dev/null +++ b/Trigger_Temp_Table.trg @@ -0,0 +1,13 @@ +CREATE TABLE t_emp_table( +user_name varchar(255) NOT NULL, + timestampn varchar(255) NOT NULL, + idn int NOT NULL, + old_last_name varchar(255) NOT NULL, + new_last_name varchar(255) NOT NULL, + old_title varchar(255) NOT NULL, + new_title varchar(255) NOT NULL, + old_salary varchar(255) NOT NULL, + new_salary varchar(255) NOT NULL, + operation varchar(255) NOT NULL, + PRIMARY KEY (IDN) +); \ No newline at end of file diff --git a/UP DEL ADD Package Procedure to perform in trigger.sql b/UP DEL ADD Package Procedure to perform in trigger.sql new file mode 100644 index 0000000..c7e3a99 --- /dev/null +++ b/UP DEL ADD Package Procedure to perform in trigger.sql @@ -0,0 +1,61 @@ +/* Formatted on 09-Nov-21 3:13:14 PM (QP5 v5.287) */ +CREATE OR REPLACE PACKAGE BODY e_tpp +AS + PROCEDURE addEmployee (e_id employee.employee_id%TYPE, + e_name employee.last_name%TYPE, + e_job employee.job_id%TYPE, + e_sal employee.salary%TYPE) + IS + BEGIN + INSERT INTO employee (employee_id, + last_name, + job_id, + salary) + VALUES (e_id, + e_name, + e_job, + e_sal); + END addEmployee; + + PROCEDURE delEmployee (e_id employee.employee_id%TYPE) + IS + BEGIN + DELETE FROM employee + WHERE employee_id = e_id; + END delEmployee; + + PROCEDURE upEmployee (e_id employee.employee_id%TYPE, + e_name employee.last_name%TYPE, + e_job employee.job_id%TYPE, + e_sal employee.salary%TYPE) + IS + BEGIN + UPDATE employee + SET last_name = e_name, job_id = e_job, salary = e_sal + WHERE employee_id = e_id; + END upEmployee; +/* PROCEDURE listEmployee + IS + CURSOR e_employees + IS + SELECT last_name FROM employee; + + TYPE e_list IS TABLE OF employee.last_name%TYPE; + + name_list e_list := e_list (); + counter INTEGER := 0; + BEGIN + FOR n IN e_employees + LOOP + counter := counter + 1; + name_list.EXTEND; + name_list (counter) := n.last_name; + DBMS_OUTPUT.put_line ( + 'Customer(' || counter || ')' || name_list (counter)); + END LOOP; + END listEmployee; */ + + + +END e_tpp; +/ \ No newline at end of file diff --git a/XX_CHECK_EMAIL.fnc b/XX_CHECK_EMAIL.fnc new file mode 100644 index 0000000..320eb58 --- /dev/null +++ b/XX_CHECK_EMAIL.fnc @@ -0,0 +1,52 @@ +Create or replace + +FUNCTION xx_check_email(l_user_name IN VARCHAR2) + +RETURN VARCHAR2 IS + +l_dot_pos NUMBER; + +l_at_pos NUMBER; + +l_str_length NUMBER; + +BEGIN + + +l_dot_pos := instr(l_user_name + +,’.’); + +l_at_pos := instr(l_user_name + +,’@’); + +l_str_length := length(l_user_name); + +IF ((l_dot_pos = 0) OR (l_at_pos = 0) OR (l_dot_pos = l_at_pos + 1) OR + +(l_at_pos = 1) OR (l_at_pos = l_str_length) OR + +(l_dot_pos = l_str_length)) + +THEN + +RETURN ‘FAILURE’; + +END IF; + +IF instr(substr(l_user_name + +,l_at_pos) + +,’.’) = 0 + +THEN + +RETURN ‘FAILURE’; + +END IF; + +RETURN ‘SUCCESS’; + +end xx_check_email; \ No newline at end of file diff --git a/deleting using package procedure and store with trigger.sql b/deleting using package procedure and store with trigger.sql new file mode 100644 index 0000000..5f79e34 --- /dev/null +++ b/deleting using package procedure and store with trigger.sql @@ -0,0 +1 @@ +EXECUTE e_tpp.delEmployee(44); \ No newline at end of file diff --git a/login check using Procedure.prc b/login check using Procedure.prc new file mode 100644 index 0000000..1b8fe6a --- /dev/null +++ b/login check using Procedure.prc @@ -0,0 +1 @@ +EXECUTE log_inn('David', 'Austin'); \ No newline at end of file diff --git a/login check using function.fnc b/login check using function.fnc new file mode 100644 index 0000000..f21b944 --- /dev/null +++ b/login check using function.fnc @@ -0,0 +1 @@ +select log_in('David', 'Austin') from employees; \ No newline at end of file diff --git a/tpp01.pks b/tpp01.pks new file mode 100644 index 0000000..db1cc4a --- /dev/null +++ b/tpp01.pks @@ -0,0 +1,21 @@ +/* Formatted on 09/Nov/21 5:07:24 PM (QP5 v5.287) */ +CREATE OR REPLACE PACKAGE e_tpp +AS + PROCEDURE delEmployee (e_id employee.employee_id%TYPE); + + PROCEDURE insertEmployee; + + PROCEDURE deleteEmployee; + + PROCEDURE updateEmployee; + + PROCEDURE addEmployee (e_id employee.employee_id%TYPE, + e_name employee.last_name%TYPE, + e_job employee.job_id%TYPE, + e_sal employee.salary%TYPE); + + PROCEDURE upEmployee (e_id employee.employee_id%TYPE, + e_name employee.last_name%TYPE, + e_job employee.job_id%TYPE, + e_sal employee.salary%TYPE); +END e_tpp; \ No newline at end of file diff --git a/tpp02.sql b/tpp02.sql new file mode 100644 index 0000000..48fc6a1 --- /dev/null +++ b/tpp02.sql @@ -0,0 +1,126 @@ +/* Formatted on 09/Nov/21 5:51:53 PM (QP5 v5.287) */ +CREATE OR REPLACE PACKAGE BODY e_tpp + +AS + idn NUMBER (6, 0); + user_name VARCHAR2 (25); + timestampn VARCHAR2 (25); + old_last_name VARCHAR2 (25); + new_last_name VARCHAR2 (25); + old_title VARCHAR2 (10); + new_title VARCHAR2 (10); + old_salary VARCHAR2 (10); + new_salary VARCHAR2 (10); + + PROCEDURE addEmployee (e_id employee.employee_id%TYPE, + e_name employee.last_name%TYPE, + e_job employee.job_id%TYPE, + e_sal employee.salary%TYPE) + IS + BEGIN + INSERT INTO employee (employee_id, + last_name, + job_id, + salary) + VALUES (e_id, + e_name, + e_job, + e_sal); + END addEmployee; + + PROCEDURE delEmployee (e_id employee.employee_id%TYPE) + IS + BEGIN + DELETE FROM employee + WHERE employee_id = c_id; + END delEmployee; + + + + PROCEDURE insertEmployee + IS + BEGIN + SELECT USER, TO_CHAR (SYSDATE, 'DD/MON/YYYY HH24:MI:SS') + INTO user_name, timestampn + FROM DUAL; + + INSERT INTO t_emp_table (user_name, + timestampn, + idn, + old_last_name, + new_last_name, + old_title, + new_title, + old_salary, + new_salary, + operation) + VALUES (USER, + SYSDATE, + :NEW.HR.employee_id, + :NEW.last_name, + :NEW.last_name, + :NEW.job_id, + :NEW.last_name, + :NEW.salary, + :NEW.salary, + 'Insert'); + END insertEmployee; + + PROCEDURE deleteEmployee +IS + BEGIN + + SELECT USER, TO_CHAR (SYSDATE, 'DD/MON/YYYY HH24:MI:SS') + INTO user_name, timestampn + FROM DUAL; + INSERT INTO t_emp_table (user_name, + timestampn, + idn, + old_last_name, + new_last_name, + old_title, + new_title, + old_salary, + new_salary, + operation) + VALUES (USER, + SYSDATE, + :OLD.employee_id, + :OLD.last_name, + :OLD.last_name, + :OLD.job_id, + :OLD.last_name, + :OLD.salary, + :OLD.salary, + 'Delete'); + END DELETEEMPLOYEE; + PROCEDURE updateEmployee + IS + BEGIN + SELECT USER, TO_CHAR (SYSDATE, 'DD/MON/YYYY HH24:MI:SS') + INTO user_name, timestampn + FROM DUAL; + INSERT INTO t_emp_table (user_name, + timestampn, + idn, + old_last_name, + new_last_name, + old_title, + new_title, + old_salary, + new_salary, + operation) + VALUES (USER, + SYSDATE, + :OLD.employee_id, + :OLD.last_name, + :NEW.last_name, + :OLD.job_id, + :NEW.last_name, + :OLD.salary, + :NEW.salary, + 'Insert'); + END UPDATEEMPLOYEE; + +END e_tpp; +/ \ No newline at end of file diff --git a/tpp03.trg b/tpp03.trg new file mode 100644 index 0000000..5927221 --- /dev/null +++ b/tpp03.trg @@ -0,0 +1,23 @@ +/* Formatted on 03-Nov-21 11:55:31 AM (QP5 v5.287) */ +CREATE OR REPLACE TRIGGER dml_emp_values + AFTER DELETE OR INSERT OR UPDATE + ON employee + FOR EACH ROW + ENABLE + +BEGIN + + IF INSERTING + THEN + e_tpp.insertEmployee (); + + ELSIF DELETING + + THEN + e_tpp.deleteEmployee (); + ELSIF UPDATING + THEN + e_tpp.updateEmployee (); + END IF; +END; +/ \ No newline at end of file diff --git a/triggerPP01.sql b/triggerPP01.sql new file mode 100644 index 0000000..112a176 --- /dev/null +++ b/triggerPP01.sql @@ -0,0 +1,137 @@ +/* Formatted on 10/Nov/21 11:46:05 AM (QP5 v5.287) */ +CREATE OR REPLACE PACKAGE BODY e_tpp +AS + /* idn NUMBER (6, 0); + user_name VARCHAR2 (25); + timestampn VARCHAR2 (25); + old_last_name VARCHAR2 (25); + new_last_name VARCHAR2 (25); + old_title VARCHAR2 (10); + new_title VARCHAR2 (10); + old_salary VARCHAR2 (10); + new_salary VARCHAR2 (10); + */ + PROCEDURE addEmployee (e_id employee.employee_id%TYPE, + e_name employee.last_name%TYPE, + e_job employee.job_id%TYPE, + e_sal employee.salary%TYPE) + IS + BEGIN + INSERT INTO employee (employee_id, + last_name, + job_id, + salary) + VALUES (e_id, + e_name, + e_job, + e_sal); + END addEmployee; + + PROCEDURE delEmployee (e_id employee.employee_id%TYPE) + IS + BEGIN + DELETE FROM employee + WHERE employee_id = e_id; + END delEmployee; + + PROCEDURE upEmployee (e_id employee.employee_id%TYPE, + e_name employee.last_name%TYPE, + e_job employee.job_id%TYPE, + e_sal employee.salary%TYPE) + IS + BEGIN + UPDATE employee + SET last_name = e_name, job_id = e_job, salary = e_sal + WHERE employee_id = e_id; + END upEmployee; + /* + PROCEDURE insertEmployee + IS + BEGIN + SELECT USER, TO_CHAR (SYSDATE, 'DD/MON/YYYY HH24:MI:SS') + INTO user_name, timestampn + FROM DUAL; + + INSERT INTO t_emp_table (user_name, + timestampn, + idn, + old_last_name, + new_last_name, + old_title, + new_title, + old_salary, + new_salary, + operation) + VALUES (USER, + SYSDATE, + :NEW.employee_id, + :NEW.last_name, + :NEW.last_name, + :NEW.job_id, + :NEW.last_name, + :NEW.salary, + :NEW.salary, + 'Insert'); + END insertEmployee; + + PROCEDURE deleteEmployee +IS + BEGIN + + SELECT USER, TO_CHAR (SYSDATE, 'DD/MON/YYYY HH24:MI:SS') + INTO user_name, timestampn + FROM DUAL; + INSERT INTO t_emp_table (user_name, + timestampn, + idn, + old_last_name, + new_last_name, + old_title, + new_title, + old_salary, + new_salary, + operation) + VALUES (USER, + SYSDATE, + :OLD.employee_id, + :OLD.last_name, + :OLD.last_name, + :OLD.job_id, + :OLD.last_name, + :OLD.salary, + :OLD.salary, + 'Delete'); + END DELETEEMPLOYEE; + PROCEDURE updateEmployee + IS + BEGIN + SELECT USER, TO_CHAR (SYSDATE, 'DD/MON/YYYY HH24:MI:SS') + INTO user_name, timestampn + FROM DUAL; + INSERT INTO t_emp_table (user_name, + timestampn, + idn, + old_last_name, + new_last_name, + old_title, + new_title, + old_salary, + new_salary, + operation) + VALUES (USER, + SYSDATE, + :OLD.employee_id, + :OLD.last_name, + :NEW.last_name, + :OLD.job_id, + :NEW.last_name, + :OLD.salary, + :NEW.salary, + 'Insert'); + END UPDATEEMPLOYEE; +*/ + + + +END e_tpp; +/ \ No newline at end of file