{"id":19956598,"url":"https://github.com/abhinavkorpal/sql-pl-sql","last_synced_at":"2025-06-25T19:04:43.289Z","repository":{"id":50637575,"uuid":"295483327","full_name":"abhinavkorpal/SQL-PL-SQL","owner":"abhinavkorpal","description":"SQL-PL-SQL","archived":false,"fork":false,"pushed_at":"2021-07-28T17:17:07.000Z","size":606,"stargazers_count":2,"open_issues_count":0,"forks_count":3,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-03-01T15:44:16.788Z","etag":null,"topics":["database","plsql","sql"],"latest_commit_sha":null,"homepage":"","language":null,"has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"unlicense","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/abhinavkorpal.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2020-09-14T17:03:03.000Z","updated_at":"2021-07-28T17:17:10.000Z","dependencies_parsed_at":"2022-09-01T17:43:30.746Z","dependency_job_id":null,"html_url":"https://github.com/abhinavkorpal/SQL-PL-SQL","commit_stats":null,"previous_names":[],"tags_count":0,"template":true,"template_full_name":null,"purl":"pkg:github/abhinavkorpal/SQL-PL-SQL","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/abhinavkorpal%2FSQL-PL-SQL","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/abhinavkorpal%2FSQL-PL-SQL/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/abhinavkorpal%2FSQL-PL-SQL/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/abhinavkorpal%2FSQL-PL-SQL/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/abhinavkorpal","download_url":"https://codeload.github.com/abhinavkorpal/SQL-PL-SQL/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/abhinavkorpal%2FSQL-PL-SQL/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":261937041,"owners_count":23232846,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["database","plsql","sql"],"created_at":"2024-11-13T01:34:57.176Z","updated_at":"2025-06-25T19:04:43.238Z","avatar_url":"https://github.com/abhinavkorpal.png","language":null,"readme":"\u003c!-- PROJECT LOGO --\u003e\n\u003cbr /\u003e\n\u003cp align=\"center\"\u003e\n  \u003ch1 align=\"center\"\u003eSQL-PL-SQL ✨\u003c/h1\u003e\n\n  \u003cp align=\"center\"\u003e\n    \u003cbr /\u003e\n    ·\n    \u003ca href=\"https://github.com/abhinavkorpal/SQL-PL-SQL/issues\"\u003eReport Bug\u003c/a\u003e\n    ·\n    \u003ca href=\"https://github.com/abhinavkorpal/SQL-PL-SQL/issues\"\u003eRequest Feature\u003c/a\u003e\n  \u003c/p\u003e\n\u003c/p\u003e\n\n* [Working with the Oracle Engine](#working-with-the-oracle-engine)\n* [Various Oracle tools connected to the oracle engine](#various-oracle-tools-connected-to-the-oracle-engine)\n* [Interaction between Oracle Clients and Oracle Engine and the server hard disk drive with data on it](#interaction-between-oracle-clients-and-oracle-engine-and-the-server-hard-disk-drive-with-data-on-it)\n* [SQL](#sql)\n* [SQL used for](#sql-used-for)\n* [DML DCL DDL](#dml-dcl-ddl)\n\n- [THE CREATE TABLE COMMAND](#the-create-table-command)\n- [INSERTION OF DATA INTO TABLES](#insertion-of-data-into-tables)\n- [VIEWING DATA IN THE TABLES](#viewing-data-in-the-tables)\n- [SQL Specific Questions](#sql-specific-questions)\n\n##### Working with the Oracle Engine\n![](https://github.com/abhinavkorpal/SQL-PL-SQL/blob/master/images/oracle_engine.png)\n\n##### Interaction between Oracle Clients and Oracle Engine and the server hard disk drive with data on it.\n![](https://github.com/abhinavkorpal/SQL-PL-SQL/blob/master/images/oracle_client_oracle_engine.png)\n\n##### Various Oracle tools connected to the oracle engine\n![](https://github.com/abhinavkorpal/SQL-PL-SQL/blob/master/images/oracle_tool_oracle_engine.png)\n\n##### SQL\n\n\u003cdetails\u003e\n\u003csummary\u003eWhat does SQL stand for?\u003c/summary\u003e\u003cbr\u003e\u003cb\u003e\n\nStructured Query Language\n\n\u003c/b\u003e\u003c/details\u003e\n\n\u003cdetails\u003e\n\u003csummary\u003eHow is SQL Different from NoSQL\u003c/summary\u003e\u003cbr\u003e\u003cb\u003e\n\nThe main difference is that SQL databases are structured (data is stored in the form of\ntables with rows and columns - like an excel spreadsheet table) while NoSQL is\nunstructured, and the data storage can vary depending on how the NoSQL DB is set up, such\nas key-value pair, document-oriented, etc.\n\u003c/b\u003e\u003c/details\u003e\n\n\u003cdetails\u003e\n\u003csummary\u003eWhat does it mean when a database is ACID compliant?\u003c/summary\u003e\u003cbr\u003e\n\nACID stands for Atomicity, Consistency, Isolation, Durability. In order to be ACID compliant, the database much meet each of the four criteria\n\n**Atomicity** - When a change occurs to the database, it should either succeed or fail as a whole.\n\nFor example, if you were to update a table, the update should completely execute. If it only partially executes, the\nupdate is considered failed as a whole, and will not go through - the DB will revert back to it's original\nstate before the update occurred. It should also be mentioned that Atomicity ensures that each\ntransaction is completed as it's own stand alone \"unit\" - if any part fails, the whole statement fails.\n\n**Consistency** - any change made to the database should bring it from one valid state into the next.\n\nFor example, if you make a change to the DB, it shouldn't corrupt it. Consistency is upheld by checks and constraints that\nare pre-defined in the DB. For example, if you tried to change a value from a string to an int when the column\nshould be of datatype string, a consistent DB would not allow this transaction to go through, and the action would\nnot be executed\n\n**Isolation** - this ensures that a database will never be seen \"mid-update\" - as multiple transactions are running at\nthe same time, it should still leave the DB in the same state as if the transactions were being run sequentially.\n\nFor example, let's say that 20 other people were making changes to the database at the same time. At the\ntime you executed your query, 15 of the 20 changes had gone through, but 5 were still in progress. You should\nonly see the 15 changes that had completed - you wouldn't see the database mid-update as the change goes through.\n\n**Durability** - Once a change is committed, it will remain committed regardless of what happens\n(power failure, system crash, etc.). This means that all completed transactions\nmust be recorded in non-volatile memory.\n\nNote that SQL is by nature ACID compliant. Certain NoSQL DB's can be ACID compliant depending on\nhow they operate, but as a general rule of thumb, NoSQL DB's are not considered ACID compliant\n\u003c/details\u003e\n\n\u003cdetails\u003e\n\u003csummary\u003eWhen is it best to use SQL? NoSQL?\u003c/summary\u003e\u003cbr\u003e\u003cb\u003e\n\nSQL - Best used when data integrity is crucial. SQL is typically implemented with many\nbusinesses and areas within the finance field due to it's ACID compliance.\n\nNoSQL - Great if you need to scale things quickly. NoSQL was designed with web applications\nin mind, so it works great if you need to quickly spread the same information around to\nmultiple servers\n\nAdditionally, since NoSQL does not adhere to the strict table with columns and rows structure\nthat Relational Databases require, you can store different data types together.\n\u003c/b\u003e\u003c/details\u003e\n\n\u003cdetails\u003e\n\u003csummary\u003eWhat is a Cartesian Product?\u003c/summary\u003e\u003cbr\u003e\n\nA Cartesian product is when all rows from the first table are joined to all rows in the second\ntable. This can be done implicitly by not defining a key to join, or explicitly by\ncalling a CROSS JOIN on two tables, such as below:\n\nSelect * from customers **CROSS JOIN** orders;\n\nNote that a Cartesian product can also be a bad thing - when performing a join\non two tables in which both do not have unique keys, this could cause the returned information\nto be incorrect.\n\u003c/details\u003e\n\n##### SQL used for\n\n- SQL can create and maintain data manipulation objects such as tables, views, sequences etc.\n\n- Data manipulation Objects will be create and stored on the server's hard disk drive, in a tabelspace, to which the user has been assigned.\n\n- Once these data manipulation objects created, they are used extensively in commerical applications.\n\n##### DML DCL DDL\n\n- SQL sentences that are used to create these objects are called **DDL's** or **Data Definition Language.**\n\n- SQL sentences that are used to manipulate data within these objects are called **DML's** or **Data Manipulation Language.**\n\n- SQL sentences that are used to control the behavior of these objects are called **DCl's** or **Data Control Language.**\n\n##### THE CREATE TABLE COMMAND\n\n```sql\nSyntax:\n        CREATE TABLE tablename(columnname datatype(size), columnname datatype(size));\n```\n\nCREATE TABLE syntax, the SQL statement starts with 'CREATE' i.e. a verb, followed by 'TABLE' i.e. a noun and '\u003ctablename\u003e' i.e. adjective.\n  \n**Example:** ***Create a client_master table who structure is***:\n\nColumn Name | Data Type | Size\n------------ | ------------- | -------------\nclient_no | varchar2 | 6\nname | varchar2 | 20\naddress1 | varchar2 | 30\naddress2 | varchar2 | 30\ncity | varchar2 | 15\nstate | varchar2 | 15\npincode | number | 6\nremarks | varchar2 | 60\nbal_due | number | 10,2\n\n```sql\nCREATE TABLE client_master (client_no varchar2(20), name varchar2(30), address1 varchar2(30), \n  address2 varchar2(30), city varchar2(15), state varchar2(15), \n  pincode number(6), remarks varchar2(60), bal_due number(10,2));\n```\n        \n##### INSERTION OF DATA INTO TABLES\n\n```sql\nSynatx: \n        INSERT INTO tablename(columnname, columnname) VALUES (expression, expression);\n```\n  \n**Example:** ***Insert the following values into the client_master table***:\n  \nColumn Name | Values\n------------ | -------------\nclient_no | C02000,\nname | Abhinav Korpal\naddress1 | HSR Layout\naddress2 | Outer Ring\ncity | Bangalore\nstate | Karantaka\npincode | 560001\n\n```sql\nINSERT INTO client_master \n  (client_no, name, address1, address2, city, state, pincode)\n  VALUES('C02000', 'Abhinav Korpal', 'HSR Layout', 'Outer Ring', 'Bangalore', 'Karantaka', 560001);\n```\n\n ##### VIEWING DATA IN THE TABLES\n\nAll Rows and All Column:\n\nTo View Global Table Data the syntax is:\n\nGlobal data extract:\n\n```sql\nI) Syntax:\n        SELECT (columname1... ...columname n) FROM tablename;\nII) Syntax:\n        SELECT * FROM tablename;\n```\nExample:\n  \n1. Retrieve the names of the employees and their salaries from the table emp_master;\n```sql\nSELECT name, salary FROM tablename;\n```\n2. Retrieve all records from tabel client_master;\n```sql\nSELECT * FROM client_master;\n```\n\n#### FILTERING TABLE DATA:\n\nThe way of filtering table data will be\n- Selected columns and all rows\n- Selected rows and all columnns\n- Selected columns and Selected rows\n\n##### Selected Columns and All Rows:\n\n```sql\nSyntax: \n        SELECT columname, columname FROM tablename;\n```\n  \n##### **Example:** ***Retrive the contents of the columns client_no and name from the table client_master***:\n  \n```sql\n  SELECT client_no, name FROM client_master;\n```\n\n##### Selected rows and all columnns:\n\n```sql\nSyntax: \n        SELECT * FROM tablename WHERE search condition;\n```\n  \n##### **Example:** ***Retrive all client_information from table client_master the value in the bal_due field is greater than 0***:\n  \n```sql\n  SELECT * FROM client_master WHERE bal_due \u003e 0;\n```\n\n##### Selected Columns and Selected Rows:\n\n```sql\nSyntax:\n        SELECT columname, columnname FROM tablename WHERE search condition;\n```\n\n#### SQL Performance Tuning\n\n###### USING ROWNUM IN SQL STATEMENTS\n\n```sql\nSyntax: \n      SELECT ROWNUM, client_no, name\n      FROM client_master\n      WHERE ROWNUM \u003c 8;\n```\n\n###### SEQUENCES\n\n```sql\nSyntax:\n      CREATE SEQUENCES sequence_name \n      [INCREMENT BY integervalue \n      START WITH integervalue \n      MAXVALUE integervalue / NOMAXVALUE integervalue \n      MINVALUE integervalue / NOMINVALUE integervalue \n      CYCLE / NOCYCLE CACHE integervalue / NOCACHE \n      ORDER / NOORDER]\n```\n\n###### Dropping A Sequence\n\n```sql\nSyntax: \n       DROP SEQUENCE sequence_name;\n```\n\n#### Security Management Using SQL\n\n###### Granting Privileges using the Grant statement\n\n```sql\nSyntax: \n        GRANT {object privileges}\n        ON objectname\n        TO username\n        [WITH GRANT OPTION];\n```\n###### Revoking permissions using the REVOKE statement\n\n```sql\nSynatx: \n       REVOKE { object privileges }\n       ON objectname\n       FROM username;\n```\n\n#### PL/SQL\n\n#### SQL*PLUS\n                       \n##### SQL Specific Questions\n\nFor these questions, we will be using the Customers and Orders tables shown below:\n\n**Customers**\n\nCustomer_ID | Customer_Name | Items_in_cart | Cash_spent_to_Date\n------------ | ------------- | ------------- | -------------\n100204 | John Smith | 0 | 20.00\n100205 | Jane Smith | 3 | 40.00\n100206 | Bobby Frank | 1 | 100.20\n\n**ORDERS**\n\nCustomer_ID | Order_ID | Item | Price | Date_sold\n------------ | ------------- | ------------- | ------------- | -------------\n100206 | A123 | Rubber Ducky | 2.20 | 2019-09-18\n100206 | A123 | Bubble Bath | 8.00 | 2019-09-18\n100206 | Q987 | 80-Pack TP | 90.00 | 2019-09-20\n100205 | Z001 | Cat Food - Tuna Fish | 10.00 | 2019-08-05\n100205 | Z001 | Cat Food - Chicken | 10.00 | 2019-08-05\n100205 | Z001 | Cat Food - Beef | 10.00 | 2019-08-05\n100205 | Z001 | Cat Food - Kitty quesadilla | 10.00 | 2019-08-05\n100204 | X202 | Coffee | 20.00 | 2019-04-29\n\n\u003cdetails\u003e\n\u003csummary\u003eHow would I select all fields from this table?\u003c/summary\u003e\u003cbr\u003e\u003cb\u003e\n\nSelect * \u003cbr\u003e\nFrom Customers;\n\u003c/b\u003e\u003c/details\u003e\n\n\u003cdetails\u003e\n\u003csummary\u003eHow many items are in John's cart?\u003c/summary\u003e\u003cbr\u003e\u003cb\u003e\n\nSelect Items_in_cart \u003cbr\u003e\nFrom Customers \u003cbr\u003e\nWhere Customer_Name = \"John Smith\";\n\u003c/b\u003e\u003c/details\u003e\n\n\u003cdetails\u003e\n\u003csummary\u003eWhat is the sum of all the cash spent across all customers?\u003c/summary\u003e\u003cbr\u003e\u003cb\u003e\n\nSelect SUM(Cash_spent_to_Date) as SUM_CASH \u003cbr\u003e\nFrom Customers;\n\u003c/b\u003e\u003c/details\u003e\n\n\u003cdetails\u003e\n\u003csummary\u003eHow many people have items in their cart?\u003c/summary\u003e\u003cbr\u003e\u003cb\u003e\n\nSelect count(1) as Number_of_People_w_items \u003cbr\u003e\nFrom Customers \u003cbr\u003e\nwhere Items_in_cart \u003e 0;\n\u003c/b\u003e\u003c/details\u003e\n\n\u003cdetails\u003e\n\u003csummary\u003eHow would you join the customer table to the order table?\u003c/summary\u003e\u003cbr\u003e\u003cb\u003e\n\nYou would join them on the unique key. In this case, the unique key is Customer_ID in\nboth the Customers table and Orders table\n\u003c/b\u003e\u003c/details\u003e\n\n\u003cdetails\u003e\n\u003csummary\u003eHow would you show which customer ordered which items?\u003c/summary\u003e\u003cbr\u003e\u003cb\u003e\n\nSelect c.Customer_Name, o.Item \u003cbr\u003e\nFrom Customers c \u003cbr\u003e\nLeft Join Orders o \u003cbr\u003e\n  On c.Customer_ID = o.Customer_ID;\n\n\u003c/b\u003e\u003c/details\u003e\n\n\u003cdetails\u003e\n\u003csummary\u003eUsing a with statement, how would you show who ordered cat food, and the total amount of money spent?\u003c/summary\u003e\u003cbr\u003e\u003cb\u003e\n\nwith cat_food as ( \u003cbr\u003e\nSelect Customer_ID, SUM(Price) as TOTAL_PRICE \u003cbr\u003e\nFrom Orders \u003cbr\u003e\nWhere Item like \"%Cat Food%\" \u003cbr\u003e\nGroup by Customer_ID \u003cbr\u003e\n) \u003cbr\u003e\nSelect Customer_name, TOTAL_PRICE \u003cbr\u003e\nFrom Customers c \u003cbr\u003e\nInner JOIN cat_food f \u003cbr\u003e\n  ON c.Customer_ID = f.Customer_ID \u003cbr\u003e\nwhere c.Customer_ID in (Select Customer_ID from cat_food);\n\nAlthough this was a simple statement, the \"with\" clause really shines when\na complex query needs to be run on a table before joining to another. With statements are nice,\nbecause you create a pseudo temp when running your query, instead of creating a whole new table.\n\nThe Sum of all the purchases of cat food weren't readily available, so we used a with statement to create\nthe pseudo table to retrieve the sum of the prices spent by each customer, then join the table normally.\n\u003c/b\u003e\u003c/details\u003e\n\n\n\n\n\n\n\n\n\n\n\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fabhinavkorpal%2Fsql-pl-sql","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fabhinavkorpal%2Fsql-pl-sql","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fabhinavkorpal%2Fsql-pl-sql/lists"}